mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 01:56:47 +00:00
Merge pull request #15 from arunsnt/CICO-111286
CICO-111286: Include diff_hunk in the review comments
This commit is contained in:
commit
6f6b38e5a9
3 changed files with 16 additions and 6 deletions
7
dist/index.js
vendored
7
dist/index.js
vendored
|
@ -460,10 +460,12 @@ function createComment(file, chunk, aiResponses) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0;
|
const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0;
|
||||||
|
const diff_hunk = chunk.content + "\n" + chunk.changes.map(c => `${c.type === 'add' ? '+' : c.type === 'del' ? '-' : ' '} ${c.content}`).join("\n");
|
||||||
return {
|
return {
|
||||||
body: aiResponse.reviewComment,
|
body: aiResponse.reviewComment,
|
||||||
path: file.to,
|
path: file.to,
|
||||||
line: commentLine,
|
line: commentLine,
|
||||||
|
diff_hunk: diff_hunk.trim(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -485,7 +487,10 @@ function createReviewComment(owner, repo, pull_number, comments, commit_id) {
|
||||||
path: comment.path,
|
path: comment.path,
|
||||||
line: comment.line,
|
line: comment.line,
|
||||||
side: 'RIGHT',
|
side: 'RIGHT',
|
||||||
commit_id, // Include commit_id in the request
|
commit_id,
|
||||||
|
start_line: comment.line,
|
||||||
|
start_side: 'RIGHT',
|
||||||
|
diff_hunk: comment.diff_hunk, // Include diff_hunk in the request
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
13
src/main.ts
13
src/main.ts
|
@ -80,8 +80,8 @@ async function analyzeCode(
|
||||||
parsedDiff: File[],
|
parsedDiff: File[],
|
||||||
prDetails: PRDetails,
|
prDetails: PRDetails,
|
||||||
existingComments: Array<{ path: string; line: number; body: string }>
|
existingComments: Array<{ path: string; line: number; body: string }>
|
||||||
): Promise<Array<{ body: string; path: string; line: number }>> {
|
): Promise<Array<{ body: string; path: string; line: number; diff_hunk: string }>> {
|
||||||
const comments: Array<{ body: string; path: string; line: number }> = [];
|
const comments: Array<{ body: string; path: string; line: number; diff_hunk: string }> = [];
|
||||||
|
|
||||||
// Log the parsed diff for debugging
|
// Log the parsed diff for debugging
|
||||||
console.log("Parsed Diff:", JSON.stringify(parsedDiff, null, 2));
|
console.log("Parsed Diff:", JSON.stringify(parsedDiff, null, 2));
|
||||||
|
@ -440,7 +440,7 @@ function createComment(
|
||||||
lineNumber: string;
|
lineNumber: string;
|
||||||
reviewComment: string;
|
reviewComment: string;
|
||||||
}>
|
}>
|
||||||
): Array<{ body: string; path: string; line: number }> {
|
): Array<{ body: string; path: string; line: number; diff_hunk: string }> {
|
||||||
return aiResponses.flatMap((aiResponse) => {
|
return aiResponses.flatMap((aiResponse) => {
|
||||||
if (!file.to) {
|
if (!file.to) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -461,11 +461,13 @@ function createComment(
|
||||||
}
|
}
|
||||||
|
|
||||||
const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0;
|
const commentLine = "ln" in change ? change.ln : "ln2" in change ? change.ln2 : 0;
|
||||||
|
const diff_hunk = chunk.content + "\n" + chunk.changes.map(c => `${c.type === 'add' ? '+' : c.type === 'del' ? '-' : ' '} ${c.content}`).join("\n");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
body: aiResponse.reviewComment,
|
body: aiResponse.reviewComment,
|
||||||
path: file.to,
|
path: file.to,
|
||||||
line: commentLine,
|
line: commentLine,
|
||||||
|
diff_hunk: diff_hunk.trim(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -474,7 +476,7 @@ async function createReviewComment(
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
comments: Array<{ body: string; path: string; line: number }>,
|
comments: Array<{ body: string; path: string; line: number; diff_hunk: string }>,
|
||||||
commit_id: string
|
commit_id: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== "");
|
const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== "");
|
||||||
|
@ -497,6 +499,9 @@ async function createReviewComment(
|
||||||
line: comment.line,
|
line: comment.line,
|
||||||
side: 'RIGHT', // Ensure the comment is on the right side of the diff
|
side: 'RIGHT', // Ensure the comment is on the right side of the diff
|
||||||
commit_id, // Include commit_id in the request
|
commit_id, // Include commit_id in the request
|
||||||
|
start_line: comment.line,
|
||||||
|
start_side: 'RIGHT',
|
||||||
|
diff_hunk: comment.diff_hunk, // Include diff_hunk in the request
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error creating review comment:", error);
|
console.error("Error creating review comment:", error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue