diff --git a/package.json b/package.json index 5ec57c86..934414b5 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "open-ai-reviewer", + "name": "roast-my-code", "version": "1.0.0", - "description": "Open AI powered code reviews", + "description": "mean and aggressive code reviews by ChatGPT", "main": "lib/main.js", - "author": "Ville Saukkonen", + "author": "Christina Martinez, based on work by Ville Saukkonen", "license": "MIT", "scripts": { "build": "tsc", diff --git a/src/main.ts b/src/main.ts index 82e8d65d..f859f3cd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -164,16 +164,33 @@ function createComment( reviewComment: string; }> ): Array<{ body: string; path: string; line: number }> { - return aiResponses.flatMap((aiResponse) => { + const comments = aiResponses.flatMap((aiResponse) => { if (!file.to) { return []; } - return { - body: aiResponse.reviewComment, - path: file.to, - line: Number(aiResponse.lineNumber), - }; + // Log the AI response and the file path + console.log("AI Response:", aiResponse); + console.log("File Path:", file.to); + console.log("Chunk:", chunk); + + const lineNumber = Number(aiResponse.lineNumber); + + // Ensure the line number exists in the chunk + if (chunk.changes.some((change: { ln: number; ln2: number; }) => change.ln === lineNumber || change.ln2 === lineNumber)) { + return { + body: aiResponse.reviewComment, + path: file.to, + line: lineNumber, + }; + } else { + console.warn(`Line number ${lineNumber} does not exist in the diff for file ${file.to}`); + return []; + } }); + + // Log the comments before returning + console.log("Comments:", comments); + return comments; } async function createReviewComment(