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 workflow to check for required reviews #370

Closed
wants to merge 3 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
56 changes: 56 additions & 0 deletions .github/workflows/check-required-reviews.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Check required reviews

on:
pull_request_review:
types: [submitted]

jobs:
check-reviews:
if: contains(github.event.pull_request.labels.*.name, 'full_review')
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Check reviews
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: python
run: |
"""Check there are enough approving reviews."""
import json
import os
import re
import subprocess
import sys

REQUIRED_REVIEWS = 2

repo = "${{ github.repository }}"
pr_number = "${{ github.event.pull_request.number }}"

# Get info on PR labels and reviews.
pr_info = json.loads(
subprocess.run(
("gh", "pr", "--json", "reviews", "--repo", repo, "view", pr_number),
check=True,
capture_output=True,
timeout=60,
text=True,
).stdout
)

# Check for enough reviews. Newer reviews invalidate older ones.
approving_reviewers = set()
for review in sorted(pr_info["reviews"], key=lambda r: r["submittedAt"]):
if review["state"] == "APPROVED":
approving_reviewers.add(review["author"]["login"])
elif review["state"] == "CHANGES_REQUESTED":
approving_reviewers.discard(review["author"]["login"])

if len(approving_reviewers) < REQUIRED_REVIEWS:
print(f"\033[31m❌ Not enough reviews.\033[0m ({len(approving_reviewers)}/{REQUIRED_REVIEWS})")
sys.exit(1)
print(f"\033[32m✔ Sufficient reviews.\033[0m ({len(approving_reviewers)}/{REQUIRED_REVIEWS})")
2 changes: 1 addition & 1 deletion .github/workflows/conda-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: Create pull requests
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if $(sha256sum --status -c ${{ runner.temp }}/lock_file_hashes); then
echo "Lock files unchanged. Skipping pull request..."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Create pull requests
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if $(sha256sum --status -c ${{ runner.temp }}/config_file_hashes); then
echo "Config file unchanged. Skipping pull request..."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
coverage html
- name: Add report to PR
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# This links to a hosted version of the HTML report.
tar -czf coverage-report.tar.gz htmlcov/
Expand Down