|
| 1 | +name: Claude Code |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + pull_request_review_comment: |
| 7 | + types: [created] |
| 8 | + issues: |
| 9 | + types: [opened, assigned] |
| 10 | + pull_request_review: |
| 11 | + types: [submitted] |
| 12 | + pull_request: |
| 13 | + types: [opened, synchronize] |
| 14 | + |
| 15 | +jobs: |
| 16 | + # Respond to @claude mentions |
| 17 | + claude-mentions: |
| 18 | + if: | |
| 19 | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || |
| 20 | + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || |
| 21 | + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || |
| 22 | + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + pull-requests: write |
| 27 | + issues: write |
| 28 | + id-token: write |
| 29 | + actions: read |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v5 |
| 33 | + with: |
| 34 | + fetch-depth: 1 |
| 35 | + |
| 36 | + - name: Run Claude Code |
| 37 | + id: claude |
| 38 | + uses: anthropics/claude-code-action@v1 |
| 39 | + with: |
| 40 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 41 | + # Restrict tools to safe GitHub CLI operations |
| 42 | + claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh issue comment:*),Bash(gh search:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh pr diff:*),Bash(gh pr comment:*),Bash(gh pr review:*),Bash(gh pr checks:*)"' |
| 43 | + |
| 44 | + # Automatic code review on PR open/update |
| 45 | + claude-pr-review: |
| 46 | + if: | |
| 47 | + github.event_name == 'pull_request' && |
| 48 | + (github.event.action == 'opened' || github.event.action == 'synchronize') && |
| 49 | + github.actor != 'dependabot[bot]' |
| 50 | + runs-on: ubuntu-latest |
| 51 | + permissions: |
| 52 | + contents: read |
| 53 | + pull-requests: write |
| 54 | + issues: write |
| 55 | + id-token: write |
| 56 | + actions: read |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@v5 |
| 60 | + with: |
| 61 | + fetch-depth: 0 |
| 62 | + |
| 63 | + - name: Run Claude Code Review |
| 64 | + id: claude-review |
| 65 | + uses: anthropics/claude-code-action@v1 |
| 66 | + with: |
| 67 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 68 | + # Restrict tools to safe GitHub CLI operations for PR review |
| 69 | + claude_args: '--allowed-tools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr review:*),Bash(gh pr checks:*),Bash(gh pr comment:*)"' |
| 70 | + prompt: | |
| 71 | + REPO: ${{ github.repository }} |
| 72 | + PR NUMBER: ${{ github.event.pull_request.number }} |
| 73 | +
|
| 74 | + You are a senior code reviewer. Review this PR thoroughly. |
| 75 | +
|
| 76 | + Use the repository's CLAUDE.md for guidance on project conventions, code style, and architecture. |
| 77 | +
|
| 78 | + ## Review Criteria (in order of severity) |
| 79 | + 1. **Security vulnerabilities** - injection, auth bypass, secrets exposure, OWASP top 10 |
| 80 | + 2. **Bugs and logic errors** - null refs, race conditions, off-by-one, error handling |
| 81 | + 3. **Breaking changes** - API compatibility, data migrations, config changes |
| 82 | + 4. **Performance issues** - N+1 queries, memory leaks, blocking calls |
| 83 | + 5. **Code quality** - unclear logic, missing validation, poor error messages |
| 84 | +
|
| 85 | + ## Review Instructions |
| 86 | + Use `gh pr review` to submit a GitHub PR review: |
| 87 | + - If you find ANY issues in categories 1-3 (security, bugs, breaking changes): |
| 88 | + `gh pr review ${{ github.event.pull_request.number }} --request-changes --body "your review"` |
| 89 | + - If you find only minor issues (categories 4-5): |
| 90 | + `gh pr review ${{ github.event.pull_request.number }} --comment --body "your review"` |
| 91 | + - If the code looks good: |
| 92 | + `gh pr review ${{ github.event.pull_request.number }} --approve --body "your review"` |
| 93 | +
|
| 94 | + ## Response Format |
| 95 | + Start your review with a summary line: |
| 96 | + - "🚨 **Changes Requested** - Found [N] issue(s) that must be addressed" |
| 97 | + - "💬 **Comment** - Found [N] suggestion(s) for improvement" |
| 98 | + - "✅ **Approved** - Code looks good" |
| 99 | +
|
| 100 | + Then list specific issues with file paths and line numbers. |
| 101 | + Be constructive and actionable. Focus on significant issues, not style nitpicks. |
0 commit comments