Skip to content

Commit

Permalink
create correct tree object for submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans committed Sep 18, 2024
1 parent 3cd1f3c commit 51d5008
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 42 deletions.
45 changes: 28 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
60 changes: 35 additions & 25 deletions src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
}
})
)
Expand Down

0 comments on commit 51d5008

Please sign in to comment.