mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 17:46:47 +00:00
Fix the bot to add review comments
This commit is contained in:
parent
fcd39ade07
commit
f2f7079221
3 changed files with 38 additions and 11 deletions
19
dist/index.js
vendored
19
dist/index.js
vendored
|
@ -128,8 +128,7 @@ Git diff to review:
|
|||
\`\`\`diff
|
||||
${chunk.content}
|
||||
${chunk.changes
|
||||
// @ts-expect-error - ln and ln2 exists where needed
|
||||
.map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`)
|
||||
.map((c) => `${'ln' in c ? c.ln : 'ln2' in c ? c.ln2 : ''} ${c.content}`)
|
||||
.join("\n")}
|
||||
\`\`\`
|
||||
`;
|
||||
|
@ -182,10 +181,24 @@ function createComment(file, chunk, aiResponses) {
|
|||
if (!file.to) {
|
||||
return [];
|
||||
}
|
||||
const lineNumber = Number(aiResponse.lineNumber);
|
||||
// Find the matching change in the chunk
|
||||
const change = chunk.changes.find((c) => {
|
||||
if ("ln" in c && c.ln === lineNumber)
|
||||
return true;
|
||||
if ("ln2" in c && c.ln2 === lineNumber)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
if (!change) {
|
||||
console.error(`Line number ${aiResponse.lineNumber} not found in the diff for file ${file.to}`);
|
||||
return [];
|
||||
}
|
||||
const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0;
|
||||
return {
|
||||
body: aiResponse.reviewComment,
|
||||
path: file.to,
|
||||
line: Number(aiResponse.lineNumber),
|
||||
line: commentLine,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue