Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand All @@ -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,
Expand All @@ -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';
Expand Down
24 changes: 17 additions & 7 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand All @@ -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(
Expand Down