Skip to content

Commit 0986541

Browse files
Tony363claude
andcommitted
fix: add fork detection to basic-review job
Fork PRs don't have access to ANTHROPIC_API_KEY and the PR author has read-only permissions, causing claude-code-action to fail. Add fork check as the first step, skipping the review gracefully for fork PRs with a notice in the step summary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3bb4f05 commit 0986541

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

.github/workflows/claude-review.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,24 @@ jobs:
5050
timeout-minutes: 15
5151

5252
steps:
53+
- name: Check if fork PR
54+
id: fork_check
55+
run: |
56+
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
57+
echo "is_fork=true" >> $GITHUB_OUTPUT
58+
echo "::notice::Fork PR detected — skipping AI review (no API key available)"
59+
else
60+
echo "is_fork=false" >> $GITHUB_OUTPUT
61+
fi
62+
5363
- name: Checkout code
64+
if: steps.fork_check.outputs.is_fork != 'true'
5465
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
5566
with:
5667
fetch-depth: 0
5768

5869
- name: Check PR size (cost control)
70+
if: steps.fork_check.outputs.is_fork != 'true'
5971
id: pr_size
6072
run: |
6173
BASE_REF="${{ github.base_ref || github.event.repository.default_branch || 'main' }}"
@@ -73,13 +85,18 @@ jobs:
7385
fi
7486
7587
- name: Skip large PR notice
76-
if: steps.pr_size.outputs.skip_review == 'true' && !contains(github.event.pull_request.labels.*.name, 'force-review')
88+
if: |
89+
steps.fork_check.outputs.is_fork != 'true' &&
90+
steps.pr_size.outputs.skip_review == 'true' &&
91+
!contains(github.event.pull_request.labels.*.name, 'force-review')
7792
run: |
7893
echo "::notice::Skipping review for large PR. Add 'force-review' label to override."
7994
exit 0
8095
8196
- name: Run Claude Code Review
82-
if: steps.pr_size.outputs.skip_review == 'false' || contains(github.event.pull_request.labels.*.name, 'force-review')
97+
if: |
98+
steps.fork_check.outputs.is_fork != 'true' &&
99+
(steps.pr_size.outputs.skip_review == 'false' || contains(github.event.pull_request.labels.*.name, 'force-review'))
83100
uses: anthropics/claude-code-action@88c168b39e7e64da0286d812b6e9fbebb6708185 # v1
84101
with:
85102
claude_args: |
@@ -95,9 +112,13 @@ jobs:
95112
if: always()
96113
run: |
97114
echo "### Review Metrics" >> $GITHUB_STEP_SUMMARY
98-
echo "- Files changed: ${{ steps.pr_size.outputs.files_changed }}" >> $GITHUB_STEP_SUMMARY
99-
echo "- Lines changed: ${{ steps.pr_size.outputs.lines_changed }}" >> $GITHUB_STEP_SUMMARY
100-
echo "- Estimated cost: ~\$1.50" >> $GITHUB_STEP_SUMMARY
115+
if [ "${{ steps.fork_check.outputs.is_fork }}" == "true" ]; then
116+
echo "- Skipped: fork PR (no API key)" >> $GITHUB_STEP_SUMMARY
117+
else
118+
echo "- Files changed: ${{ steps.pr_size.outputs.files_changed }}" >> $GITHUB_STEP_SUMMARY
119+
echo "- Lines changed: ${{ steps.pr_size.outputs.lines_changed }}" >> $GITHUB_STEP_SUMMARY
120+
echo "- Estimated cost: ~\$1.50" >> $GITHUB_STEP_SUMMARY
121+
fi
101122
102123
# ─── Phase 2: Sensitive file detection ────────────────────────────
103124
detect-high-stakes:

0 commit comments

Comments
 (0)