|
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.repository == 'medusajs/medusa' && 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: github.repository == 'medusajs/medusa' && 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.repository == 'medusajs/medusa' && |
|
86
|
((github.event_name == 'pull_request_target' && |
|
87
|
github.event.pull_request.draft == false && |
|
88
|
github.event.pull_request.user.login != 'github-actions[bot]') || |
|
89
|
(github.event_name == 'issue_comment' && |
|
90
|
github.event.issue.pull_request.url != '' && |
|
91
|
contains(github.event.comment.body, '@medusajs-bot review'))) |
|
92
|
runs-on: ubuntu-latest |
|
93
|
outputs: |
|
94
|
pr_number: ${{ steps.set.outputs.pr_number }} |
|
95
|
should_review: ${{ steps.set.outputs.should_review }} |
|
96
|
trigger_reason: ${{ steps.set.outputs.trigger_reason }} |
|
97
|
steps: |
|
98
|
- name: Checkout repository |
|
99
|
uses: actions/checkout@v4 |
|
100
|
with: |
|
101
|
fetch-depth: 1 |
|
102
|
|
|
103
|
- name: Set PR number and check team membership |
|
104
|
id: set |
|
105
|
env: |
|
106
|
GH_TOKEN: ${{ github.token }} |
|
107
|
run: | |
|
108
|
if [ "${{ github.event_name }}" == "issue_comment" ]; then |
|
109
|
echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT |
|
110
|
echo "should_review=true" >> $GITHUB_OUTPUT |
|
111
|
echo "trigger_reason=manual review request via comment" >> $GITHUB_OUTPUT |
|
112
|
else |
|
113
|
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT |
|
114
|
|
|
115
|
# Skip PR description edits made by bots (e.g. Cursor) |
|
116
|
if [ "${{ github.event.action }}" == "edited" ] && [ "${{ github.event.sender.type }}" == "Bot" ]; then |
|
117
|
echo "should_review=false" >> $GITHUB_OUTPUT |
|
118
|
exit 0 |
|
119
|
fi |
|
120
|
|
|
121
|
# Skip merge commits (e.g. merging base branch into the PR branch) |
|
122
|
if [ "${{ github.event.action }}" == "synchronize" ]; then |
|
123
|
PARENTS=$(gh api repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }} --jq '.parents | length') |
|
124
|
if [ "$PARENTS" -gt 1 ]; then |
|
125
|
echo "should_review=false" >> $GITHUB_OUTPUT |
|
126
|
exit 0 |
|
127
|
fi |
|
128
|
fi |
|
129
|
|
|
130
|
# Determine trigger reason |
|
131
|
case "${{ github.event.action }}" in |
|
132
|
opened) echo "trigger_reason=new PR opened" >> $GITHUB_OUTPUT ;; |
|
133
|
reopened) echo "trigger_reason=PR reopened" >> $GITHUB_OUTPUT ;; |
|
134
|
synchronize) echo "trigger_reason=new commit pushed" >> $GITHUB_OUTPUT ;; |
|
135
|
edited) echo "trigger_reason=PR description updated" >> $GITHUB_OUTPUT ;; |
|
136
|
ready_for_review) echo "trigger_reason=PR marked as ready for review" >> $GITHUB_OUTPUT ;; |
|
137
|
*) echo "trigger_reason=${{ github.event.action }}" >> $GITHUB_OUTPUT ;; |
|
138
|
esac |
|
139
|
|
|
140
|
AUTHOR="${{ github.event.pull_request.user.login }}" |
|
141
|
if grep -qF "\"@${AUTHOR}\"" ./.github/teams.yml; then |
|
142
|
echo "should_review=false" >> $GITHUB_OUTPUT |
|
143
|
else |
|
144
|
echo "should_review=true" >> $GITHUB_OUTPUT |
|
145
|
fi |
|
146
|
fi |
|
147
|
|
|
148
|
# Runs on pull_request_target and issue_comment: calls the reusable review workflow |
|
149
|
review: |
|
150
|
needs: prepare |
|
151
|
if: github.repository == 'medusajs/medusa' && needs.prepare.result == 'success' && needs.prepare.outputs.should_review == 'true' |
|
152
|
uses: ./.github/workflows/review-pr-action.yml |
|
153
|
with: |
|
154
|
pr_number: ${{ needs.prepare.outputs.pr_number }} |
|
155
|
trigger_reason: ${{ needs.prepare.outputs.trigger_reason }} |
|
156
|
secrets: |
|
157
|
MEDUSA_APP_ID: ${{ secrets.MEDUSA_APP_ID }} |
|
158
|
MEDUSA_APP_PRIVATE_KEY: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }} |
|
159
|
CLAUDE_CODE_API_TOKEN: ${{ secrets.CLAUDE_CODE_API_TOKEN }} |
|
160
|
SLACK_WEBHOOK_URL_PR_REVIEW: ${{ secrets.SLACK_WEBHOOK_URL_PR_REVIEW }} |