-
Notifications
You must be signed in to change notification settings - Fork 35
63 lines (52 loc) · 2.07 KB
/
review-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Enforce Review Rules
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
enforce-review-rules:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if PR modifies specific path
shell: bash
id: check-path
run: |
BASE_SHA=$(jq -r .pull_request.base.sha < $GITHUB_EVENT_PATH)
HEAD_SHA=$(jq -r .pull_request.head.sha < $GITHUB_EVENT_PATH)
git fetch origin $BASE_SHA $HEAD_SHA
files=$(git diff --name-only $BASE_SHA $HEAD_SHA | tr '\n' ' ')
echo "files=$files" >> $GITHUB_OUTPUT
if echo "$files" | grep -q 'src/contracts/'; then
echo "specific_path=true" >> $GITHUB_OUTPUT
else
echo "specific_path=false" >> $GITHUB_OUTPUT
fi
- name: Ensure required reviewers
shell: bash
id: ensure-reviewers
run: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
PR_NUMBER=${{ github.event.pull_request.number }}
REPO=${{ github.repository }}
# Fetch approved and non-dismissed reviews of the PR
REVIEWERS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \
| jq -r '[.[] | select(.state == "APPROVED" and .dismissed_at == null) | .user.login] | unique | .[]')
if [ $? -ne 0 ]; then
echo "Failed to fetch reviews"
exit 1
fi
NUM_REVIEWERS=$(echo "$REVIEWERS" | wc -w)
# Check review requirements
if [ "${{ steps.check-path.outputs.specific_path }}" == "true" ]; then
if [ "$NUM_REVIEWERS" -lt 2 ]; then
echo "Insufficient reviewers for src/contracts/ path. Required: 2 reviewers."
echo "review_check_passed=false" >> $GITHUB_OUTPUT
exit 1
fi
fi
echo "review_check_passed=true" >> $GITHUB_OUTPUT
- name: Success message
if: steps.ensure-reviewers.outputs.review_check_passed == 'true'
run: echo "Review checks passed successfully!"