Skip to content

Commit a7a606e

Browse files
committed
feat: Enhance Claude Code Review workflow with inline comments
- Add write permission for pull-requests to enable inline comments - Add gh api endpoint for posting review comments - Fix Claude inline-comments implementation - Fix comment prompt formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> fix: claude.md
1 parent dc9eab3 commit a7a606e

File tree

2 files changed

+159
-13
lines changed

2 files changed

+159
-13
lines changed

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

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Claude Code Review
22

33
on:
44
pull_request:
5-
types: [opened, synchronize]
5+
types: [opened] # Only run when PR is first created, not on every commit
66
# Optional: Only run on specific file changes
77
# paths:
88
# - "src/**/*.ts"
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ubuntu-latest
3434
permissions:
3535
contents: read
36-
pull-requests: read
36+
pull-requests: write
3737
issues: read
3838
id-token: write
3939

@@ -50,20 +50,118 @@ jobs:
5050
with:
5151
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
5252
prompt: |
53-
REPO: ${{ github.repository }}
54-
PR NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
53+
# Code Review Task
5554
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
55+
**REPO:** ${{ github.repository }}
56+
**PR:** ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
57+
**COMMIT:** ${{ github.event.pull_request.head.sha }}
6258
63-
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
59+
## Context
6460
65-
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
61+
This is the **Neon MCP Server** - a Model Context Protocol server bridging LLMs to Neon Postgres API.
62+
Review this PR with understanding of:
63+
- MCP tool/handler architecture (see CLAUDE.md lines 83-122)
64+
- TypeScript ES2022 + Node16 ESM requirements
65+
- Tool registration pattern: definitions.ts → toolsSchema.ts → handlers/ → tools.ts
66+
- Multi-call state management for migrations/tuning tools
67+
68+
## What's Already Automated (Don't Review)
69+
70+
- ❌ Lint errors → `bun run lint` (automated by pr.yml)
71+
- ❌ Build failures → `bun run build` (automated by pr.yml)
72+
- ❌ Formatting issues → Automated
73+
74+
## Focus Your Review On (Significant Issues Only)
75+
76+
1. **Architecture & Design**
77+
- Does new tool follow the tool registration pattern?
78+
- Is handler properly typed in NEON_HANDLERS?
79+
- Are Zod schemas correctly defined in toolsSchema.ts?
80+
81+
2. **Security Vulnerabilities**
82+
- SQL injection risks (tool handlers using raw SQL)
83+
- Secrets exposure (API keys, tokens logged or returned)
84+
- Input validation gaps (Zod schema completeness)
85+
- Command injection in bash tool uses
86+
87+
3. **Logic Bugs**
88+
- Error handling gaps (unhandled promise rejections)
89+
- State management issues (branch ID tracking for multi-call tools)
90+
- Edge cases not covered (null/undefined handling)
91+
92+
4. **Performance Issues**
93+
- N+1 API call patterns
94+
- Inefficient Neon API usage
95+
- Missing pagination handling
96+
- Unnecessary data fetching
97+
98+
5. **Testing Gaps**
99+
- Missing Braintrust evaluations for new tools
100+
- Uncovered edge cases in existing tests
101+
- Integration test scenarios missing
102+
103+
6. **MCP-Specific Issues**
104+
- Tool descriptions not clear for LLMs
105+
- Missing analytics tracking (trackEvent calls)
106+
- Error handling doesn't use ToolError pattern
107+
- Missing Sentry error capture
108+
109+
## Review Instructions
110+
111+
### Step 1: Analyze the PR
112+
Use `gh pr view` and `gh pr diff` to understand the changes.
113+
114+
### Step 2: Identify Significant Issues
115+
- Read the full diff and changed files
116+
- For each significant issue, note: file path, line number, severity, description
117+
- Only flag issues a human reviewer would care about (not lint/format)
118+
119+
### Step 3: Post Inline Comments
120+
For each significant issue (max 5 per file), post an inline comment using:
121+
122+
```bash
123+
gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number || github.event.inputs.pr_number }}/comments -f body="COMMENT_BODY" -f path="relative/path/to/file.ts" -F line=42 -f side="RIGHT" -f commit_id="${{ github.event.pull_request.head.sha || github.sha }}"
124+
```
125+
126+
**IMPORTANT:**
127+
- Use a SINGLE LINE command (no backslashes or line continuations)
128+
- For this PR, use: `gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number || github.event.inputs.pr_number }}/comments`
129+
- Commit SHA: `${{ github.event.pull_request.head.sha || github.sha }}`
130+
- Post comments for EVERY significant issue you find (not just a summary)
131+
- Keep the body text concise and use \n for line breaks within the body parameter
132+
133+
**Inline Comment Format:**
134+
- Use emoji severity: 🔴 Critical | 🟡 Important | 🔵 Consider
135+
- Start with **[Category]** (Security/Logic/Performance/Architecture/Testing)
136+
- Explain the issue clearly
137+
- Provide actionable fix or suggestion
138+
- Reference CLAUDE.md patterns when applicable
139+
140+
**Example:**
141+
```
142+
🔴 **[Security]**: Potential SQL injection vulnerability. User input is concatenated directly into SQL query.\n\n**Fix:** Use parameterized queries:\n\`\`\`typescript\nconst result = await query('SELECT * FROM users WHERE name = $1', [userName]);\n\`\`\`
143+
```
144+
145+
Note: In the actual gh command, newlines are represented as \n within the body parameter.
146+
147+
### Step 4: Post Summary Comment
148+
After posting inline comments, create a summary with:
149+
- Review statistics (files, lines, issues)
150+
- Severity breakdown (🔴, 🟡, 🔵 counts)
151+
- Key findings (2-3 most critical issues)
152+
- What looks good (2-3 positive aspects)
153+
- Note that lint/build are automated
154+
155+
Use `gh pr comment` to post the summary.
156+
157+
## Guidelines
158+
159+
- **Be selective**: Only comment on significant issues worth a human's attention
160+
- **Be specific**: Reference exact lines, provide clear fixes
161+
- **Be constructive**: Explain the "why" behind suggestions
162+
- **Be project-aware**: Use CLAUDE.md patterns and terminology
163+
- **Don't duplicate**: Skip issues automated tools will catch
66164
67165
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
68166
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
69-
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:*)"'
167+
claude_args: '--allowed-tools "Bash(gh:*)"'

CLAUDE.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,54 @@ landing/ # Next.js landing page
227227

228228
- **Neon API Client**: Created using `@neondatabase/api-client` package. All tool handlers receive a pre-configured `neonClient` instance.
229229

230+
## Claude Code Review Workflow
231+
232+
This repository uses an enhanced Claude Code Review workflow that provides inline feedback on pull requests.
233+
234+
### What Gets Reviewed
235+
236+
- Architecture and design patterns (tool registration, handler typing)
237+
- Security vulnerabilities (SQL injection, secrets, input validation)
238+
- Logic bugs (error handling, state management, edge cases)
239+
- Performance issues (N+1 queries, inefficient API usage)
240+
- Testing gaps (missing evaluations, uncovered scenarios)
241+
- MCP-specific patterns (analytics tracking, error handling, Sentry capture)
242+
243+
### What's Automated (Not Reviewed by Claude)
244+
245+
- Linting: `bun run lint` (checked by pr.yml)
246+
- Building: `bun run build` (checked by pr.yml)
247+
- Formatting: Automated formatting checks
248+
249+
### Review Process
250+
251+
1. Workflow triggers automatically on PR open
252+
2. Claude analyzes changes with full project context
253+
3. Inline comments posted on significant issues
254+
4. Summary comment provides overview and statistics
255+
256+
### Inline Comment Format
257+
258+
- **Severity**: 🔴 Critical | 🟡 Important | 🔵 Consider
259+
- **Category**: [Security/Logic/Performance/Architecture/Testing/MCP]
260+
- **Description**: Clear explanation with context
261+
- **Fix**: Actionable code example or reference
262+
263+
Example:
264+
265+
```
266+
🔴 **[Security]**: SQL injection vulnerability - user input concatenated directly into SQL.
267+
268+
**Fix:** Use parameterized queries:
269+
const result = await query('SELECT * FROM users WHERE name = $1', [userName]);
270+
```
271+
272+
### Triggering Reviews
273+
274+
- **Automatic**: Opens when PR is created
275+
- **Manual**: Run workflow via GitHub Actions with PR number
276+
- **Security**: Only OWNER/MEMBER/COLLABORATOR PRs (blocks external)
277+
230278
## Testing Strategy
231279

232280
Tests use Braintrust for LLM-based evaluations. Each test:

0 commit comments

Comments
 (0)