diff --git a/pull_requests.toml b/.github/pull_requests.toml similarity index 63% rename from pull_requests.toml rename to .github/pull_requests.toml index 06f4178998347..3bfff6ba9eca0 100644 --- a/pull_requests.toml +++ b/.github/pull_requests.toml @@ -1,4 +1,5 @@ [committee] members = ["celinval", -"jaisnan" +"jaisnan", +"jaisu-1" ] diff --git a/.github/workflows/pr_approval.yml b/.github/workflows/pr_approval.yml index 0fca338dde0f2..5719a16ab5da3 100644 --- a/.github/workflows/pr_approval.yml +++ b/.github/workflows/pr_approval.yml @@ -7,14 +7,22 @@ on: jobs: check-approvals: - if: github.event.review.state == 'APPROVED' + if: github.event.review.state == 'APPROVED' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install TOML parser + run: npm install @iarna/toml + - name: Check PR Relevance and Approvals uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | + const fs = require('fs'); + const toml = require('@iarna/toml'); const { owner, repo } = context.repo; let pull_number; @@ -52,11 +60,10 @@ jobs: return; } - // If we're here, the PR is relevant. Now check if it's an approval or manual trigger - if (github.event_name === 'pull_request_review' && github.event.review.state !== 'approved') { - console.log('Not an approval. Exiting workflow.'); - return; - } + // Read and parse the TOML file + const tomlContent = fs.readFileSync('.github/pull_requests.toml', 'utf8'); + const tomlData = toml.parse(tomlContent); + const requiredApprovers = tomlData.required_approvers; // Get all reviews const reviews = await github.rest.pulls.listReviews({ @@ -71,15 +78,20 @@ jobs: .map(review => review.user.login) ); + const requiredApprovals = 2; + const requiredApproversCount = Array.from(approvers) + .filter(approver => requiredApprovers.includes(approver)) + .length; + console.log('PR Approvers:', Array.from(approvers)); + console.log('Required Approvers:', requiredApproversCount); - const requiredApprovals = 2; const checkName = 'PR Approval Status'; - const conclusion = approvers.size >= requiredApprovals ? 'success' : 'failure'; + const conclusion = (approvers.size >= requiredApprovals && requiredApproversCount >= 2) ? 'success' : 'failure'; const output = { title: checkName, - summary: `PR has ${approvers.size}/${requiredApprovals} required approvals.`, - text: `Approvers: ${Array.from(approvers).join(', ')}` + summary: `PR has ${approvers.size} total approvals and ${requiredApproversCount} required approvals.`, + text: `Approvers: ${Array.from(approvers).join(', ')}\nRequired Approvers: ${requiredApprovers.join(', ')}` }; // Get PR details @@ -119,5 +131,5 @@ jobs: } if (conclusion === 'failure') { - core.setFailed(`PR needs at least ${requiredApprovals} approvals. Current approvals: ${approvers.size}`); + core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApproversCount}`); } diff --git a/README.md b/README.md index b718f3fc6b1cd..0ed4d1a77d85f 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,5 @@ See [LICENSE-APACHE](https://github.com/model-checking/kani/blob/main/LICENSE-AP Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses. See [the Rust repository](https://github.com/rust-lang/rust) for details. + +##CHECKING THAT THIS DOESNT TRIGGER THE BOT