mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 10:06:47 +00:00
CICO-111286: Include diff_hunk in the review comments
This commit is contained in:
parent
2d083cc61e
commit
c2dee0d45a
3 changed files with 16 additions and 6 deletions
13
src/main.ts
13
src/main.ts
|
@ -80,8 +80,8 @@ async function analyzeCode(
|
|||
parsedDiff: File[],
|
||||
prDetails: PRDetails,
|
||||
existingComments: Array<{ path: string; line: number; body: string }>
|
||||
): Promise<Array<{ body: string; path: string; line: number }>> {
|
||||
const comments: 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; diff_hunk: string }> = [];
|
||||
|
||||
// Log the parsed diff for debugging
|
||||
console.log("Parsed Diff:", JSON.stringify(parsedDiff, null, 2));
|
||||
|
@ -440,7 +440,7 @@ function createComment(
|
|||
lineNumber: string;
|
||||
reviewComment: string;
|
||||
}>
|
||||
): Array<{ body: string; path: string; line: number }> {
|
||||
): Array<{ body: string; path: string; line: number; diff_hunk: string }> {
|
||||
return aiResponses.flatMap((aiResponse) => {
|
||||
if (!file.to) {
|
||||
return [];
|
||||
|
@ -461,11 +461,13 @@ function createComment(
|
|||
}
|
||||
|
||||
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 {
|
||||
body: aiResponse.reviewComment,
|
||||
path: file.to,
|
||||
line: commentLine,
|
||||
diff_hunk: diff_hunk.trim(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -474,7 +476,7 @@ async function createReviewComment(
|
|||
owner: string,
|
||||
repo: string,
|
||||
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
|
||||
): Promise<void> {
|
||||
const validComments = comments.filter(comment => comment.path && comment.line > 0 && comment.body.trim() !== "");
|
||||
|
@ -497,6 +499,9 @@ async function createReviewComment(
|
|||
line: comment.line,
|
||||
side: 'RIGHT', // Ensure the comment is on the right side of the diff
|
||||
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) {
|
||||
console.error("Error creating review comment:", error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue