Skip to content

Commit e55263b

Browse files
authored
chore(ci): CC review - fix /bot-review checkout on fork PRs (cube-js#11192)
The review workflow resolved the PR's head branch name and checked it out from the base repo — for fork PRs that branch only exists in the fork, so checkout failed (run 28585715254). GitHub mirrors every PR head into the base repo as refs/pull/<N>/head, readable with the workflow token, so check out that ref instead; it works uniformly for fork and same-repo PRs. Only the PR number is needed now, so the resolve step (and its `gh pr view` round-trip) is replaced by a job-level PR_NUMBER coalesce. Checkout also sets persist-credentials: false since the checked-out tree is now fork-controlled.
1 parent 5b96418 commit e55263b

1 file changed

Lines changed: 13 additions & 27 deletions

File tree

.github/workflows/claude-code-review.yml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414

1515
concurrency:
1616
# PR number lives in different fields depending on entry point — coalesce so
17-
# the same PR shares a group regardless of whether we got here via push or
18-
# via the /bot-review proxy.
17+
# the same PR shares a group regardless of whether we got here via
18+
# pull_request or via the /bot-review proxy.
1919
group: claude-code-review-${{ inputs.pr_number || github.event.pull_request.number }}-${{ github.event.action || 'manual' }}
2020
cancel-in-progress: true
2121

@@ -32,29 +32,11 @@ jobs:
3232
contents: read
3333
pull-requests: write
3434
id-token: write
35+
env:
36+
# Same coalesce as the concurrency group above (which can't read `env`,
37+
# so the expression appears twice).
38+
PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }}
3539
steps:
36-
- name: Resolve PR ref
37-
id: pr
38-
env:
39-
GH_TOKEN: ${{ github.token }}
40-
# Pull all event-controlled inputs through env vars instead of
41-
# interpolating directly into the script — branch names are
42-
# attacker-controlled and could carry shell metacharacters.
43-
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
44-
PR_NUMBER_FROM_EVENT: ${{ github.event.pull_request.number }}
45-
PR_HEAD_REF_FROM_EVENT: ${{ github.event.pull_request.head.ref }}
46-
REPO: ${{ github.repository }}
47-
run: |
48-
if [ -n "$INPUT_PR_NUMBER" ]; then
49-
number="$INPUT_PR_NUMBER"
50-
ref=$(gh pr view "$number" --repo "$REPO" --json headRefName --jq .headRefName)
51-
else
52-
number="$PR_NUMBER_FROM_EVENT"
53-
ref="$PR_HEAD_REF_FROM_EVENT"
54-
fi
55-
echo "number=$number" >> "$GITHUB_OUTPUT"
56-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
57-
5840
- name: React to trigger comment
5941
# Quick ACK so the user who typed /bot-review or /bot-deep-review sees
6042
# the bot picked up the command — actual review takes a few minutes.
@@ -72,8 +54,12 @@ jobs:
7254
- name: Checkout repository
7355
uses: actions/checkout@v6
7456
with:
75-
ref: ${{ steps.pr.outputs.ref }}
57+
# A fork PR's head branch doesn't exist in the base repo, so checking it
58+
# out by branch name fails. GitHub mirrors every PR head into the base
59+
# repo as refs/pull/<N>/head — readable with the workflow token
60+
ref: refs/pull/${{ env.PR_NUMBER }}/head
7661
fetch-depth: 1
62+
persist-credentials: false
7763

7864
- name: Configure gh aliases for review-thread operations
7965
run: bash .github/actions/setup-claude-code-review.sh
@@ -88,7 +74,7 @@ jobs:
8874
allowed_bots: "cursor[bot]"
8975
prompt: |
9076
REPO: ${{ github.repository }}
91-
PR NUMBER: ${{ steps.pr.outputs.number }}
77+
PR NUMBER: ${{ env.PR_NUMBER }}
9278
9379
Perform a comprehensive code review with the following focus areas:
9480
@@ -142,7 +128,7 @@ jobs:
142128
Before posting new comments, list existing review threads on this PR using the
143129
preconfigured alias:
144130
145-
gh list-review-threads ${{ github.repository_owner }} ${{ github.event.repository.name }} ${{ steps.pr.outputs.number }}
131+
gh list-review-threads ${{ github.repository_owner }} ${{ github.event.repository.name }} ${{ env.PR_NUMBER }}
146132
147133
For each thread where ALL of the following hold:
148134
- `isResolved` is false

0 commit comments

Comments
 (0)