Skip to content

Commit 7238c7c

Browse files
authored
feat(ci): make Claude code review on-demand via /claude-review command (#175)
- Change trigger from automatic to manual comment trigger - Only repository owner can invoke - Stricter command matching (exact or space-prefixed) - Fork protection to prevent reviewing malicious fork PRs - Separate jobs for reactions with minimal permissions - Concurrency control to prevent parallel reviews
1 parent b5a64a3 commit 7238c7c

1 file changed

Lines changed: 54 additions & 12 deletions

File tree

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

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,52 @@
11
name: Claude Code Review
22

33
on:
4-
pull_request:
5-
types: [opened, synchronize]
6-
# Optional: Only run on specific file changes
7-
# paths:
8-
# - "src/**/*.ts"
9-
# - "src/**/*.tsx"
10-
# - "src/**/*.js"
11-
# - "src/**/*.jsx"
4+
issue_comment:
5+
types: [created]
6+
7+
concurrency:
8+
group: claude-review-${{ github.event.issue.number }}
9+
cancel-in-progress: true
1210

1311
jobs:
14-
claude-review:
15-
# Skip fork PRs to prevent prompt injection via malicious PR content
16-
if: github.event.pull_request.head.repo.full_name == github.repository
12+
# Notify unauthorized users who try to use the command
13+
notify-unauthorized:
14+
if: |
15+
github.event.issue.pull_request &&
16+
(github.event.comment.body == '/claude-review' ||
17+
startsWith(github.event.comment.body, '/claude-review ')) &&
18+
github.event.comment.author_association != 'OWNER'
19+
runs-on: ubuntu-latest
20+
permissions:
21+
issues: write
22+
steps:
23+
- name: React to indicate unauthorized
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
run: |
27+
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
28+
-f content='-1'
1729
30+
# Acknowledge the command with a reaction
31+
acknowledge:
32+
if: |
33+
github.event.issue.pull_request &&
34+
(github.event.comment.body == '/claude-review' ||
35+
startsWith(github.event.comment.body, '/claude-review ')) &&
36+
github.event.comment.author_association == 'OWNER'
37+
runs-on: ubuntu-latest
38+
permissions:
39+
issues: write
40+
steps:
41+
- name: React to acknowledge command
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
run: |
45+
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
46+
-f content='+1'
47+
48+
claude-review:
49+
needs: acknowledge
1850
runs-on: ubuntu-latest
1951
permissions:
2052
contents: read
@@ -23,6 +55,16 @@ jobs:
2355
id-token: write
2456

2557
steps:
58+
- name: Check if PR is from fork
59+
env:
60+
GH_TOKEN: ${{ github.token }}
61+
run: |
62+
IS_FORK=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json isCrossRepository -q '.isCrossRepository')
63+
if [ "$IS_FORK" = "true" ]; then
64+
echo "::error::Cannot review PRs from forks due to security concerns"
65+
exit 1
66+
fi
67+
2668
- name: Checkout repository
2769
uses: actions/checkout@v6
2870
with:
@@ -35,7 +77,7 @@ jobs:
3577
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
3678
prompt: |
3779
REPO: ${{ github.repository }}
38-
PR NUMBER: ${{ github.event.pull_request.number }}
80+
PR NUMBER: ${{ github.event.issue.number }}
3981
4082
Please review this pull request and provide feedback on:
4183
- Code quality and best practices

0 commit comments

Comments
 (0)