forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for committee among the PR approval
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[committee] | ||
members = ["celinval", | ||
"jaisnan" | ||
] |