|
1 | | -name: Main Reviewer Checklist |
| 1 | +name: Reviewer Checklist |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | | - types: [assigned] |
| 5 | + types: [review_requested] |
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | checklist: |
9 | 9 | runs-on: ubuntu-latest |
10 | | - |
11 | 10 | steps: |
12 | | - # Step 1: Check out the repository |
13 | 11 | - name: Checkout repository |
14 | 12 | uses: actions/checkout@v3 |
15 | 13 |
|
16 | | - # Step 2: Extract the main reviewer (assignee) and PR details |
17 | | - - name: Extract PR details |
| 14 | + - name: Extract PR reviewer info |
18 | 15 | id: pr_details |
19 | 16 | run: | |
20 | | - echo "ASSIGNEE=$(jq -r '.assignee.login' < $GITHUB_EVENT_PATH)" >> $GITHUB_ENV |
| 17 | + REVIEWERS=$(jq -r '.pull_request.requested_reviewers[].login' < $GITHUB_EVENT_PATH) |
| 18 | + NEW_REVIEWER=$(jq -r '.requested_reviewer.login' < $GITHUB_EVENT_PATH) |
| 19 | + ACTOR=$(jq -r '.sender.login' < $GITHUB_EVENT_PATH) |
| 20 | + echo "REVIEWERS=$REVIEWERS" >> $GITHUB_ENV |
| 21 | + echo "NEW_REVIEWER=$NEW_REVIEWER" >> $GITHUB_ENV |
| 22 | + echo "ACTOR=$ACTOR" >> $GITHUB_ENV |
| 23 | +
|
| 24 | + - name: Determine checklist type |
| 25 | + id: checklist_type |
| 26 | + run: | |
| 27 | + # Only act if the user requested themselves |
| 28 | + if [ "$ACTOR" != "$NEW_REVIEWER" ]; then |
| 29 | + echo "SKIP=true" >> $GITHUB_ENV |
| 30 | + exit 0 |
| 31 | + fi |
| 32 | + COUNT=$(echo "$REVIEWERS" | grep -c .) |
| 33 | + if [ "$COUNT" -eq "1" ]; then |
| 34 | + echo "TEMPLATE=main_rev_checklist.md" >> $GITHUB_ENV |
| 35 | + echo "SKIP=false" >> $GITHUB_ENV |
| 36 | + else |
| 37 | + echo "TEMPLATE=rev_checklist.md" >> $GITHUB_ENV |
| 38 | + echo "SKIP=false" >> $GITHUB_ENV |
| 39 | + fi |
21 | 40 |
|
22 | | - # Step 3: Replace the placeholder in the checklist template |
23 | | - - name: Replace reviewer name in checklist template |
| 41 | + - name: Prepare checklist |
| 42 | + if: env.SKIP == 'false' |
24 | 43 | run: | |
25 | | - ASSIGNEE=${{ env.ASSIGNEE }} |
26 | | - sed "s/__MAINREV__/$ASSIGNEE/g" .github/workflows/main_rev_checklist.md > filled_checklist.md |
| 44 | + sed "s/__REV__/${{ env.NEW_REVIEWER }}/g" .github/workflows/${{ env.TEMPLATE }} > filled_checklist.md |
27 | 45 |
|
28 | | - # Step 4: Post the filled checklist as a comment |
29 | 46 | - name: Post checklist as a comment |
| 47 | + if: env.SKIP == 'false' |
30 | 48 | uses: peter-evans/create-or-update-comment@v3 |
31 | 49 | with: |
32 | 50 | token: ${{ secrets.GITHUB_TOKEN }} |
33 | | - issue-number: ${{ github.event.pull_request.number }} |
34 | 51 | body-path: filled_checklist.md |
| 52 | + issue-number: ${{ github.event.pull_request.number }} |
0 commit comments