Skip to content

Commit

Permalink
Check for committee among the PR approval
Browse files Browse the repository at this point in the history
  • Loading branch information
jaisnan committed Jun 26, 2024
1 parent 52bea58 commit 20c6114
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/pr_approval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PR Approval Check

on:
pull_request_review:
types: [submitted]

jobs:
check_approvals:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub toml
- name: Check PR approvals
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
import os
import toml
from github import Github
def load_committee_members():
with open('pr_committee.toml', 'r') as f:
config = toml.load(f)
return set(config.get('pr_committee', []))
def check_approvals(repo, pr_number, committee_members):
pr = repo.get_pull(pr_number)
reviews = pr.get_reviews()
approved_committee_members = set()
for review in reviews:
if review.state == 'APPROVED' and review.user.login in committee_members:
approved_committee_members.add(review.user.login)
return len(approved_committee_members) >= 2
github_token = os.environ['GITHUB_TOKEN']
g = Github(github_token)
repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])
pr_number = int(os.environ['GITHUB_EVENT_PATH'].split('/')[-1].split('.')[0])
committee_members = load_committee_members()
if check_approvals(repo, pr_number, committee_members):
print("PR approved by at least 2 committee members.")
exit(0)
else:
print("PR does not have approval from at least 2 committee members.")
exit(1)
4 changes: 4 additions & 0 deletions pull_requests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[committee]
members = ["celinval",
"jaisnan"
]

0 comments on commit 20c6114

Please sign in to comment.