mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-09-10 11:47:08 +00:00
Update main.ts
This commit is contained in:
parent
e834b3d3b4
commit
cbb2d0dcdf
1 changed files with 23 additions and 35 deletions
40
src/main.ts
40
src/main.ts
|
@ -182,43 +182,30 @@ async function createReviewComment(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!OPENAI_API_KEY || OPENAI_API_KEY.trim() === "") {
|
|
||||||
console.error("❌ OPENAI_API_KEY is missing or empty!");
|
|
||||||
} else {
|
|
||||||
console.log("✅ OPENAI_API_KEY is set.");
|
|
||||||
}
|
|
||||||
console.log(
|
|
||||||
const prDetails = await getPRDetails();
|
const prDetails = await getPRDetails();
|
||||||
let diff: string | null;
|
|
||||||
const eventData = JSON.parse(
|
|
||||||
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (eventData.action === "opened") {
|
// pobierz szczegóły PR (base i head sha)
|
||||||
diff = await getDiff(
|
const prResponse = await octokit.pulls.get({
|
||||||
prDetails.owner,
|
owner: prDetails.owner,
|
||||||
prDetails.repo,
|
repo: prDetails.repo,
|
||||||
prDetails.pull_number
|
pull_number: prDetails.pull_number,
|
||||||
);
|
});
|
||||||
} else if (eventData.action === "synchronize") {
|
|
||||||
const newBaseSha = eventData.before;
|
|
||||||
const newHeadSha = eventData.after;
|
|
||||||
|
|
||||||
|
const baseSha = prResponse.data.base.sha;
|
||||||
|
const headSha = prResponse.data.head.sha;
|
||||||
|
|
||||||
|
// pobierz diff całego PR
|
||||||
const response = await octokit.repos.compareCommits({
|
const response = await octokit.repos.compareCommits({
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/vnd.github.v3.diff",
|
accept: "application/vnd.github.v3.diff",
|
||||||
},
|
},
|
||||||
owner: prDetails.owner,
|
owner: prDetails.owner,
|
||||||
repo: prDetails.repo,
|
repo: prDetails.repo,
|
||||||
base: newBaseSha,
|
base: baseSha,
|
||||||
head: newHeadSha,
|
head: headSha,
|
||||||
});
|
});
|
||||||
|
|
||||||
diff = String(response.data);
|
const diff = String(response.data);
|
||||||
} else {
|
|
||||||
console.log("Unsupported event:", process.env.GITHUB_EVENT_NAME);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!diff) {
|
if (!diff) {
|
||||||
console.log("No diff found");
|
console.log("No diff found");
|
||||||
|
@ -239,6 +226,7 @@ async function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const comments = await analyzeCode(filteredDiff, prDetails);
|
const comments = await analyzeCode(filteredDiff, prDetails);
|
||||||
|
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
await createReviewComment(
|
await createReviewComment(
|
||||||
prDetails.owner,
|
prDetails.owner,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue