From 274218e3fbfd02dc31733ea51f240ddda24d6ed3 Mon Sep 17 00:00:00 2001 From: Juan Diaz Date: Fri, 11 Jul 2025 16:04:20 -0400 Subject: [PATCH] Improve PR Review Automation with better error handling and permissions (#563) * Add PR review automation workflow and script closes #559 * Improve PR review automation with better error handling and permissions --- .github/workflows/pr-review-automation.yml | 5 +++++ scripts/pr-review-automation.js | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-review-automation.yml b/.github/workflows/pr-review-automation.yml index 2ed2b43c..818f9487 100644 --- a/.github/workflows/pr-review-automation.yml +++ b/.github/workflows/pr-review-automation.yml @@ -10,6 +10,11 @@ on: jobs: pr-review-automation: runs-on: ubuntu-latest + # Add permissions for the GITHUB_TOKEN to comment on PRs + permissions: + contents: read + pull-requests: write + issues: write steps: - uses: actions/checkout@v4 diff --git a/scripts/pr-review-automation.js b/scripts/pr-review-automation.js index f2d21970..0ddbb8bc 100644 --- a/scripts/pr-review-automation.js +++ b/scripts/pr-review-automation.js @@ -5,9 +5,16 @@ const token = process.env.GITHUB_TOKEN; const octokit = getOctokit(token); async function run() { - const pr = context.payload.pull_request; - const { owner, repo } = context.repo; - const prNumber = pr.number; + try { + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const prNumber = pr.number; + + console.log(`Working with repository: ${owner}/${repo}`); + console.log(`PR number: ${prNumber}`); + console.log(`PR author: ${pr.user.login}`); + console.log(`Head repo: ${pr.head.repo.full_name}`); + console.log(`Base repo: ${pr.base.repo.full_name}`); const filesChanged = await octokit.rest.pulls.listFiles({ owner, @@ -67,6 +74,11 @@ async function run() { } else { console.log("No issues found in this PR."); } + } catch (error) { + console.error("Error in PR review automation:", error); + // Don't exit with error code to avoid failing the entire workflow + // Just log the error and continue + } } async function checkForNewApiLinks(owner, repo, pr) {