Skip to content

Commit e292a56

Browse files
authored
Merge pull request #91 from qoomon/copilot/incremental-commit-tree-build
Build commit tree incrementally to avoid timeouts on large commits
2 parents 0f4cc87 + 8d19e7d commit e292a56

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

dist/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38203,7 +38203,7 @@ async function getCachedObjectSha(path) {
3820338203
async function createCommit(octokit, repository, args) {
3820438204
let commitTreeSha = args.tree;
3820538205
if (args.files.length > 0) {
38206-
console.log('Creating commit tree...');
38206+
console.log('Creating blobs...');
3820738207
let progress = 0;
3820838208
const commitTreeBlobs = await Promise.all(args.files.map(async ({ path, mode, status, loadContent }) => (async function () {
3820938209
switch (status) {
@@ -38240,14 +38240,22 @@ async function createCommit(octokit, repository, args) {
3824038240
})().finally(() => {
3824138241
progress++;
3824238242
// log progress
38243-
console.log(`${progress} of ${args.files.length} files...`);
38243+
console.log(` ${progress} of ${args.files.length} files...`);
3824438244
})));
38245-
commitTreeSha = await octokit.rest.git.createTree({
38246-
...repository,
38247-
base_tree: args.parents[0],
38248-
tree: commitTreeBlobs,
38249-
}).then(({ data }) => data.sha);
38250-
console.log('Creating commit tree done.', commitTreeSha);
38245+
console.log('Creating commit tree...');
38246+
const chunkSize = 100;
38247+
for (let i = 0; i < commitTreeBlobs.length; i += chunkSize) {
38248+
const chunk = commitTreeBlobs.slice(i, i + chunkSize);
38249+
commitTreeSha = await octokit.rest.git.createTree({
38250+
...repository,
38251+
base_tree: commitTreeSha,
38252+
tree: chunk,
38253+
}).then(({ data }) => data.sha).finally(() => {
38254+
progress++;
38255+
// log progress
38256+
console.log(` ${progress} of ${args.files.length} blobs...`);
38257+
});
38258+
}
3825138259
}
3825238260
console.log('Creating commit...');
3825338261
const commit = await octokit.rest.git.createCommit({

lib/github.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function createCommit(
1515
) {
1616
let commitTreeSha = args.tree
1717
if (args.files.length > 0) {
18-
console.log('Creating commit tree...')
18+
console.log('Creating blobs...')
1919
let progress = 0
2020
const commitTreeBlobs = await Promise.all(args.files.map(async ({path, mode, status, loadContent}) => (async function(){
2121
switch (status) {
@@ -53,17 +53,24 @@ export async function createCommit(
5353
})().finally(() => {
5454
progress++;
5555
// log progress
56-
console.log(`${progress} of ${args.files.length} files...`)
56+
console.log(` ${progress} of ${args.files.length} files...`)
5757
})
5858
))
59+
console.log('Creating commit tree...')
60+
const chunkSize = 100
5961

60-
commitTreeSha = await octokit.rest.git.createTree({
61-
...repository,
62-
base_tree: args.parents[0],
63-
tree: commitTreeBlobs,
64-
}).then(({data}) => data.sha)
65-
66-
console.log('Creating commit tree done.', commitTreeSha)
62+
for (let i = 0; i < commitTreeBlobs.length; i += chunkSize) {
63+
const chunk = commitTreeBlobs.slice(i, i + chunkSize)
64+
commitTreeSha = await octokit.rest.git.createTree({
65+
...repository,
66+
base_tree: commitTreeSha,
67+
tree: chunk,
68+
}).then(({data}) => data.sha).finally(() => {
69+
progress++;
70+
// log progress
71+
console.log(` ${progress} of ${args.files.length} blobs...`)
72+
})
73+
}
6774
}
6875

6976
console.log('Creating commit...')

0 commit comments

Comments
 (0)