Skip to content

Commit

Permalink
Make one review for files (#148)
Browse files Browse the repository at this point in the history
* Make one review comment for files

* Add build diff
  • Loading branch information
keenranger authored Nov 5, 2024
1 parent c086468 commit 0adfa2a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
21 changes: 16 additions & 5 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -148211,6 +148211,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 || '';
Expand All @@ -148224,11 +148225,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,
Expand All @@ -148239,6 +148236,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';
Expand Down
24 changes: 17 additions & 7 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 || '';
Expand All @@ -129,22 +131,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(
Expand Down

0 comments on commit 0adfa2a

Please sign in to comment.