-
Notifications
You must be signed in to change notification settings - Fork 883
58 lines (52 loc) · 2.37 KB
/
pr-approvals.yaml
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
# All PRs except trivial ones should require 2 approvals, since this a global setting
# we cannot make this decision from github configuration alone. So we set the required
# approved in github to 1 and make this check required which will enforce 2 approvals
# unless overwritten or only CI files are touched.
name: PR Approval Check
"on":
pull_request:
types: [opened, synchronize, reopened, edited, auto_merge_enabled, auto_merge_disabled]
branches: [main]
pull_request_review:
jobs:
check_approvals:
name: Check for sufficient approvals
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Check for sufficient approvals
shell: bash --norc --noprofile {0}
env:
BODY: ${{ github.event.pull_request.body }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.number }}
run: |
echo "Event is: "
cat <<EOF
${{ toJSON(github.event) }}
EOF
echo "PR number is $PR_NUMBER"
echo "$BODY" | egrep -qsi '^disable-check:.*\<approval-count\>'
if [[ $? -ne 0 ]]; then
# Get the list of modified files in this pull request
echo "Modified files: "
gh pr view $PR_NUMBER --json files
# Get modified files, but exclude those that are workflow
# files or are related to Hypercore table access
# method. These require only a single reviewer.
files=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path | select(startswith(".github") or test("hypercore|columnar_scan") | not)')
# Get the number of approvals in this pull request
echo "Reviews: "
gh pr view $PR_NUMBER --json reviews
approvals=$(gh pr view $PR_NUMBER --json reviews --jq '[.reviews.[] | select((.authorAssociation == "MEMBER" or .authorAssociation == "CONTRIBUTOR") and .state == "APPROVED")] | length')
if [[ $approvals -lt 2 ]] && [[ "${files}" ]] ; then
echo "This pull request requires 2 approvals before merging."
echo
echo "For trivial changes, you may disable this check by adding this trailer to the pull request message:"
echo
echo "Disable-check: approval-count"
echo
exit 1
fi
fi