Demo PR #19
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Reviewer Checklist | |
| on: | |
| pull_request: | |
| types: [unassigned, assigned, review_requested, review_request_removed] | |
| jobs: | |
| checklist: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Check out the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| # Step 2: Extract the assignee, reviewers, and PR details | |
| - name: Extract PR details | |
| id: pr_details | |
| run: | | |
| ASSIGNEE=$(jq -r '.assignee.login // ""' < $GITHUB_EVENT_PATH) | |
| REVIEWERS=$(jq -r '.pull_request.requested_reviewers[].login // ""' < $GITHUB_EVENT_PATH) | |
| echo "ASSIGNEE=$ASSIGNEE" >> $GITHUB_ENV | |
| echo "REVIEWERS=$REVIEWERS" >> $GITHUB_ENV | |
| # Step 3: Determine the checklist template or skip posting | |
| - name: Determine checklist template or skip | |
| id: checklist_template | |
| run: | | |
| ASSIGNEE="${{ env.ASSIGNEE }}" | |
| REVIEWERS="${{ env.REVIEWERS }}" | |
| # If assignee is also a reviewer, use main_rev_checklist.md | |
| if [[ "$REVIEWERS" == *"$ASSIGNEE"* && -n "$ASSIGNEE" ]]; then | |
| echo "TEMPLATE=main_rev_checklist.md" >> $GITHUB_ENV | |
| echo "POST_CHECKLIST=true" >> $GITHUB_ENV | |
| # If assignee is set but NOT a reviewer, skip posting | |
| elif [[ -n "$ASSIGNEE" && "$REVIEWERS" != *"$ASSIGNEE"* ]]; then | |
| echo "POST_CHECKLIST=false" >> $GITHUB_ENV | |
| # If there are reviewers (and assignee is empty or not a reviewer), use rev_checklist.md | |
| elif [[ -n "$REVIEWERS" ]]; then | |
| echo "TEMPLATE=rev_checklist.md" >> $GITHUB_ENV | |
| echo "POST_CHECKLIST=true" >> $GITHUB_ENV | |
| else | |
| echo "POST_CHECKLIST=false" >> $GITHUB_ENV | |
| fi | |
| # Step 4: Replace the placeholder in the selected checklist template | |
| - name: Replace reviewer name in checklist template | |
| if: env.POST_CHECKLIST == 'true' | |
| run: | | |
| TEMPLATE=${{ env.TEMPLATE }} | |
| ASSIGNEE=${{ env.ASSIGNEE }} | |
| sed "s/__REV__/$ASSIGNEE/g" .github/workflows/$TEMPLATE > filled_checklist.md | |
| # Step 5: Post the filled checklist as a comment | |
| - name: Post checklist as a comment | |
| if: env.POST_CHECKLIST == 'true' | |
| uses: peter-evans/create-or-update-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body-path: filled_checklist.md |