mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-02-20 16:20:27 +00:00
Only comment on lines that are part of the changed code
This commit is contained in:
parent
a9a064dfa1
commit
897fedd47c
1 changed files with 20 additions and 4 deletions
24
src/main.ts
24
src/main.ts
|
@ -86,10 +86,9 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
||||||
- Write the comment in GitHub Markdown format.
|
- Write the comment in GitHub Markdown format.
|
||||||
- Use the given description only for the overall context and only comment the code.
|
- Use the given description only for the overall context and only comment the code.
|
||||||
- IMPORTANT: NEVER suggest adding comments to the code.
|
- IMPORTANT: NEVER suggest adding comments to the code.
|
||||||
|
- IMPORTANT: Only comment on lines that are part of the changed code (lines starting with + or -).
|
||||||
|
|
||||||
Review the following code diff in the file "${
|
Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.
|
||||||
file.to
|
|
||||||
}" and take the pull request title and description into account when writing the response.
|
|
||||||
|
|
||||||
Pull request title: ${prDetails.title}
|
Pull request title: ${prDetails.title}
|
||||||
Pull request description:
|
Pull request description:
|
||||||
|
@ -158,10 +157,27 @@ function createComment(
|
||||||
if (!file.to) {
|
if (!file.to) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert lineNumber to number
|
||||||
|
const lineNum = Number(aiResponse.lineNumber);
|
||||||
|
|
||||||
|
// Verify the line number is within the current chunk
|
||||||
|
const isLineInChunk = chunk.changes.some(
|
||||||
|
(change) =>
|
||||||
|
// Check both new and old line numbers
|
||||||
|
(change.ln && change.ln === lineNum) ||
|
||||||
|
(change.ln2 && change.ln2 === lineNum)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isLineInChunk) {
|
||||||
|
console.log(`Warning: Line ${lineNum} is not part of the current diff chunk in ${file.to}`);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
body: aiResponse.reviewComment,
|
body: aiResponse.reviewComment,
|
||||||
path: file.to,
|
path: file.to,
|
||||||
line: Number(aiResponse.lineNumber),
|
line: lineNum,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue