create correct tree object for submodule
This commit is contained in:
parent
3cd1f3c5cf
commit
51d5008576
2 changed files with 64 additions and 43 deletions
47
dist/index.js
vendored
47
dist/index.js
vendored
|
@ -1369,25 +1369,36 @@ class GitHubHelper {
|
|||
let treeSha = parentCommit.tree;
|
||||
if (commit.changes.length > 0) {
|
||||
core.info(`Creating tree objects for local commit ${commit.sha}`);
|
||||
const treeObjects = yield Promise.all(commit.changes.map((_a) => __awaiter(this, [_a], void 0, function* ({ path, mode, status }) {
|
||||
let sha = null;
|
||||
if (status === 'A' || status === 'M') {
|
||||
try {
|
||||
const { data: blob } = yield blobCreationLimit(() => this.octokit.rest.git.createBlob(Object.assign(Object.assign({}, repository), { content: utils.readFileBase64([repoPath, path]), encoding: 'base64' })));
|
||||
sha = blob.sha;
|
||||
}
|
||||
catch (error) {
|
||||
core.error(`Error creating blob for file '${path}': ${utils.getErrorMessage(error)}`);
|
||||
throw error;
|
||||
}
|
||||
const treeObjects = yield Promise.all(commit.changes.map((_a) => __awaiter(this, [_a], void 0, function* ({ path, mode, status, dstSha }) {
|
||||
if (mode === '160000') {
|
||||
// submodule
|
||||
return {
|
||||
path,
|
||||
mode,
|
||||
sha: dstSha,
|
||||
type: 'commit'
|
||||
};
|
||||
}
|
||||
else {
|
||||
let sha = null;
|
||||
if (status === 'A' || status === 'M') {
|
||||
try {
|
||||
const { data: blob } = yield blobCreationLimit(() => this.octokit.rest.git.createBlob(Object.assign(Object.assign({}, repository), { content: utils.readFileBase64([repoPath, path]), encoding: 'base64' })));
|
||||
sha = blob.sha;
|
||||
core.info(`Created blob for file '${path}'`);
|
||||
}
|
||||
catch (error) {
|
||||
core.error(`Error creating blob for file '${path}': ${utils.getErrorMessage(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return {
|
||||
path,
|
||||
mode,
|
||||
sha,
|
||||
type: 'blob'
|
||||
};
|
||||
}
|
||||
core.info(`Created blob for file '${path}'`);
|
||||
return {
|
||||
path,
|
||||
mode,
|
||||
sha,
|
||||
type: 'blob'
|
||||
};
|
||||
})));
|
||||
const chunkSize = 100;
|
||||
const chunkedTreeObjects = Array.from({ length: Math.ceil(treeObjects.length / chunkSize) }, (_, i) => treeObjects.slice(i * chunkSize, i * chunkSize + chunkSize));
|
||||
|
|
|
@ -35,7 +35,7 @@ type TreeObject = {
|
|||
path: string
|
||||
mode: '100644' | '100755' | '040000' | '160000' | '120000'
|
||||
sha: string | null
|
||||
type: 'blob'
|
||||
type: 'blob' | 'commit'
|
||||
}
|
||||
|
||||
export class GitHubHelper {
|
||||
|
@ -255,31 +255,41 @@ export class GitHubHelper {
|
|||
if (commit.changes.length > 0) {
|
||||
core.info(`Creating tree objects for local commit ${commit.sha}`)
|
||||
const treeObjects = await Promise.all(
|
||||
commit.changes.map(async ({path, mode, status}) => {
|
||||
let sha: string | null = null
|
||||
if (status === 'A' || status === 'M') {
|
||||
try {
|
||||
const {data: blob} = await blobCreationLimit(() =>
|
||||
this.octokit.rest.git.createBlob({
|
||||
...repository,
|
||||
content: utils.readFileBase64([repoPath, path]),
|
||||
encoding: 'base64'
|
||||
})
|
||||
)
|
||||
sha = blob.sha
|
||||
} catch (error) {
|
||||
core.error(
|
||||
`Error creating blob for file '${path}': ${utils.getErrorMessage(error)}`
|
||||
)
|
||||
throw error
|
||||
commit.changes.map(async ({path, mode, status, dstSha}) => {
|
||||
if (mode === '160000') {
|
||||
// submodule
|
||||
return <TreeObject>{
|
||||
path,
|
||||
mode,
|
||||
sha: dstSha,
|
||||
type: 'commit'
|
||||
}
|
||||
} else {
|
||||
let sha: string | null = null
|
||||
if (status === 'A' || status === 'M') {
|
||||
try {
|
||||
const {data: blob} = await blobCreationLimit(() =>
|
||||
this.octokit.rest.git.createBlob({
|
||||
...repository,
|
||||
content: utils.readFileBase64([repoPath, path]),
|
||||
encoding: 'base64'
|
||||
})
|
||||
)
|
||||
sha = blob.sha
|
||||
core.info(`Created blob for file '${path}'`)
|
||||
} catch (error) {
|
||||
core.error(
|
||||
`Error creating blob for file '${path}': ${utils.getErrorMessage(error)}`
|
||||
)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
return <TreeObject>{
|
||||
path,
|
||||
mode,
|
||||
sha,
|
||||
type: 'blob'
|
||||
}
|
||||
}
|
||||
core.info(`Created blob for file '${path}'`)
|
||||
return <TreeObject>{
|
||||
path,
|
||||
mode,
|
||||
sha,
|
||||
type: 'blob'
|
||||
}
|
||||
})
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue