mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 09: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
27
dist/index.js
vendored
27
dist/index.js
vendored
|
@ -197,10 +197,35 @@ require("./sourcemap-register.js");
|
||||||
for (const file of parsedDiff) {
|
for (const file of parsedDiff) {
|
||||||
if (file.to === "/dev/null") continue; // Ignore deleted files
|
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||||
for (const chunk of file.chunks) {
|
for (const chunk of file.chunks) {
|
||||||
|
const validLineNumbers = new Set();
|
||||||
|
chunk.changes.forEach((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 prompt = createPrompt(file, chunk, prDetails);
|
||||||
const aiResponse = yield getAIResponse(prompt);
|
const aiResponse = yield getAIResponse(prompt);
|
||||||
if (aiResponse) {
|
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) {
|
if (newComments) {
|
||||||
comments.push(...newComments);
|
comments.push(...newComments);
|
||||||
}
|
}
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
18
src/main.ts
18
src/main.ts
|
@ -109,10 +109,26 @@ async function analyzeCode(
|
||||||
for (const file of parsedDiff) {
|
for (const file of parsedDiff) {
|
||||||
if (file.to === "/dev/null") continue; // Ignore deleted files
|
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||||
for (const chunk of file.chunks) {
|
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 prompt = createPrompt(file, chunk, prDetails);
|
||||||
const aiResponse = await getAIResponse(prompt);
|
const aiResponse = await getAIResponse(prompt);
|
||||||
if (aiResponse) {
|
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) {
|
if (newComments) {
|
||||||
comments.push(...newComments);
|
comments.push(...newComments);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue