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 enforce group approvals #158

Merged
merged 3 commits into from
Nov 10, 2024
Merged
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
42 changes: 42 additions & 0 deletions .github/workflows/group-approvals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Enforce Group-Based Approvals
on:
pull_request_review:
types: [submitted]

jobs:
enforce_approvals:
runs-on: ubuntu-latest
steps:
- name: Check Required Approvals
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GROUP_1: "nickytaiko,JMcryptospain,Pigitaiko,swarna1101,JBScaled"
GROUP_2: "bennettyong,myronrotter,KorbinianK,bearni95"
run: |
GROUP_1_REQUIRED=0
GROUP_2_REQUIRED=0
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")

# Fetch pull request reviews
REVIEWS=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/reviews" | jq -r '.[] | select(.state == "APPROVED") | .user.login')

# Check approvals against each group
IFS=',' read -ra GROUP1 <<< "$GROUP_1"
IFS=',' read -ra GROUP2 <<< "$GROUP_2"

for APPROVER in $REVIEWS; do
if [[ " ${GROUP1[@]} " =~ " $APPROVER " ]]; then
GROUP_1_REQUIRED=1
elif [[ " ${GROUP2[@]} " =~ " $APPROVER " ]]; then
GROUP_2_REQUIRED=1
fi
done

# Validate if both groups have approved
if [[ $GROUP_1_REQUIRED -eq 1 && $GROUP_2_REQUIRED -eq 1 ]]; then
echo "Required approvals from both groups present."
else
echo "Approval from both groups is required."
exit 1
fi
Loading