diff --git a/src/main.ts b/src/main.ts index 75f4402..44d3f76 100644 --- a/src/main.ts +++ b/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,