From 39e6568d73dd2dfcb0d209e88ef83395590944d3 Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Sat, 20 May 2023 16:05:54 +0800 Subject: [PATCH] build --- out/github-action.cjs | 43 +++++++++++++++++++------------------------ src/github-action.ts | 36 ++++++++++++++---------------------- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/out/github-action.cjs b/out/github-action.cjs index a737e95..91c19a1 100644 --- a/out/github-action.cjs +++ b/out/github-action.cjs @@ -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"]); diff --git a/src/github-action.ts b/src/github-action.ts index 8c4d3ec..7fb3432 100644 --- a/src/github-action.ts +++ b/src/github-action.ts @@ -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 });