Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sample test #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pull_requests.toml → .github/pull_requests.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[committee]
members = ["celinval",
"jaisnan"
"jaisnan",
"jaisu-1"
]
34 changes: 23 additions & 11 deletions .github/workflows/pr_approval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand Down Expand Up @@ -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}`);
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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