mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 17:46:47 +00:00
review changed files only
This commit is contained in:
parent
32f7a8317c
commit
0f627714f1
3 changed files with 106 additions and 9 deletions
48
dist/index.js
vendored
48
dist/index.js
vendored
|
@ -89,6 +89,8 @@ 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);
|
||||
|
@ -103,6 +105,30 @@ function analyzeCode(parsedDiff, prDetails) {
|
|||
return comments;
|
||||
});
|
||||
}
|
||||
function getChangedFiles(owner, repo, baseSha, headSha) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const response = yield octokit.repos.compareCommits({
|
||||
owner,
|
||||
repo,
|
||||
base: baseSha,
|
||||
head: headSha,
|
||||
});
|
||||
return response.data.diff_url;
|
||||
});
|
||||
}
|
||||
function getBaseAndHeadShas(owner, repo, pull_number) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const prResponse = yield octokit.pulls.get({
|
||||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
});
|
||||
return {
|
||||
baseSha: prResponse.data.base.sha,
|
||||
headSha: prResponse.data.head.sha,
|
||||
};
|
||||
});
|
||||
}
|
||||
function createPrompt(file, chunk, prDetails) {
|
||||
return `- Provide the response in following JSON format: [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]
|
||||
- Do not give positive comments or compliments.
|
||||
|
@ -181,14 +207,27 @@ function createReviewComment(owner, repo, pull_number, comments) {
|
|||
});
|
||||
});
|
||||
}
|
||||
(function main() {
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const prDetails = yield getPRDetails();
|
||||
const diff = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
||||
if (!diff) {
|
||||
const { baseSha, headSha } = yield getBaseAndHeadShas(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
||||
let diffUrl;
|
||||
if (process.env.GITHUB_EVENT_NAME === "pull_request") {
|
||||
diffUrl = yield getDiff(prDetails.owner, prDetails.repo, prDetails.pull_number);
|
||||
}
|
||||
else if (process.env.GITHUB_EVENT_NAME === "push") {
|
||||
diffUrl = yield getChangedFiles(prDetails.owner, prDetails.repo, baseSha, headSha);
|
||||
}
|
||||
else {
|
||||
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
|
||||
return;
|
||||
}
|
||||
if (!diffUrl) {
|
||||
console.log("No diff found");
|
||||
return;
|
||||
}
|
||||
const diffResponse = yield octokit.request({ url: diffUrl });
|
||||
const diff = diffResponse.data;
|
||||
const parsedDiff = (0, parse_diff_1.default)(diff);
|
||||
const excludePatterns = core
|
||||
.getInput("exclude")
|
||||
|
@ -202,7 +241,8 @@ function createReviewComment(owner, repo, pull_number, comments) {
|
|||
yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
|
||||
}
|
||||
});
|
||||
})().catch((error) => {
|
||||
}
|
||||
main().catch((error) => {
|
||||
console.error("Error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
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