Fix the bot to add review comments

This commit is contained in:
Arun Murugan 2024-05-22 09:49:41 -04:00
parent fcd39ade07
commit f2f7079221
3 changed files with 38 additions and 11 deletions

19
dist/index.js vendored
View file

@ -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,
};
});
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long