Skip to content

Commit b9ff3b6

Browse files
matthallett1claude
andcommitted
[.github] Fix claude-review for fork PRs — fetch via refs/pull/N/head
claude-code-action@v1 does `git fetch origin <branch-name>` internally, which fails for fork PRs because the branch doesn't exist on origin. Fix: pre-fetch the PR code via GitHub's refs/pull/N/head ref (works for all PRs regardless of fork status) and check it out on a local branch with the expected name before the action runs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2d3a834 commit b9ff3b6

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

.github/workflows/claude-review.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,29 @@ jobs:
2626
contains('justfinethanku,matthallett1,adrienneaguirre,kaleab27', github.event.comment.user.login))
2727
runs-on: ubuntu-latest
2828
steps:
29-
- name: Checkout PR code
29+
- name: Checkout repository
3030
uses: actions/checkout@v4
3131
with:
32-
ref: ${{ github.event.pull_request.head.sha || github.sha }}
3332
fetch-depth: 0
3433

34+
- name: Checkout PR branch
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
# Determine PR number based on event type
39+
if [ "${{ github.event_name }}" = "issue_comment" ]; then
40+
PR_NUMBER="${{ github.event.issue.number }}"
41+
else
42+
PR_NUMBER="${{ github.event.pull_request.number }}"
43+
fi
44+
45+
# Fetch PR head via refs/pull/N/head (works for both fork and same-repo PRs)
46+
git fetch origin "pull/${PR_NUMBER}/head:refs/remotes/origin/pr-head"
47+
48+
# Get the branch name the action expects and check it out locally
49+
BRANCH=$(gh pr view "${PR_NUMBER}" --json headRefName -q .headRefName)
50+
git checkout -B "${BRANCH}" refs/remotes/origin/pr-head
51+
3552
- uses: anthropics/claude-code-action@v1
3653
with:
3754
github_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)