Skip to content

Commit 0adfa2a

Browse files
authored
Make one review for files (#148)
* Make one review comment for files * Add build diff
1 parent c086468 commit 0adfa2a

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

action/index.cjs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148211,6 +148211,7 @@ const robot = (app) => {
148211148211
return 'no change';
148212148212
}
148213148213
console.time('gpt cost');
148214+
const ress = [];
148214148215
for (let i = 0; i < changedFiles.length; i++) {
148215148216
const file = changedFiles[i];
148216148217
const patch = file.patch || '';
@@ -148224,11 +148225,7 @@ const robot = (app) => {
148224148225
try {
148225148226
const res = await chat?.codeReview(patch);
148226148227
if (!!res) {
148227-
await context.octokit.pulls.createReviewComment({
148228-
repo: repo.repo,
148229-
owner: repo.owner,
148230-
pull_number: context.pullRequest().pull_number,
148231-
commit_id: commits[commits.length - 1].sha,
148228+
ress.push({
148232148229
path: file.filename,
148233148230
body: res,
148234148231
position: patch.split('\n').length - 1,
@@ -148239,6 +148236,20 @@ const robot = (app) => {
148239148236
console.error(`review ${file.filename} failed`, e);
148240148237
}
148241148238
}
148239+
try {
148240+
await context.octokit.pulls.createReview({
148241+
repo: repo.repo,
148242+
owner: repo.owner,
148243+
pull_number: context.pullRequest().pull_number,
148244+
body: "Code review by ChatGPT",
148245+
event: 'COMMENT',
148246+
commit_id: commits[commits.length - 1].sha,
148247+
comments: ress,
148248+
});
148249+
}
148250+
catch (e) {
148251+
console.error(`Failed to create review`, e);
148252+
}
148242148253
console.timeEnd('gpt cost');
148243148254
console.info('successfully reviewed', context.payload.pull_request.html_url);
148244148255
return 'success';

src/bot.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export const robot = (app: Probot) => {
113113

114114
console.time('gpt cost');
115115

116+
const ress = [];
117+
116118
for (let i = 0; i < changedFiles.length; i++) {
117119
const file = changedFiles[i];
118120
const patch = file.patch || '';
@@ -129,22 +131,30 @@ export const robot = (app: Probot) => {
129131
}
130132
try {
131133
const res = await chat?.codeReview(patch);
132-
133134
if (!!res) {
134-
await context.octokit.pulls.createReviewComment({
135-
repo: repo.repo,
136-
owner: repo.owner,
137-
pull_number: context.pullRequest().pull_number,
138-
commit_id: commits[commits.length - 1].sha,
135+
ress.push({
139136
path: file.filename,
140137
body: res,
141138
position: patch.split('\n').length - 1,
142-
});
139+
})
143140
}
144141
} catch (e) {
145142
console.error(`review ${file.filename} failed`, e);
146143
}
147144
}
145+
try {
146+
await context.octokit.pulls.createReview({
147+
repo: repo.repo,
148+
owner: repo.owner,
149+
pull_number: context.pullRequest().pull_number,
150+
body: "Code review by ChatGPT",
151+
event: 'COMMENT',
152+
commit_id: commits[commits.length - 1].sha,
153+
comments: ress,
154+
});
155+
} catch (e) {
156+
console.error(`Failed to create review`, e);
157+
}
148158

149159
console.timeEnd('gpt cost');
150160
console.info(

0 commit comments

Comments
 (0)