Skip to content

Commit b84cb86

Browse files
Copilotqoomon
andauthored
fix: restore args.parents[0] as base_tree for incremental createTree loop
Agent-Logs-Url: https://github.com/qoomon/actions--create-commit/sessions/3fdd930f-0a88-42f2-9a09-235c3114f626 Co-authored-by: qoomon <3963394+qoomon@users.noreply.github.com>
1 parent 56e493c commit b84cb86

3 files changed

Lines changed: 9 additions & 20 deletions

File tree

dist/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38244,11 +38244,12 @@ async function createCommit(octokit, repository, args) {
3824438244
})));
3824538245
console.log('Creating commit tree...');
3824638246
const chunkSize = 100;
38247+
let chunkBaseTree = args.parents[0];
3824738248
for (let i = 0; i < commitTreeBlobs.length; i += chunkSize) {
3824838249
const chunk = commitTreeBlobs.slice(i, i + chunkSize);
38249-
commitTreeSha = await octokit.rest.git.createTree({
38250+
chunkBaseTree = commitTreeSha = await octokit.rest.git.createTree({
3825038251
...repository,
38251-
...(commitTreeSha !== undefined ? { base_tree: commitTreeSha } : {}),
38252+
...(chunkBaseTree !== undefined ? { base_tree: chunkBaseTree } : {}),
3825238253
tree: chunk,
3825338254
}).then(({ data }) => data.sha).finally(() => {
3825438255
progress++;
@@ -38257,9 +38258,6 @@ async function createCommit(octokit, repository, args) {
3825738258
});
3825838259
}
3825938260
}
38260-
if (commitTreeSha === undefined) {
38261-
throw new Error('Could not determine commit tree SHA: no parent tree SHA was provided and no files were given to create a new tree');
38262-
}
3826338261
console.log('Creating commit...');
3826438262
const commit = await octokit.rest.git.createCommit({
3826538263
...repository,
@@ -38384,13 +38382,10 @@ const action = () => run(async () => {
3838438382
const headCommit = await getCommitDetails('HEAD');
3838538383
const repositoryRemoteUrl = await getRemoteUrl(input.remoteName);
3838638384
const repository = parseRepositoryFromUrl(repositoryRemoteUrl);
38387-
const parentCommit = headCommit.parents.length > 0
38388-
? await getCommitDetails(headCommit.parents[0])
38389-
: null;
3839038385
const githubCommit = await createCommit(octokit, repository, {
3839138386
subject: headCommit.subject,
3839238387
body: headCommit.body,
38393-
tree: parentCommit?.tree,
38388+
tree: headCommit.tree,
3839438389
parents: headCommit.parents,
3839538390
files: headCommit.files.map((file) => ({
3839638391
path: file.path,

index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ export const action = () => run(async () => {
9393
const headCommit = await getCommitDetails('HEAD')
9494
const repositoryRemoteUrl = await getRemoteUrl(input.remoteName)
9595
const repository = parseRepositoryFromUrl(repositoryRemoteUrl)
96-
const parentCommit = headCommit.parents.length > 0
97-
? await getCommitDetails(headCommit.parents[0])
98-
: null
9996
const githubCommit = await createCommit(octokit, repository, {
10097
subject: headCommit.subject,
10198
body: headCommit.body,
102-
tree: parentCommit?.tree,
99+
tree: headCommit.tree,
103100
parents: headCommit.parents,
104101
files: headCommit.files.map((file) => ({
105102
path: file.path,

lib/github.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ export async function createCommit(
5959
console.log('Creating commit tree...')
6060
const chunkSize = 100
6161

62+
let chunkBaseTree: string | undefined = args.parents[0]
6263
for (let i = 0; i < commitTreeBlobs.length; i += chunkSize) {
6364
const chunk = commitTreeBlobs.slice(i, i + chunkSize)
64-
commitTreeSha = await octokit.rest.git.createTree({
65+
chunkBaseTree = commitTreeSha = await octokit.rest.git.createTree({
6566
...repository,
66-
...(commitTreeSha !== undefined ? {base_tree: commitTreeSha} : {}),
67+
...(chunkBaseTree !== undefined ? {base_tree: chunkBaseTree} : {}),
6768
tree: chunk,
6869
}).then(({data}) => data.sha).finally(() => {
6970
progress++;
@@ -73,10 +74,6 @@ export async function createCommit(
7374
}
7475
}
7576

76-
if (commitTreeSha === undefined) {
77-
throw new Error('Could not determine commit tree SHA: no parent tree SHA was provided and no files were given to create a new tree')
78-
}
79-
8077
console.log('Creating commit...')
8178
const commit = await octokit.rest.git.createCommit({
8279
...repository,
@@ -123,7 +120,7 @@ export type CreateCommitArgs = {
123120
subject: string
124121
body: string
125122
parents: string[]
126-
tree: string | undefined,
123+
tree: string,
127124
files: {
128125
path: string
129126
mode: '100644' | '100755' | '040000' | '160000' | '120000' | string

0 commit comments

Comments
 (0)