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