-
Notifications
You must be signed in to change notification settings - Fork 10
57 lines (46 loc) · 1.51 KB
/
require-reviewers.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
name: PR requirements
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- review_requested
- review_request_removed
- auto_merge_enabled
merge_group:
types: [checks_requested]
# Allow calling sharing this workflow with other repositories.
workflow_call:
jobs:
require-reviewer:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check for reviewers or reviews
run: |
# Ensure jq is installed
sudo apt-get install jq
jq -r ".pull_request.requested_reviewers" "$GITHUB_EVENT_PATH" | tee reviewers.json
REVIEWER_COUNT=$(cat reviewers.json | jq length)
if [ $REVIEWER_COUNT -ne 0 ]; then
exit 0
fi
jq -r ".pull_request.number" "$GITHUB_EVENT_PATH" | tee number.json
ISSUE_NUMBER=$(cat number.json | tr -d '\n')
if [ "$ISSUE_NUMBER" == "null" ]; then
echo "Not a PR - do not reqire reviewers"
exit 0
fi
curl \
--url https://api.github.com/repos/${{ github.repository }}/pulls/$ISSUE_NUMBER/reviews \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' | tee reviews.json
REVIEW_COUNT=$(cat reviews.json | jq length)
if [ $REVIEW_COUNT -ne 0 ]; then
exit 0
fi
echo "No reviewer and no review found."
exit 1