Testing reviewer checklist actions #27
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: [review_requested] | |
| jobs: | |
| checklist: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Extract PR reviewer info (sanitize usernames for GitHub mentions) | |
| id: pr_details | |
| run: | | |
| # Only allow valid GitHub username characters: [A-Za-z0-9-] | |
| sanitize() { | |
| echo "$1" | sed 's/[^A-Za-z0-9-]//g' | |
| } | |
| REVIEWERS=$(jq -r '.pull_request.requested_reviewers[].login' < $GITHUB_EVENT_PATH) | |
| SANITIZED_REVIEWERS="" | |
| for r in $REVIEWERS; do | |
| SANITIZED_REVIEWERS="$SANITIZED_REVIEWERS $(sanitize "$r")" | |
| done | |
| NEW_REVIEWER=$(jq -r '.requested_reviewer.login' < $GITHUB_EVENT_PATH) | |
| SANITIZED_NEW_REVIEWER=$(sanitize "$NEW_REVIEWER") | |
| echo "REVIEWERS=$(echo "$SANITIZED_REVIEWERS" | xargs)" >> $GITHUB_ENV | |
| echo "NEW_REVIEWER=$SANITIZED_NEW_REVIEWER" >> $GITHUB_ENV | |
| - name: Determine checklist type | |
| id: checklist_type | |
| run: | | |
| COUNT=$(echo "$REVIEWERS" | grep -c .) | |
| if [ "$COUNT" -eq "1" ]; then | |
| echo "TEMPLATE=main_rev_checklist.md" >> $GITHUB_ENV | |
| else | |
| echo "TEMPLATE=rev_checklist.md" >> $GITHUB_ENV | |
| fi | |
| echo "SKIP=false" >> $GITHUB_ENV | |
| - name: Prepare checklist | |
| if: env.SKIP == 'false' | |
| run: | | |
| sed "s/__REV__/${{ env.NEW_REVIEWER }}/g" .github/workflows/${{ env.TEMPLATE }} > filled_checklist.md | |
| - name: Post checklist as a comment | |
| if: env.SKIP == 'false' | |
| uses: peter-evans/create-or-update-comment@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body-path: filled_checklist.md | |
| issue-number: ${{ github.event.pull_request.number }} |