1 name: PR Review
2
3 on:
4 pull_request_target:
5 types: [opened, reopened, synchronize, edited, ready_for_review]
6 issue_comment:
7 types: [created]
8 workflow_dispatch:
9 inputs:
10 pr_number:
11 description: "Review only this PR (e.g. 16248). Leave empty to review every open non-draft PR."
12 required: false
13 default: ''
14 type: string
15 skip_reviewed:
16 description: "Skip PRs that already have initial-approval or requires-more labels. Ignored when pr_number is set."
17 required: false
18 default: true
19 type: boolean
20
21 jobs:
22 # Runs only on workflow_dispatch: resolves which PRs to review. With
23 # `pr_number` set it emits that single PR; otherwise it collects all open
24 # non-draft PRs for the matrix below.
25 get-open-prs:
26 if: github.event_name == 'workflow_dispatch'
27 runs-on: ubuntu-latest
28 permissions:
29 pull-requests: read
30 outputs:
31 matrix: ${{ steps.get-prs.outputs.matrix }}
32 steps:
33 - name: Get open non-draft PRs
34 id: get-prs
35 env:
36 GH_TOKEN: ${{ github.token }}
37 PR_NUMBER: ${{ inputs.pr_number }}
38 SKIP_REVIEWED: ${{ inputs.skip_reviewed }}
39 run: |
40 set -euo pipefail
41
42 # Explicitly targeting one PR skips the label and draft filters: the
43 # point of naming a PR is to re-run the review on it regardless.
44 if [[ -n "$PR_NUMBER" ]]; then
45 if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
46 echo "::error::pr_number must be a positive integer, got '$PR_NUMBER'" >&2
47 exit 1
48 fi
49 echo "Reviewing PR #$PR_NUMBER only."
50 echo "matrix=[{\"number\":$PR_NUMBER}]" >> "$GITHUB_OUTPUT"
51 exit 0
52 fi
53
54 matrix=$(gh pr list --repo ${{ github.repository }} --state open --limit 200 --json number,isDraft,author,labels \
55 --jq "[.[] | select(
56 .isDraft == false and
57 .author.is_bot == false and
58 (if \"$SKIP_REVIEWED\" == \"true\" then ([.labels[].name] | contains([\"initial-approval\"]) | not) and ([.labels[].name] | contains([\"requires-more\"]) | not) else true end)
59 ) | {number: .number}]")
60
61 echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
62
63 # Runs on workflow_dispatch: reviews every open non-draft PR (team members included)
64 review-all:
65 needs: get-open-prs
66 if: needs.get-open-prs.outputs.matrix != '[]' && needs.get-open-prs.outputs.matrix != ''
67 strategy:
68 matrix:
69 pr: ${{ fromJson(needs.get-open-prs.outputs.matrix) }}
70 max-parallel: 5
71 fail-fast: false
72 uses: ./.github/workflows/review-pr-action.yml
73 with:
74 pr_number: "${{ matrix.pr.number }}"
75 trigger_reason: "manual workflow dispatch"
76 secrets:
77 MEDUSA_APP_ID: ${{ secrets.MEDUSA_APP_ID }}
78 MEDUSA_APP_PRIVATE_KEY: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }}
79 CLAUDE_CODE_API_TOKEN: ${{ secrets.CLAUDE_CODE_API_TOKEN }}
80 SLACK_WEBHOOK_URL_PR_REVIEW: ${{ secrets.SLACK_WEBHOOK_URL_PR_REVIEW }}
81
82 # Runs on pull_request_target and issue_comment (@medusajs-bot review) events: determines PR number
83 prepare:
84 if: |
85 (github.event_name == 'pull_request_target' &&
86 github.event.pull_request.draft == false &&
87 github.event.pull_request.user.login != 'github-actions[bot]') ||
88 (github.event_name == 'issue_comment' &&
89 github.event.issue.pull_request.url != '' &&
90 contains(github.event.comment.body, '@medusajs-bot review'))
91 runs-on: ubuntu-latest
92 outputs:
93 pr_number: ${{ steps.set.outputs.pr_number }}
94 should_review: ${{ steps.set.outputs.should_review }}
95 trigger_reason: ${{ steps.set.outputs.trigger_reason }}
96 steps:
97 - name: Checkout repository
98 uses: actions/checkout@v4
99 with:
100 fetch-depth: 1
101
102 - name: Set PR number and check team membership
103 id: set
104 env:
105 GH_TOKEN: ${{ github.token }}
106 run: |
107 if [ "${{ github.event_name }}" == "issue_comment" ]; then
108 echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
109 echo "should_review=true" >> $GITHUB_OUTPUT
110 echo "trigger_reason=manual review request via comment" >> $GITHUB_OUTPUT
111 else
112 echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
113
114 # Skip PR description edits made by bots (e.g. Cursor)
115 if [ "${{ github.event.action }}" == "edited" ] && [ "${{ github.event.sender.type }}" == "Bot" ]; then
116 echo "should_review=false" >> $GITHUB_OUTPUT
117 exit 0
118 fi
119
120 # Skip merge commits (e.g. merging base branch into the PR branch)
121 if [ "${{ github.event.action }}" == "synchronize" ]; then
122 PARENTS=$(gh api repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }} --jq '.parents | length')
123 if [ "$PARENTS" -gt 1 ]; then
124 echo "should_review=false" >> $GITHUB_OUTPUT
125 exit 0
126 fi
127 fi
128
129 # Determine trigger reason
130 case "${{ github.event.action }}" in
131 opened) echo "trigger_reason=new PR opened" >> $GITHUB_OUTPUT ;;
132 reopened) echo "trigger_reason=PR reopened" >> $GITHUB_OUTPUT ;;
133 synchronize) echo "trigger_reason=new commit pushed" >> $GITHUB_OUTPUT ;;
134 edited) echo "trigger_reason=PR description updated" >> $GITHUB_OUTPUT ;;
135 ready_for_review) echo "trigger_reason=PR marked as ready for review" >> $GITHUB_OUTPUT ;;
136 *) echo "trigger_reason=${{ github.event.action }}" >> $GITHUB_OUTPUT ;;
137 esac
138
139 AUTHOR="${{ github.event.pull_request.user.login }}"
140 if grep -qF "\"@${AUTHOR}\"" ./.github/teams.yml; then
141 echo "should_review=false" >> $GITHUB_OUTPUT
142 else
143 echo "should_review=true" >> $GITHUB_OUTPUT
144 fi
145 fi
146
147 # Runs on pull_request_target and issue_comment: calls the reusable review workflow
148 review:
149 needs: prepare
150 if: needs.prepare.result == 'success' && needs.prepare.outputs.should_review == 'true'
151 uses: ./.github/workflows/review-pr-action.yml
152 with:
153 pr_number: ${{ needs.prepare.outputs.pr_number }}
154 trigger_reason: ${{ needs.prepare.outputs.trigger_reason }}
155 secrets:
156 MEDUSA_APP_ID: ${{ secrets.MEDUSA_APP_ID }}
157 MEDUSA_APP_PRIVATE_KEY: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }}
158 CLAUDE_CODE_API_TOKEN: ${{ secrets.CLAUDE_CODE_API_TOKEN }}
159 SLACK_WEBHOOK_URL_PR_REVIEW: ${{ secrets.SLACK_WEBHOOK_URL_PR_REVIEW }}