diff --git a/.github/pull_requests.toml b/.github/pull_requests.toml index 979d2ad13b80e..bb1af6dfc1388 100644 --- a/.github/pull_requests.toml +++ b/.github/pull_requests.toml @@ -10,5 +10,6 @@ members = [ "qinheping", "tautschnig", "jaisnan", - "patricklam" + "patricklam", + "carolynzech", ] diff --git a/.github/workflows/pr_approval.yml b/.github/workflows/pr_approval.yml index fbac5035e2d3a..1ded62522cf5e 100644 --- a/.github/workflows/pr_approval.yml +++ b/.github/workflows/pr_approval.yml @@ -5,18 +5,19 @@ name: Check PR Approvals # To protect against that scenario, we can turn on number of approvals required to 2 in the github settings # of the repository on: + workflow_dispatch: + pull_request: + branches: [ main ] pull_request_review: types: [submitted] - workflow_dispatch: - -# Without these permissions, we get a 403 error from github -# for trying to modify the pull request for newer project. -# Source: https://stackoverflow.com/a/76994510 -permissions: write-all + push: + paths: + - 'library/**' + - 'doc/src/challenges/' + - '.github/workflows' jobs: check-approvals: - if: github.event.review.state == 'APPROVED' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - name: Checkout repository @@ -58,7 +59,7 @@ jobs: pull_number }); - const relevantPaths = ['library/', 'doc/src/challenges/']; + const relevantPaths = ['library/', 'doc/src/challenges/', '.github/workflows']; const isRelevantPR = files.data.some(file => relevantPaths.some(path => file.filename.startsWith(path)) ); @@ -73,7 +74,6 @@ jobs: const tomlContent = fs.readFileSync('.github/pull_requests.toml', 'utf8'); console.log('TOML content:', tomlContent); const tomlData = toml.parse(tomlContent); - console.log('Parsed TOML data:', JSON.stringify(tomlData, null, 2)); if (!tomlData.committee || !Array.isArray(tomlData.committee.members)) { throw new Error('committee.members is not an array in the TOML file'); @@ -110,52 +110,16 @@ jobs: // Core logic that checks if the approvers are in the committee const checkName = 'PR Approval Status'; - const conclusion = (approvers.size >= requiredApprovals && currentCountfromCommittee >= 2) ? 'success' : 'failure'; + const conclusion = (currentCountfromCommittee >= requiredApprovals) ? 'success' : 'failure'; const output = { title: checkName, summary: `PR has ${approvers.size} total approvals and ${requiredApprovals} required approvals.`, text: `Approvers: ${Array.from(approvers).join(', ')}\nRequired Approvers: ${requiredApprovers.join(', ')}` }; - // Get PR details - const pr = await github.rest.pulls.get({ - owner, - repo, - pull_number - }); - - // Create or update check run - const checkRuns = await github.rest.checks.listForRef({ - owner, - repo, - ref: pr.data.head.sha, - check_name: checkName - }); - - // Reuse the same workflow everytime there's a new review submitted - // instead of creating new workflows. Better efficiency and readability - // as the number of workflows is kept to a minimal number - if (checkRuns.data.total_count > 0) { - await github.rest.checks.update({ - owner, - repo, - check_run_id: checkRuns.data.check_runs[0].id, - status: 'completed', - conclusion, - output - }); - } else { - await github.rest.checks.create({ - owner, - repo, - name: checkName, - head_sha: pr.data.head.sha, - status: 'completed', - conclusion, - output - }); - } - + // Simplify to not use github create at all if (conclusion === 'failure') { core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApprovals}`); + } else { + console.log(`PR has sufficient approvals (${approvers.size}/${requiredApprovals})`); }