Skip to content

Commit 3091a7a

Browse files
committed
fix(ci): checkout pr code instead of base branch in claude review
pull_request_target defaults to checking out the base branch HEAD, not the PR's actual code. Claude was reviewing main branch content and flagging "missing" changes that the PR itself introduced. Using ref: head.sha ensures we checkout the PR commit. fetch-depth: 0 provides full history for diff/blame operations. Fork handling step configures origin correctly for external contributor PRs. Pattern adopted from vcluster-docs/.github/workflows/claude-review.yml Closes DEVOPS-501
1 parent fd932f5 commit 3091a7a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ on:
1212

1313
jobs:
1414
claude-review:
15-
# Optional: Filter by PR author
16-
# if: |
17-
# github.event.pull_request.user.login == 'external-contributor' ||
18-
# github.event.pull_request.user.login == 'new-developer' ||
19-
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20-
15+
# Only run for PRs in the main org (not forks) to prevent untrusted code
16+
# from accessing secrets in pull_request_target context
17+
if: github.repository_owner == 'loft-sh'
2118
runs-on: ubuntu-latest
2219
permissions:
2320
contents: read
@@ -28,7 +25,19 @@ jobs:
2825
- name: Checkout repository
2926
uses: actions/checkout@v4
3027
with:
31-
fetch-depth: 1
28+
ref: ${{ github.event.pull_request.head.sha }}
29+
fetch-depth: 0
30+
31+
- name: Setup fork as origin for Claude
32+
if: ${{ github.event.pull_request.head.repo.fork == true }}
33+
env:
34+
PR_HEAD_CLONE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
35+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
36+
run: |
37+
git remote rename origin upstream
38+
git remote add origin "$PR_HEAD_CLONE_URL"
39+
git fetch origin "$PR_HEAD_REF"
40+
git checkout -B "$PR_HEAD_REF" "origin/$PR_HEAD_REF"
3241
3342
- name: Run Claude Code Review
3443
id: claude-review

0 commit comments

Comments
 (0)