Skip to content

Commit 00aa376

Browse files
authored
fix: claude-code-review action for forked branches (#2171)
1 parent c3334b9 commit 00aa376

File tree

1 file changed

+68
-20
lines changed

1 file changed

+68
-20
lines changed

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

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ on:
77
- opened
88
- synchronize
99
- ready_for_review
10-
# Optional: Only run on specific file changes
11-
# paths:
12-
# - "src/**/*.ts"
13-
# - "src/**/*.tsx"
14-
# - "src/**/*.js"
15-
# - "src/**/*.jsx"
1610
# For PRs from forked repositories (secure path with secrets)
1711
pull_request_target:
1812
types:
@@ -21,14 +15,12 @@ on:
2115
- ready_for_review
2216

2317
jobs:
24-
claude-review:
25-
# Skip draft PRs and prevent duplicate runs
18+
# Job for same-repo PRs (can use OIDC if needed)
19+
claude-review-same-repo:
2620
if: |
27-
github.event.pull_request.draft == false &&
28-
(
29-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
30-
(github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository)
31-
)
21+
github.event_name == 'pull_request' &&
22+
github.event.pull_request.head.repo.full_name == github.repository &&
23+
github.event.pull_request.draft == false
3224
3325
runs-on: ubuntu-latest
3426
permissions:
@@ -47,12 +39,65 @@ jobs:
4739
env:
4840
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4941
run: |
50-
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
51-
echo "⚠️ Forked PR detected - running in secure mode"
52-
echo "PR from: ${{ github.event.pull_request.head.repo.full_name }}"
53-
echo "Base repo: ${{ github.repository }}"
54-
fi
42+
echo "Checking out PR #${{ github.event.pull_request.number }}"
43+
gh pr checkout ${{ github.event.pull_request.number }}
44+
echo "✅ PR branch checked out successfully"
45+
46+
- name: Run Claude Code Review
47+
id: claude-review
48+
uses: anthropics/claude-code-action@v1
49+
with:
50+
github_token: ${{ secrets.GITHUB_TOKEN }}
51+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
52+
prompt: |
53+
REPO: ${{ github.repository }}
54+
PR NUMBER: ${{ github.event.pull_request.number }}
55+
56+
Please review this pull request and provide feedback on:
57+
- Code quality and best practices
58+
- Potential bugs or issues
59+
- Performance considerations
60+
- Security concerns
61+
- Test coverage
62+
63+
# Steps to run a Review:
64+
1) Check if previous review is already done by Claude. If so, perform a re-reivew with the latest changes referring previous review.
65+
2) If no previous review is found, perform a new review with the latest changes.
66+
67+
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
68+
69+
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
5570
71+
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
72+
73+
# Job for forked PRs (no OIDC, token-based only)
74+
claude-review-forked:
75+
if: |
76+
github.event_name == 'pull_request_target' &&
77+
github.event.pull_request.head.repo.full_name != github.repository &&
78+
github.event.pull_request.draft == false
79+
80+
runs-on: ubuntu-latest
81+
permissions:
82+
contents: read
83+
pull-requests: write
84+
issues: read
85+
# Explicitly disable id-token to avoid OIDC flow
86+
87+
steps:
88+
- name: Checkout repository (no credentials persisted)
89+
uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 1
92+
persist-credentials: false
93+
94+
- name: Checkout PR branch (forked PR)
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
run: |
98+
echo "⚠️ Forked PR detected - running in secure mode"
99+
echo "PR from: ${{ github.event.pull_request.head.repo.full_name }}"
100+
echo "Base repo: ${{ github.repository }}"
56101
echo "Checking out PR #${{ github.event.pull_request.number }}"
57102
gh pr checkout ${{ github.event.pull_request.number }}
58103
echo "✅ PR branch checked out successfully"
@@ -61,6 +106,7 @@ jobs:
61106
id: claude-review
62107
uses: anthropics/claude-code-action@v1
63108
with:
109+
github_token: ${{ secrets.GITHUB_TOKEN }}
64110
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
65111
prompt: |
66112
REPO: ${{ github.repository }}
@@ -73,10 +119,12 @@ jobs:
73119
- Security concerns
74120
- Test coverage
75121
122+
# Steps to run a Review:
123+
1) Check if previous review is already done by Claude. If so, perform a re-reivew with the latest changes referring previous review.
124+
2) If no previous review is found, perform a new review with the latest changes.
125+
76126
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
77127
78128
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
79129
80-
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
81-
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
82130
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'

0 commit comments

Comments
 (0)