diff --git a/action/index.cjs b/action/index.cjs index 27aedd0..dc41f58 100644 --- a/action/index.cjs +++ b/action/index.cjs @@ -148209,6 +148209,7 @@ const robot = (app) => { return 'no change'; } console.time('gpt cost'); + const ress = []; for (let i = 0; i < changedFiles.length; i++) { const file = changedFiles[i]; const patch = file.patch || ''; @@ -148222,11 +148223,7 @@ const robot = (app) => { try { const res = await chat?.codeReview(patch); if (!!res) { - await context.octokit.pulls.createReviewComment({ - repo: repo.repo, - owner: repo.owner, - pull_number: context.pullRequest().pull_number, - commit_id: commits[commits.length - 1].sha, + ress.push({ path: file.filename, body: res, position: patch.split('\n').length - 1, @@ -148237,6 +148234,20 @@ const robot = (app) => { console.error(`review ${file.filename} failed`, e); } } + try { + await context.octokit.pulls.createReview({ + repo: repo.repo, + owner: repo.owner, + pull_number: context.pullRequest().pull_number, + body: "Code review by ChatGPT", + event: 'COMMENT', + commit_id: commits[commits.length - 1].sha, + comments: ress, + }); + } + catch (e) { + console.error(`Failed to create review`, e); + } console.timeEnd('gpt cost'); console.info('successfully reviewed', context.payload.pull_request.html_url); return 'success'; diff --git a/src/bot.ts b/src/bot.ts index f7c3fed..90f71be 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -110,6 +110,8 @@ export const robot = (app: Probot) => { console.time('gpt cost'); + const ress = []; + for (let i = 0; i < changedFiles.length; i++) { const file = changedFiles[i]; const patch = file.patch || ''; @@ -126,22 +128,30 @@ export const robot = (app: Probot) => { } try { const res = await chat?.codeReview(patch); - if (!!res) { - await context.octokit.pulls.createReviewComment({ - repo: repo.repo, - owner: repo.owner, - pull_number: context.pullRequest().pull_number, - commit_id: commits[commits.length - 1].sha, + ress.push({ path: file.filename, body: res, position: patch.split('\n').length - 1, - }); + }) } } catch (e) { console.error(`review ${file.filename} failed`, e); } } + try { + await context.octokit.pulls.createReview({ + repo: repo.repo, + owner: repo.owner, + pull_number: context.pullRequest().pull_number, + body: "Code review by ChatGPT", + event: 'COMMENT', + commit_id: commits[commits.length - 1].sha, + comments: ress, + }); + } catch (e) { + console.error(`Failed to create review`, e); + } console.timeEnd('gpt cost'); console.info(