-
Notifications
You must be signed in to change notification settings - Fork 8
70 lines (64 loc) · 2.67 KB
/
auto-assign.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
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Auto Assign
on:
pull_request:
types: [ opened, ready_for_review ]
permissions:
pull-requests: write
jobs:
count-reviewers:
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
timeout-minutes: 5
outputs:
count: ${{ steps.extract.outputs.count }}
steps:
- name: Extract the number of reviewers
id: extract
run: |
# https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=opened#pull_request
# https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=ready_for_review#pull_request
reviewers_count=$(jq '.pull_request.requested_reviewers | length' < "${{ github.event_path }}")
echo "count=${reviewers_count}" >> "$GITHUB_OUTPUT"
request-reviewers:
needs:
- count-reviewers
if: needs.count-reviewers.outputs.count == '0'
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
# https://github.com/marketplace/actions/create-github-app-token
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@e8e39f73bb84fdf315a015fa3104f314c0a258b4 # v1.8.1
with:
app-id: ${{ secrets.APP_ID_OF_YUMEMI_TEAM_REVIEW_REQUESTER }}
private-key: ${{ secrets.APP_PRIVATE_KEY_OF_YUMEMI_TEAM_REVIEW_REQUESTER }}
- name: Request reviewers
env:
REVIEWERS: ${{ vars.REVIEWERS }}
TEAM_REVIEWERS: ${{ vars.TEAM_REVIEWERS }}
run: |
reviewers=$(jq -R 'split(",")' <<< "${REVIEWERS:-}" | jq 'map(select(length > 0))')
team_reviewers=$(jq -R 'split(",")' <<< "${TEAM_REVIEWERS:-}" | jq 'map(select(length > 0))')
# https://docs.github.com/ja/rest/pulls/review-requests?apiVersion=2022-11-28#request-reviewers-for-a-pull-request
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ steps.app-token.outputs.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers" \
-d "{ \"reviewers\": ${reviewers}, \"team_reviewers\": ${team_reviewers} }"
request-assignees:
needs:
- count-reviewers
- request-reviewers
if: always()
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
# https://github.com/marketplace/actions/review-assign-action
- name: Request assignees
uses: hkusu/review-assign-action@5bee595fdb9765d4a0bd35724b6302fa15569158 # v1.4.0
with:
assignees: ${{ github.actor }}
ready-comment: 'Ready for review :rocket:'