Skip to content

Commit 723c7a1

Browse files
feat(git): add automated code review command
Add /git:review-changes command that provides AI-powered code review analysis for git changes. Features include security vulnerability detection, performance analysis, and PR-ready formatting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bdd655f commit 723c7a1

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

PLUGINS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Git workflow automation and utilities
7070
- **`/git:cherry-pick-by-patch` `<commit_hash>`** - Cherry-pick git commit into current branch by "patch" command
7171
- **`/git:commit-suggest` `[N]`** - Generate Conventional Commits style commit messages or summarize existing commits
7272
- **`/git:debt-scan`** - Analyze technical debt indicators in the repository
73+
- **`/git:review-changes` `[--staged|--pr-ready|--commits N]`** - Automated code review analysis for git changes
7374
- **`/git:suggest-reviewers` `[base-branch]`** - Suggest appropriate reviewers for a PR based on git blame and OWNERS files
7475
- **`/git:summary`** - Show current branch, git status, and recent commits for quick context
7576

docs/data.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
"synopsis": "/git:debt-scan",
3232
"argument_hint": ""
3333
},
34+
{
35+
"name": "review-changes",
36+
"description": "Automated code review analysis for git changes",
37+
"synopsis": "/git:review-changes # Review current working directory changes",
38+
"argument_hint": "[--staged|--pr-ready|--commits N]"
39+
},
3440
{
3541
"name": "suggest-reviewers",
3642
"description": "Suggest appropriate reviewers for a PR based on git blame and OWNERS files",
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
description: Automated code review analysis for git changes
3+
argument-hint: [--staged|--pr-ready|--commits N]
4+
---
5+
6+
## Name
7+
git:review-changes
8+
9+
## Synopsis
10+
```
11+
/git:review-changes # Review current working directory changes
12+
/git:review-changes --staged # Review staged changes only
13+
/git:review-changes --pr-ready # Generate PR-ready review summary
14+
/git:review-changes --commits N # Review last N commits
15+
```
16+
17+
## Description
18+
AI-powered code review assistant that analyzes git changes and provides structured feedback on code quality, security, performance, and style. Helps maintain consistent code review standards across development teams.
19+
20+
**Key Features:**
21+
- Security vulnerability detection
22+
- Performance issue identification
23+
- Code style and best practice recommendations
24+
- Automated review checklist generation
25+
- PR-ready summary formatting
26+
27+
**Use cases:**
28+
- Pre-commit quality checks
29+
- Self-review before creating PRs
30+
- Mentoring and learning from automated feedback
31+
- Ensuring consistent review standards
32+
33+
## Implementation
34+
35+
The command analyzes git changes using multiple review perspectives:
36+
37+
**Step 1: Change Detection**
38+
1. Determine scope based on arguments:
39+
- Default: `git diff HEAD` (all uncommitted changes)
40+
- `--staged`: `git diff --cached` (staged changes only)
41+
- `--commits N`: `git diff HEAD~N..HEAD` (last N commits)
42+
2. Extract changed files and diff content
43+
3. Identify file types for language-specific analysis
44+
45+
**Step 2: Multi-Perspective Analysis**
46+
Analyze changes from these perspectives:
47+
1. **Security Review**
48+
- Check for hardcoded secrets/credentials
49+
- Identify potential injection vulnerabilities
50+
- Review authentication/authorization changes
51+
- Flag unsafe file operations
52+
53+
2. **Performance Review**
54+
- Identify inefficient algorithms or data structures
55+
- Check for unnecessary database queries
56+
- Review memory allocation patterns
57+
- Flag potential bottlenecks
58+
59+
3. **Code Quality Review**
60+
- Assess code readability and maintainability
61+
- Check adherence to established patterns
62+
- Review error handling implementation
63+
- Validate naming conventions
64+
65+
4. **Testing Coverage**
66+
- Identify untested code paths
67+
- Suggest test cases for new functionality
68+
- Review existing test modifications
69+
- Check for regression test needs
70+
71+
**Step 3: Generate Structured Report**
72+
1. **Summary Section**: High-level change overview
73+
2. **Critical Issues**: Security and performance blockers
74+
3. **Recommendations**: Specific improvement suggestions
75+
4. **Review Checklist**: Items for human reviewers to verify
76+
5. **Test Plan**: Suggested testing approach
77+
78+
**Step 4: Format Output**
79+
- `--pr-ready` flag generates markdown formatted for PR descriptions
80+
- Standard output uses terminal-friendly formatting with colors/icons
81+
- Include file references with line numbers for easy navigation
82+
83+
## Examples
84+
85+
```bash
86+
# Review all uncommitted changes
87+
/git:review-changes
88+
89+
# Review only staged files before commit
90+
git add src/auth.ts src/middleware.ts
91+
/git:review-changes --staged
92+
93+
# Generate PR description with review summary
94+
/git:review-changes --pr-ready
95+
96+
# Review changes in last 3 commits
97+
/git:review-changes --commits 3
98+
```
99+
100+
## Return Value
101+
102+
**Standard Format:**
103+
```
104+
🔍 Code Review Analysis
105+
106+
📋 SUMMARY
107+
- 3 files changed, 45 insertions, 12 deletions
108+
- Languages: TypeScript (2), Markdown (1)
109+
- Scope: Authentication system refactoring
110+
111+
🔴 CRITICAL ISSUES
112+
- src/auth.ts:23 - Potential SQL injection in user query
113+
- src/middleware.ts:45 - Hardcoded API key detected
114+
115+
⚠️ PERFORMANCE CONCERNS
116+
- src/auth.ts:67 - N+1 query pattern in user lookup
117+
- Consider caching user permissions (lines 89-103)
118+
119+
✅ POSITIVE CHANGES
120+
- Improved error handling in auth flow
121+
- Added comprehensive input validation
122+
- Clear separation of concerns
123+
124+
📝 RECOMMENDATIONS
125+
1. Use parameterized queries for database operations
126+
2. Extract configuration to environment variables
127+
3. Add rate limiting to authentication endpoints
128+
4. Consider adding integration tests for auth flow
129+
130+
🧪 SUGGESTED TEST PLAN
131+
- [ ] Unit tests for new validation functions
132+
- [ ] Integration tests for auth middleware
133+
- [ ] Security testing for injection vulnerabilities
134+
- [ ] Load testing for performance changes
135+
136+
📁 FILES REVIEWED
137+
- src/auth.ts (32 lines changed)
138+
- src/middleware.ts (13 lines changed)
139+
- README.md (2 lines changed)
140+
```
141+
142+
**PR-Ready Format (`--pr-ready`):**
143+
```markdown
144+
## Code Review Summary
145+
146+
### Changes Overview
147+
- **Files Modified:** 3 files (2 TypeScript, 1 Markdown)
148+
- **Lines Changed:** +45/-12
149+
- **Scope:** Authentication system refactoring
150+
151+
### Security Review ⚠️
152+
- **CRITICAL**: Potential SQL injection vulnerability in `src/auth.ts:23`
153+
- **HIGH**: Hardcoded credentials in `src/middleware.ts:45`
154+
155+
### Performance Impact ✅
156+
- **CONCERN**: N+1 query pattern detected in user lookup
157+
- **IMPROVEMENT**: Enhanced caching strategy recommended
158+
159+
### Review Checklist
160+
- [ ] Verify database queries use parameterized statements
161+
- [ ] Confirm no hardcoded secrets remain
162+
- [ ] Test authentication flow end-to-end
163+
- [ ] Validate rate limiting implementation
164+
165+
### Test Plan
166+
- Unit tests for validation functions
167+
- Integration tests for middleware
168+
- Security penetration testing
169+
- Performance benchmark comparison
170+
```
171+
172+
## Security Guidelines
173+
174+
**The command follows these security principles:**
175+
- Never logs or displays actual secret values
176+
- Provides generic warnings about credential patterns
177+
- Suggests secure alternatives for identified issues
178+
- Focuses on defensive security practices only
179+
180+
## Language-Specific Reviews
181+
182+
**TypeScript/JavaScript:**
183+
- ESLint rule violations
184+
- TypeScript strict mode compliance
185+
- React/Node.js best practices
186+
- Package vulnerability checks
187+
188+
**Python:**
189+
- PEP 8 style compliance
190+
- Security best practices (bandit-style checks)
191+
- Performance anti-patterns
192+
- Type hint coverage
193+
194+
**Go:**
195+
- Go fmt compliance
196+
- Race condition detection
197+
- Error handling patterns
198+
- Interface design review
199+
200+
**General:**
201+
- Documentation completeness
202+
- Git commit message quality
203+
- Breaking change identification
204+
- Backward compatibility analysis
205+
206+
## Arguments
207+
208+
- **--staged**: Review only staged changes (git diff --cached)
209+
- **--pr-ready**: Format output as PR-ready markdown summary
210+
- **--commits N**: Review changes in last N commits (1-20)
211+
- **[default]**: Review all uncommitted changes in working directory
212+
213+
## See Also
214+
- **`/git:commit-suggest`** - Generate conventional commit messages
215+
- **`/git:summary`** - Display repository status and recent commits
216+
- **`/utils:generate-test-plan`** - Create comprehensive test plans

0 commit comments

Comments
 (0)