-
Notifications
You must be signed in to change notification settings - Fork 7
72 lines (58 loc) · 2.52 KB
/
require-assignees-reviews.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
71
72
name: Require Assignees Reviews
on:
pull_request:
types:
- assigned
- unassigned
# Should cancel outdated workflows on clearing or assigning several people at once, and only let last instance of this workflow run
concurrency:
group: required-reviewers-${{ github.event.pull_request.head.ref }}
cancel-in-progress: true
env:
LIST: ${{ toJSON(github.event.pull_request.assignees.*.login) }}
jobs:
update-requested-reviewers:
runs-on: ubuntu-latest
name: Update requested reviewers
steps:
# get the repo / files to work on
- name: Checkout repository
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.OTTO_ACTIONS_SSH_KEY }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set git user information
run: |
git config --global user.email "otto@nsquared.io"
git config --global user.name "otto-bot-git"
- name: Cleanup old review files
run: |
echo Removing old file
rm ./.github/code-review/require-person/**/PR-${{ github.event.number }} -f
echo Removed old files successfully
# the below bash script uses jq to iterate on comma separated array [ 'string1', 'string2' ] (not same as a bash array)
# it has two main parts
# first: looping over assignees creating code ownership files for each
# second: takes effect only if the run removed all assignees and the list was empty, in this case it commits the deletion of files
- name: Create corresponding review files
run: |
jq -rc '.[]' <<< "$LIST" | while read i; do
echo "Creating file for $i to review PR-${{ github.event.number }}"
mkdir -p "./.github/code-review/require-person/$i/" && touch "./.github/code-review/require-person/$i/PR-${{ github.event.number }}"
echo "Successfully created file for $i to review PR-${{ github.event.number }}"
git add -A
echo "Successfully staged any changes"
git commit -m "Requiring review from '$i' ci bypass" || true
echo "Commit step done"
git push
echo "Successfully pushed to remote"
sleep 9
echo "Successfully woke up"
echo Success
done
git add -A
echo "Successfully staged"
git commit -m "Removed required reviewers ci bypass" || true
echo "Successfully made commit"
git push
echo "Successfully pushed to remote"