This commit is contained in:
di-sukharev
2023-05-20 16:05:54 +08:00
parent 1867c96f22
commit 39e6568d73
2 changed files with 33 additions and 46 deletions

View File

@@ -27945,33 +27945,28 @@ async function improveCommitMessagesWithRebase(commits, diffs) {
let improvedMessagesBySha2 = {};
for (let i2 = 0; i2 < improvePromises.length; i2 += chunkSize) {
const chunkOfPromises = improvePromises.slice(i2, i2 + chunkSize);
await Promise.all(chunkOfPromises).then((results) => {
return results.reduce((acc, improvedMsg, i3) => {
const index = Object.keys(improvedMessagesBySha2).length;
acc[diffs[index + i3].sha] = improvedMsg;
return acc;
}, improvedMessagesBySha2);
}).catch((error) => {
ce(`error in Promise.all(getCommitDiffs(SHAs)): ${error}`);
throw error;
});
const sleepFor = 3e3 + 200 * (i2 / chunkSize);
ce(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
try {
await Promise.all(chunkOfPromises).then((results) => {
return results.reduce((acc, improvedMsg, i3) => {
const index = Object.keys(improvedMessagesBySha2).length;
acc[diffs[index + i3].sha] = improvedMsg;
return acc;
}, improvedMessagesBySha2);
});
const sleepFor = 3e3 + 200 * (i2 / chunkSize);
ce(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
} catch (error) {
ce(error);
ce("Retrying");
i2 -= chunkSize;
}
}
return improvedMessagesBySha2;
}
let improvedMessagesBySha = {};
try {
improvedMessagesBySha = await improveMessagesInChunks();
} catch (error) {
ce(error);
ce("retrying");
await improveCommitMessagesWithRebase(commits, diffs);
return;
}
const improvedMessagesBySha = await improveMessagesInChunks();
console.log({ improvedMessagesBySha });
ce("Done.");
const { stdout } = await execa("git", ["rev-parse", "--abbrev-ref", "HEAD"]);

View File

@@ -83,42 +83,34 @@ async function improveCommitMessagesWithRebase(
for (let i = 0; i < improvePromises.length; i += chunkSize) {
const chunkOfPromises = improvePromises.slice(i, i + chunkSize);
await Promise.all(chunkOfPromises)
.then((results) => {
try {
await Promise.all(chunkOfPromises).then((results) => {
return results.reduce((acc, improvedMsg, i) => {
const index = Object.keys(improvedMessagesBySha).length;
acc[diffs![index + i].sha] = improvedMsg;
return acc;
}, improvedMessagesBySha);
})
.catch((error) => {
outro(`error in Promise.all(getCommitDiffs(SHAs)): ${error}`);
throw error;
});
// openAI errors with 429 code (too many requests) so lets sleep a bit
const sleepFor = 3000 + 200 * (i / chunkSize);
// openAI errors with 429 code (too many requests) so lets sleep a bit
const sleepFor = 3000 + 200 * (i / chunkSize);
outro(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
outro(
`Improved ${chunkOfPromises.length} messages. Sleeping for ${sleepFor}`
);
await sleep(sleepFor);
} catch (error) {
outro(error as string);
outro('Retrying');
i -= chunkSize;
}
}
return improvedMessagesBySha;
}
let improvedMessagesBySha: MessageBySha = {};
try {
improvedMessagesBySha = await improveMessagesInChunks();
} catch (error) {
outro(error as string);
outro('retrying');
await improveCommitMessagesWithRebase(commits, diffs);
return;
}
const improvedMessagesBySha: MessageBySha = await improveMessagesInChunks();
console.log({ improvedMessagesBySha });