do not comment deleted files

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

19
dist/index.js vendored
View file

@ -1,4 +1,4 @@
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 3109:
@ -89,13 +89,15 @@ function analyzeCode(parsedDiff, prDetails) {
return __awaiter(this, void 0, void 0, function* () {
const comments = [];
for (const file of parsedDiff) {
for (const chunk of file.chunks) {
const prompt = createPrompt(file, chunk, prDetails);
const aiResponse = yield getAIResponse(prompt);
if (aiResponse) {
const newComments = createComment(file, chunk, aiResponse);
if (newComments) {
comments.push(...newComments);
if (file.to !== '/dev/null') {
for (const chunk of file.chunks) {
const prompt = createPrompt(file, chunk, prDetails);
const aiResponse = yield getAIResponse(prompt);
if (aiResponse) {
const newComments = createComment(file, chunk, aiResponse);
if (newComments) {
comments.push(...newComments);
}
}
}
}
@ -18526,4 +18528,3 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/
/******/ })()
;
//# sourceMappingURL=index.js.map

View file

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

View file

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