mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-28 20:14:14 +00:00
Refactor code analysis and review comment creation
The codebase has been refactored for improved maintainability and reliability. The `analyzeCode` and `createReviewComment` functions have been significantly updated to create comments based on AI responses, while respecting line limits and ignoring deleted files. Additionally, error handling has been optimized to provide clearer error messages when the context length exceeds the maximum limit.
This commit is contained in:
parent
06f5bdddfb
commit
d8265ef750
2 changed files with 365 additions and 150 deletions
513
dist/index.js
vendored
513
dist/index.js
vendored
|
@ -1,6 +1,360 @@
|
|||
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
/***/ 195:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.analyzeCode = void 0;
|
||||
const createPrompt_1 = __nccwpck_require__(3695);
|
||||
const getAIResponse_1 = __nccwpck_require__(8268);
|
||||
const createComment_1 = __nccwpck_require__(6206);
|
||||
function analyzeCode(parsedDiff, prDetails) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const comments = [];
|
||||
for (const file of parsedDiff) {
|
||||
if (file.to === "/dev/null")
|
||||
continue; // Ignore deleted files
|
||||
for (const chunk of file.chunks) {
|
||||
// Ignore diffs longer than 2000 characters
|
||||
if (chunk.content.length > 4000)
|
||||
continue;
|
||||
const prompt = (0, createPrompt_1.createPrompt)(file, chunk, prDetails);
|
||||
const aiResponse = yield (0, getAIResponse_1.getAIResponse)(prompt);
|
||||
if (aiResponse) {
|
||||
const newComments = (0, createComment_1.createComment)(file, chunk, aiResponse);
|
||||
if (newComments) {
|
||||
comments.push(...newComments);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return comments;
|
||||
});
|
||||
}
|
||||
exports.analyzeCode = analyzeCode;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6206:
|
||||
/***/ ((__unused_webpack_module, exports) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.createComment = void 0;
|
||||
function createComment(file, chunk, aiResponses) {
|
||||
return aiResponses.flatMap((aiResponse) => {
|
||||
if (!file.to) {
|
||||
return [];
|
||||
}
|
||||
return {
|
||||
body: aiResponse.reviewComment,
|
||||
path: file.to,
|
||||
line: Number(aiResponse.lineNumber),
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.createComment = createComment;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3695:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.createPrompt = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const language = core.getInput("language") || 'English';
|
||||
function createPrompt(file, chunk, prDetails) {
|
||||
return `Your task is to review pull requests. Instructions:
|
||||
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
||||
- Do not give positive comments or compliments.
|
||||
- Provide comments in ${language} language.
|
||||
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
||||
- Write the comment in GitHub Markdown format.
|
||||
- Use the given description only for the overall context and only comment the code.
|
||||
- IMPORTANT: NEVER suggest adding comments to 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.
|
||||
|
||||
Pull request title: ${prDetails.title}
|
||||
Pull request description:
|
||||
|
||||
---
|
||||
${prDetails.description}
|
||||
---
|
||||
|
||||
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")}
|
||||
\`\`\`
|
||||
`;
|
||||
}
|
||||
exports.createPrompt = createPrompt;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9325:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.createReviewComment = exports.octokit = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const rest_1 = __nccwpck_require__(5375);
|
||||
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
||||
exports.octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
||||
function createReviewComment(owner, repo, pull_number, comments) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield exports.octokit.pulls.createReview({
|
||||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
comments,
|
||||
event: "COMMENT",
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.createReviewComment = createReviewComment;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8268:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getAIResponse = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const openai_1 = __importDefault(__nccwpck_require__(47));
|
||||
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
||||
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
||||
const openai = new openai_1.default({
|
||||
apiKey: OPENAI_API_KEY,
|
||||
});
|
||||
function getAIResponse(prompt) {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const queryConfig = {
|
||||
model: OPENAI_API_MODEL,
|
||||
temperature: 0.2,
|
||||
max_tokens: 700,
|
||||
top_p: 1,
|
||||
frequency_penalty: 0,
|
||||
presence_penalty: 0,
|
||||
};
|
||||
const response = yield openai.chat.completions.create(Object.assign(Object.assign(Object.assign({}, queryConfig), (OPENAI_API_MODEL === "gpt-4-1106-preview"
|
||||
? { response_format: { type: "json_object" } }
|
||||
: {})), { messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: prompt,
|
||||
},
|
||||
] }));
|
||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
||||
console.log("GPT response:");
|
||||
console.log(res);
|
||||
const cleanupResponse = res
|
||||
.replace(/```json/g, "")
|
||||
.replace(/```/g, "");
|
||||
return JSON.parse(cleanupResponse).reviews;
|
||||
});
|
||||
}
|
||||
exports.getAIResponse = getAIResponse;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 87:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getDiff = void 0;
|
||||
const createReviewComment_1 = __nccwpck_require__(9325);
|
||||
function getDiff(owner, repo, pull_number) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield createReviewComment_1.octokit.pulls.get({
|
||||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
mediaType: { format: "diff" },
|
||||
});
|
||||
// @ts-expect-error - response.data is a string
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
exports.getDiff = getDiff;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8678:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getPRDetails = void 0;
|
||||
const fs_1 = __nccwpck_require__(7147);
|
||||
const createReviewComment_1 = __nccwpck_require__(9325);
|
||||
function getPRDetails() {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { repository, number } = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH || "", "utf8"));
|
||||
const prResponse = yield createReviewComment_1.octokit.pulls.get({
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name,
|
||||
pull_number: number,
|
||||
});
|
||||
return {
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name,
|
||||
pull_number: number,
|
||||
title: (_a = prResponse.data.title) !== null && _a !== void 0 ? _a : "",
|
||||
description: (_b = prResponse.data.body) !== null && _b !== void 0 ? _b : "",
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.getPRDetails = getPRDetails;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3109:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
|
@ -44,161 +398,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const fs_1 = __nccwpck_require__(7147);
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const openai_1 = __importDefault(__nccwpck_require__(47));
|
||||
const rest_1 = __nccwpck_require__(5375);
|
||||
const parse_diff_1 = __importDefault(__nccwpck_require__(4833));
|
||||
const minimatch_1 = __importDefault(__nccwpck_require__(2002));
|
||||
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
||||
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
||||
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
||||
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
||||
const openai = new openai_1.default({
|
||||
apiKey: OPENAI_API_KEY,
|
||||
});
|
||||
function getPRDetails() {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { repository, number } = JSON.parse((0, fs_1.readFileSync)(process.env.GITHUB_EVENT_PATH || "", "utf8"));
|
||||
const prResponse = yield octokit.pulls.get({
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name,
|
||||
pull_number: number,
|
||||
});
|
||||
return {
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name,
|
||||
pull_number: number,
|
||||
title: (_a = prResponse.data.title) !== null && _a !== void 0 ? _a : "",
|
||||
description: (_b = prResponse.data.body) !== null && _b !== void 0 ? _b : "",
|
||||
};
|
||||
});
|
||||
}
|
||||
function getDiff(owner, repo, pull_number) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield octokit.pulls.get({
|
||||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
mediaType: { format: "diff" },
|
||||
});
|
||||
// @ts-expect-error - response.data is a string
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
function analyzeCode(parsedDiff, prDetails) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const comments = [];
|
||||
for (const file of parsedDiff) {
|
||||
if (file.to === "/dev/null")
|
||||
continue; // Ignore deleted files
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return comments;
|
||||
});
|
||||
}
|
||||
function createPrompt(file, chunk, prDetails) {
|
||||
return `Your task is to review pull requests. Instructions:
|
||||
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
||||
- Do not give positive comments or compliments.
|
||||
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
||||
- Write the comment in GitHub Markdown format.
|
||||
- Use the given description only for the overall context and only comment the code.
|
||||
- IMPORTANT: NEVER suggest adding comments to 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.
|
||||
|
||||
Pull request title: ${prDetails.title}
|
||||
Pull request description:
|
||||
|
||||
---
|
||||
${prDetails.description}
|
||||
---
|
||||
|
||||
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")}
|
||||
\`\`\`
|
||||
`;
|
||||
}
|
||||
function getAIResponse(prompt) {
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const queryConfig = {
|
||||
model: OPENAI_API_MODEL,
|
||||
temperature: 0.2,
|
||||
max_tokens: 700,
|
||||
top_p: 1,
|
||||
frequency_penalty: 0,
|
||||
presence_penalty: 0,
|
||||
};
|
||||
try {
|
||||
const response = yield openai.chat.completions.create(Object.assign(Object.assign(Object.assign({}, queryConfig), (OPENAI_API_MODEL === "gpt-4-1106-preview"
|
||||
? { response_format: { type: "json_object" } }
|
||||
: {})), { messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: prompt,
|
||||
},
|
||||
] }));
|
||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
||||
return JSON.parse(res).reviews;
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error:", error);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
function createComment(file, chunk, aiResponses) {
|
||||
return aiResponses.flatMap((aiResponse) => {
|
||||
if (!file.to) {
|
||||
return [];
|
||||
}
|
||||
return {
|
||||
body: aiResponse.reviewComment,
|
||||
path: file.to,
|
||||
line: Number(aiResponse.lineNumber),
|
||||
};
|
||||
});
|
||||
}
|
||||
function createReviewComment(owner, repo, pull_number, comments) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield octokit.pulls.createReview({
|
||||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
comments,
|
||||
event: "COMMENT",
|
||||
});
|
||||
});
|
||||
}
|
||||
const createReviewComment_1 = __nccwpck_require__(9325);
|
||||
const analyzeCode_1 = __nccwpck_require__(195);
|
||||
const getPRDetails_1 = __nccwpck_require__(8678);
|
||||
const getDiff_1 = __nccwpck_require__(87);
|
||||
function main() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const prDetails = yield getPRDetails();
|
||||
const prDetails = yield (0, getPRDetails_1.getPRDetails)();
|
||||
let diff;
|
||||
const eventData = JSON.parse((0, fs_1.readFileSync)((_a = process.env.GITHUB_EVENT_PATH) !== null && _a !== void 0 ? _a : "", "utf8"));
|
||||
if (eventData.action === "opened") {
|
||||
diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
||||
diff = yield (0, getDiff_1.getDiff)(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
||||
}
|
||||
else if (eventData.action === "synchronize") {
|
||||
const newBaseSha = eventData.before;
|
||||
const newHeadSha = eventData.after;
|
||||
const response = yield octokit.repos.compareCommits({
|
||||
const response = yield createReviewComment_1.octokit.repos.compareCommits({
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3.diff",
|
||||
},
|
||||
|
@ -225,16 +443,13 @@ function main() {
|
|||
const filteredDiff = parsedDiff.filter((file) => {
|
||||
return !excludePatterns.some((pattern) => { var _a; return (0, minimatch_1.default)((_a = file.to) !== null && _a !== void 0 ? _a : "", pattern); });
|
||||
});
|
||||
const comments = yield analyzeCode(filteredDiff, prDetails);
|
||||
const comments = yield (0, analyzeCode_1.analyzeCode)(filteredDiff, prDetails);
|
||||
if (comments.length > 0) {
|
||||
yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
|
||||
yield (0, createReviewComment_1.createReviewComment)(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
|
||||
}
|
||||
});
|
||||
}
|
||||
main().catch((error) => {
|
||||
console.error("Error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
main();
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue