|
| 1 | +name: PR Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + issue_comment: |
| 7 | + types: [created] |
| 8 | + |
| 9 | +jobs: |
| 10 | + check: |
| 11 | + # NOTE: comment body matching is exact — /review or /pr-reviewer with no trailing spaces, newlines, or mixed case |
| 12 | + # This does not fail the workflow; non-matching comments simply do not trigger the job |
| 13 | + if: | |
| 14 | + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) || |
| 15 | + (github.event_name == 'issue_comment' && github.event.issue.pull_request != null && |
| 16 | + (github.event.comment.body == '/review' || github.event.comment.body == '/pr-reviewer')) |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + allowed: ${{ steps.gate.outputs.allowed }} |
| 20 | + pr_number: ${{ steps.gate.outputs.pr_number }} |
| 21 | + head_sha: ${{ steps.gate.outputs.head_sha }} |
| 22 | + steps: |
| 23 | + - name: Gate check |
| 24 | + id: gate |
| 25 | + run: | |
| 26 | + set -euo pipefail |
| 27 | + if [ "$EVENT_NAME" = "pull_request" ]; then |
| 28 | + echo "allowed=true" >> $GITHUB_OUTPUT |
| 29 | + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 30 | + echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + # Fall back to "none" if user is not a collaborator (gh api returns 404) so allowed=false is output cleanly |
| 33 | + PERM=$(gh api repos/$GITHUB_REPOSITORY/collaborators/$COMMENT_USER_LOGIN/permission --jq '.permission' 2>/dev/null || echo "none") |
| 34 | + # Intentionally require admin or maintain; write collaborators are excluded to |
| 35 | + # limit who can trigger potentially expensive/sensitive review automation. |
| 36 | + if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ]; then |
| 37 | + DATA=$(gh api repos/$GITHUB_REPOSITORY/pulls/$ISSUE_NUMBER) |
| 38 | + echo "allowed=true" >> $GITHUB_OUTPUT |
| 39 | + echo "pr_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT |
| 40 | + echo "head_sha=$(echo "$DATA" | jq -r '.head.sha')" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "allowed=false" >> $GITHUB_OUTPUT |
| 43 | + fi |
| 44 | + fi |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + EVENT_NAME: ${{ github.event_name }} |
| 48 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 49 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 50 | + COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }} |
| 51 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 52 | + # GITHUB_REPOSITORY is set automatically by GitHub Actions (owner/repo) |
| 53 | + |
| 54 | + review: |
| 55 | + needs: check |
| 56 | + if: needs.check.outputs.allowed == 'true' |
| 57 | + uses: adobe/aio-reusable-workflows/.github/workflows/pr-review.yml@main |
| 58 | + with: |
| 59 | + pr_number: ${{ needs.check.outputs.pr_number }} |
| 60 | + head_sha: ${{ needs.check.outputs.head_sha }} |
| 61 | + secrets: |
| 62 | + AWS_BEARER_TOKEN_BEDROCK: ${{ secrets.APP_BUILDER_AWS_BEARER_TOKEN_BEDROCK }} |
0 commit comments