mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-22 10:36:47 +00:00
Verify if an AI comment is part of the actual PR changes prior to submit it
This commit is contained in:
parent
912010c7b3
commit
1abe8317f1
3 changed files with 44 additions and 3 deletions
18
src/main.ts
18
src/main.ts
|
@ -109,10 +109,26 @@ async function analyzeCode(
|
|||
for (const file of parsedDiff) {
|
||||
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||
for (const chunk of file.chunks) {
|
||||
const validLineNumbers = new Set<number>();
|
||||
chunk.changes.forEach((change: parseDiff.Change) => {
|
||||
if ("ln" in change && change.ln) validLineNumbers.add(change.ln);
|
||||
if ("ln2" in change && change.ln2) validLineNumbers.add(change.ln2);
|
||||
|
||||
// Generate a range of line numbers for additive changes.
|
||||
if ("ln1" in change && "ln2" in change && change.ln1 && change.ln2) {
|
||||
for (let i = change.ln1; i <= change.ln2; i++) {
|
||||
validLineNumbers.add(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const prompt = createPrompt(file, chunk, prDetails);
|
||||
const aiResponse = await getAIResponse(prompt);
|
||||
if (aiResponse) {
|
||||
const newComments = createComment(file, chunk, aiResponse);
|
||||
const validAIResponses = aiResponse.filter((response) =>
|
||||
validLineNumbers.has(Number(response.lineNumber))
|
||||
);
|
||||
const newComments = createComment(file, chunk, validAIResponses);
|
||||
if (newComments) {
|
||||
comments.push(...newComments);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue