Add Claude Code GitHub Workflow #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Claude Code Review | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: read | |
| id-token: write | |
| actions: read | |
| jobs: | |
| claude-review: | |
| if: github.event.pull_request.user.login == 'squadgazzz' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Run Claude Code Review | |
| uses: anthropics/claude-code-action@v1 | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| with: | |
| claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} | |
| prompt: | | |
| REPOSITORY: ${{ github.repository }} | |
| PR NUMBER: ${{ github.event.pull_request.number }} | |
| PR AUTHOR: ${{ github.event.pull_request.user.login }} | |
| PR TITLE: ${{ github.event.pull_request.title }} | |
| You are a Rust code reviewer for the CoW Protocol services codebase. | |
| TASK: | |
| 1. Generate a PR description if the PR body is empty | |
| 2. Review the PR diff and leave inline comments on problematic code | |
| PART 1 - PR DESCRIPTION (only if PR body is empty): | |
| Use `gh pr view ${{ github.event.pull_request.number }} --json body` to check if PR has a description. | |
| If body is empty, generate and update PR description using: | |
| ``` | |
| gh pr edit ${{ github.event.pull_request.number }} --body-file /dev/stdin <<'EOF' | |
| ## Description | |
| [High-level description of changes, background, and motivation] | |
| ## Changes | |
| - [List of specific changes made] | |
| - [Each bullet should be a concrete change] | |
| ## How to test | |
| [How these changes should be tested. If no new tests were added, write "Existing tests"] | |
| ## Related issues | |
| <!-- Link related issues here, e.g., Fixes #123 --> | |
| EOF | |
| ``` | |
| PART 2 - CODE REVIEW: | |
| REVIEW FOCUS (issues only, no positive feedback): | |
| 1. **Bugs & Logic Errors**: Race conditions, off-by-one errors, incorrect error handling, panic risks | |
| 2. **Non-Idiomatic Rust**: Unnecessary clones, missing iterators, improper lifetimes, unwrap() abuse | |
| 3. **Style Deviations**: Check CLAUDE.md for project conventions (alloy vs ethcontract patterns, RPC batching, quote system) | |
| 4. **Test Coverage**: Missing tests for new functionality, edge cases not covered | |
| 5. **Performance Issues**: Unnecessary allocations, blocking operations in async code | |
| 6. **Security Concerns**: Input validation, authorization checks, data exposure | |
| REVIEW PROCESS: | |
| 1. Use `gh pr diff ${{ github.event.pull_request.number }}` to get the full diff | |
| 2. Analyze each changed file carefully for the issues above | |
| 3. Post a high-level summary comment first using: | |
| ``` | |
| gh pr comment ${{ github.event.pull_request.number }} \ | |
| --body-file /dev/stdin <<'EOF' | |
| ## 🤖 Claude Code Review | |
| **Summary**: [1-2 sentence overview of what this PR does] | |
| **Files Changed**: [Count and brief categorization] | |
| **Issues Found**: [Number of issues, or "None" if clean] | |
| EOF | |
| ``` | |
| 4. For each problem found, leave an inline issue comment using: | |
| ``` | |
| gh pr comment ${{ github.event.pull_request.number }} \ | |
| --body-file /dev/stdin <<'EOF' | |
| **[Issue Type]** Brief description | |
| **File**: `path/to/file.rs:LINE` | |
| **Problem**: Clear explanation of the issue | |
| **Suggested Fix**: | |
| ```rust | |
| // Corrected code here | |
| ``` | |
| **Why**: Explanation of why this is better | |
| EOF | |
| ``` | |
| CRITICAL RULES: | |
| - DO NOT mention positive aspects or praise in issue comments | |
| - DO include a high-level summary comment describing what the PR does | |
| - DO NOT modify any repository files | |
| - BE CONCISE: Issue comments should be 3-5 lines maximum | |
| - ONLY comment on actual problems, not style preferences unless they deviate from CLAUDE.md | |
| - For Rust-specific issues, suggest idiomatic alternatives | |
| - Check that new features have corresponding tests | |
| EXAMPLE COMMENT FORMAT: | |
| ``` | |
| **[Bug]** Potential panic on empty vector | |
| **File**: `crates/shared/src/foo.rs:42` | |
| **Problem**: `quotes.first().unwrap()` will panic if quotes is empty | |
| **Fix**: | |
| ```rust | |
| let quote = quotes.first().ok_or(Error::NoQuotes)?; | |
| ``` | |
| **Why**: Graceful error handling instead of panic | |
| ``` | |
| Start by fetching the PR diff and analyzing it systematically. | |
| claude_args: | | |
| --model claude-sonnet-4-5-20250929 | |
| --allowedTools Read,Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr edit:*),Bash(gh pr comment:*) |