do not comment deleted files

This commit is contained in:
Daniel Prentis 2023-03-30 19:07:04 +02:00
parent cc0ff7a63b
commit a58f3e3c83
3 changed files with 1323 additions and 1321 deletions

2615
dist/index.js vendored

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"package": "ncc build --source-map --license licenses.txt", "package": "ncc build",
"format": "prettier --write .", "format": "prettier --write .",
"lint": "prettier --check ." "lint": "prettier --check ."
}, },

View file

@ -64,13 +64,15 @@ async function analyzeCode(
const comments: Array<{ body: string; path: string; line: number }> = []; const comments: Array<{ body: string; path: string; line: number }> = [];
for (const file of parsedDiff) { for (const file of parsedDiff) {
for (const chunk of file.chunks) { if (file.to !== '/dev/null') {
const prompt = createPrompt(file, chunk, prDetails); for (const chunk of file.chunks) {
const aiResponse = await getAIResponse(prompt); const prompt = createPrompt(file, chunk, prDetails);
if (aiResponse) { const aiResponse = await getAIResponse(prompt);
const newComments = createComment(file, chunk, aiResponse); if (aiResponse) {
if (newComments) { const newComments = createComment(file, chunk, aiResponse);
comments.push(...newComments); if (newComments) {
comments.push(...newComments);
}
} }
} }
} }
@ -86,9 +88,8 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
- Write the comment in GitHub markdown. - Write the comment in GitHub markdown.
- Use the given description only for the overall context and only comment the code. - Use the given description only for the overall context and only comment the code.
Review the following code diff in the file "${ Review the following code diff in the file "${file.to
file.to }" and take the pull request title and description into account when writing the response.
}" and take the pull request title and description into account when writing the response.
Pull request title: ${prDetails.title} Pull request title: ${prDetails.title}
Pull request description: Pull request description:
@ -102,9 +103,9 @@ Git diff to review:
\`\`\`diff \`\`\`diff
${chunk.content} ${chunk.content}
${chunk.changes ${chunk.changes
// @ts-expect-error - ln and ln2 exists where needed // @ts-expect-error - ln and ln2 exists where needed
.map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`)
.join("\n")} .join("\n")}
\`\`\` \`\`\`
`; `;
} }