Skip to content

Commit 1f8b4c2

Browse files
committed
build
1 parent 9cb205e commit 1f8b4c2

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

action/index.cjs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150469,6 +150469,7 @@ const robot = (app) => {
150469150469
const includePatterns = (process.env.INCLUDE_PATTERNS || '').split(',').filter((v) => Boolean(v.trim()));
150470150470
loglevel_1.default.debug('ignoreList:', ignoreList);
150471150471
loglevel_1.default.debug('ignorePatterns:', ignorePatterns);
150472+
loglevel_1.default.debug('includePatterns:', includePatterns);
150472150473
changedFiles = changedFiles?.filter((file) => {
150473150474
const url = new URL(file.contents_url);
150474150475
// if includePatterns is not empty, only include files that match the pattern
@@ -150502,10 +150503,10 @@ const robot = (app) => {
150502150503
}
150503150504
try {
150504150505
const res = await chat?.codeReview(patch);
150505-
if (!!res) {
150506+
if (!res.lgtm && !!res.review_comment) {
150506150507
ress.push({
150507150508
path: file.filename,
150508-
body: res,
150509+
body: res.review_comment,
150509150510
position: patch.split('\n').length - 1,
150510150511
});
150511150512
}
@@ -150519,7 +150520,7 @@ const robot = (app) => {
150519150520
repo: repo.repo,
150520150521
owner: repo.owner,
150521150522
pull_number: context.pullRequest().pull_number,
150522-
body: "Code review by ChatGPT",
150523+
body: ress.length ? "Code review by ChatGPT" : "LGTM 👍",
150523150524
event: 'COMMENT',
150524150525
commit_id: commits[commits.length - 1].sha,
150525150526
comments: ress,
@@ -150588,15 +150589,23 @@ class Chat {
150588150589
const answerLanguage = process.env.LANGUAGE
150589150590
? `Answer me in ${process.env.LANGUAGE},`
150590150591
: '';
150591-
const prompt = process.env.PROMPT ||
150592-
'Below is a code patch, please help me do a brief code review on it. Any bug risks and/or improvement suggestions are welcome:';
150593-
return `${prompt}, ${answerLanguage}:
150594-
${patch}
150592+
const userPrompt = process.env.PROMPT || 'Please review the following code patch. Focus on potential bugs, risks, and improvement suggestions.';
150593+
const jsonFormatRequirement = '\nProvide your feedback in a strict JSON format with the following structure:\n' +
150594+
'{\n' +
150595+
' "lgtm": boolean, // true if the code looks good to merge, false if there are concerns\n' +
150596+
' "review_comment": string // Your detailed review comments. You can use markdown syntax in this string, but the overall response must be a valid JSON\n' +
150597+
'}\n' +
150598+
'Ensure your response is a valid JSON object.\n';
150599+
return `${userPrompt}${jsonFormatRequirement} ${answerLanguage}:
150600+
${patch}
150595150601
`;
150596150602
};
150597150603
codeReview = async (patch) => {
150598150604
if (!patch) {
150599-
return '';
150605+
return {
150606+
lgtm: true,
150607+
review_comment: ""
150608+
};
150600150609
}
150601150610
console.time('code-review cost');
150602150611
const prompt = this.generatePrompt(patch);
@@ -150611,12 +150620,27 @@ class Chat {
150611150620
temperature: +(process.env.temperature || 0) || 1,
150612150621
top_p: +(process.env.top_p || 0) || 1,
150613150622
max_tokens: process.env.max_tokens ? +process.env.max_tokens : undefined,
150623+
response_format: {
150624+
type: "json_object"
150625+
},
150614150626
});
150615150627
console.timeEnd('code-review cost');
150616150628
if (res.choices.length) {
150617-
return res.choices[0].message.content;
150629+
try {
150630+
const json = JSON.parse(res.choices[0].message.content || "");
150631+
return json;
150632+
}
150633+
catch (e) {
150634+
return {
150635+
lgtm: false,
150636+
review_comment: res.choices[0].message.content || ""
150637+
};
150638+
}
150618150639
}
150619-
return '';
150640+
return {
150641+
lgtm: true,
150642+
review_comment: ""
150643+
};
150620150644
};
150621150645
}
150622150646
exports.Chat = Chat;

action/src/chat.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ export declare class Chat {
33
private isAzure;
44
constructor(apikey: string);
55
private generatePrompt;
6-
codeReview: (patch: string) => Promise<string | null>;
6+
codeReview: (patch: string) => Promise<{
7+
lgtm: boolean;
8+
review_comment: string;
9+
}>;
710
}

0 commit comments

Comments
 (0)