review-copilot
Version:
ReviewCopilot - AI-powered code review assistant with customizable prompts
530 lines (388 loc) β’ 12.5 kB
Markdown
English | [δΈζ](README.zh-CN.md)
<p align="center">
<img src="public/logo.svg" alt="ReviewCopilot Logo" width="180" />
</p>
<h1 align="center">ReviewCopilot</h1>
<p align="center">
<strong>AI-powered code review assistant for GitHub with customizable rules and multi-provider support</strong>
</p>
<p align="center">
<a href="https://github.com/AlexShan2008/review-copilot/actions"><img src="https://github.com/AlexShan2008/review-copilot/actions/workflows/ci.yml/badge.svg" alt="CI Status"></a>
<a href="https://codecov.io/gh/AlexShan2008/review-copilot"><img src="https://codecov.io/gh/AlexShan2008/review-copilot/branch/main/graph/badge.svg" alt="codecov"></a>
<a href="https://www.npmjs.com/package/review-copilot"><img src="https://img.shields.io/npm/v/review-copilot.svg" alt="npm version"></a>
<a href="https://www.npmjs.com/package/review-copilot"><img src="https://img.shields.io/npm/dt/review-copilot.svg" alt="Total Downloads"></a>
<a href="https://opensource.org/license/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="https://github.com/AlexShan2008/review-copilot/blob/main/CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"></a>
</p>
## π Table of Contents
- [β¨ Features](#-features)
- [π Quick Start](#-quick-start)
- [π¦ Installation](#-installation)
- [βοΈ Configuration](#οΈ-configuration)
- [π€ AI Providers](#-ai-providers)
- [π§ Usage](#-usage)
- [ποΈ CI/CD Integration](#οΈ-cicd-integration)
- [π Examples](#-examples)
- [πΌοΈ Screenshots](#οΈ-screenshots)
- [π Troubleshooting](#-troubleshooting)
- [π€ Contributing](#-contributing)
- [π License](#-license)
## β¨ Features
<table>
<tr>
<td width="50%">
**π€ AI-Powered Reviews**
- OpenAI GPT models support
- DeepSeek integration
- Customizable review prompts
- Multi-provider support
</td>
<td width="50%">
**π Smart Rules**
- Commit message validation
- Branch naming conventions
- Custom review points
- File pattern filtering
</td>
</tr>
<tr>
<td width="50%">
**π§ Easy Integration**
- GitHub Actions ready
- GitLab CI (coming soon)
- Environment-based config
- Zero-config setup
</td>
<td width="50%">
**π― Flexible & Secure**
- YAML configuration
- Environment variables
- Glob pattern filtering
- Secure API key management
</td>
</tr>
</table>
## π Quick Start
Get ReviewCopilot running in under 2 minutes:
```bash
# 1. Install
npm install -D review-copilot
# 2. Initialize
npx review-copilot init
# 3. Set your API key
echo "AI_API_KEY_DEEPSEEK=your-api-key" >> .env
# 4. Run review
npx review-copilot review
```
> **π‘ Tip**: DeepSeek is recommended for stability. OpenAI support is in beta.
### π― What you get:
- β
Automated code quality analysis
- β
Security vulnerability detection
- β
Performance optimization suggestions
- β
Best practices enforcement
- β
Direct PR comments integration
### π Why ReviewCopilot?
<table>
<tr>
<td width="50%">
**β° Save Time**
- Instant feedback on code changes
- Reduce manual review time by 60%
- Focus on architecture, not syntax
</td>
<td width="50%">
**π§ Easy Setup**
- Zero configuration required
- Works with existing CI/CD
- Supports multiple AI providers
</td>
</tr>
<tr>
<td width="50%">
**π Improve Quality**
- Consistent review standards
- Catch issues early
- Learn from AI suggestions
</td>
<td width="50%">
**π° Cost Effective**
- Reduce senior developer review time
- DeepSeek: ~$0.001 per request
- OpenAI: ~$0.01 per request
</td>
</tr>
</table>
## π¦ Installation
### Using npm
```bash
npm install -D review-copilot
```
### Using pnpm
```bash
pnpm add -D review-copilot
```
### Using yarn
```bash
yarn add -D review-copilot
```
## βοΈ Configuration
### Basic Setup
After running `npx review-copilot init`, you'll get a `.review-copilot.yaml` file:
```yaml
providers:
deepseek:
enabled: true
apiKey: ${AI_API_KEY_DEEPSEEK}
model: deepseek-chat
rules:
commitMessage:
enabled: true
pattern: '^(feat|fix|docs|style|refactor|test|chore|ci)(\\(.+\\))?: .{1,50}'
branchName:
enabled: true
pattern: '^(feature|bugfix|hotfix|release)/[A-Z]+-[0-9]+-.+'
codeChanges:
enabled: true
filePatterns:
- '**/*.{ts,tsx,js,jsx}'
- '!**/dist/**'
- '!**/node_modules/**'
```
### Environment Variables
Create a `.env` file in your project root:
```env
# Choose your AI provider
AI_API_KEY_DEEPSEEK=your-deepseek-api-key
AI_API_KEY_OPENAI=your-openai-api-key
```
### Advanced Configuration
<details>
<summary>π Click to expand advanced configuration options</summary>
```yaml
providers:
openai:
enabled: false
apiKey: ${AI_API_KEY_OPENAI}
model: gpt-4o-mini
baseURL: https://api.openai.com/v1
deepseek:
enabled: true
apiKey: ${AI_API_KEY_DEEPSEEK}
model: deepseek-chat
baseURL: https://api.deepseek.com/v1
customReviewPoints:
- name: 'Security Check'
prompt: 'Review code for potential security vulnerabilities, focusing on input validation, authentication, and data handling.'
- name: 'Performance Review'
prompt: 'Analyze code for performance bottlenecks, memory usage, and optimization opportunities.'
- name: 'Accessibility Check'
prompt: 'Review frontend code for accessibility compliance and best practices.'
rules:
commitMessage:
enabled: true
pattern: '^(feat|fix|docs|style|refactor|test|chore|ci)(\\(.+\\))?: .{1,50}'
prompt: 'Ensure commit messages follow Conventional Commits specification.'
branchName:
enabled: true
pattern: '^(feature|bugfix|hotfix|release)/[A-Z]+-[0-9]+-.+'
prompt: 'Check if branch name follows the pattern: <type>/<ticket-id>-<description>'
codeChanges:
enabled: true
filePatterns:
- '**/*.{ts,tsx,js,jsx,py,java,go,rs}'
- '!**/test/**'
- '!**/tests/**'
- '!**/*.test.*'
- '!**/*.spec.*'
- '!**/dist/**'
- '!**/build/**'
- '!**/node_modules/**'
- '!**/coverage/**'
prompt: 'Review code changes focusing on code quality, potential bugs, performance, security, and best practices.'
```
</details>
## π€ AI Providers
### DeepSeek (Recommended)
- β
Stable and reliable
- β
Cost-effective
- β
Good code understanding
- π Get your API key: [DeepSeek Platform](https://platform.deepseek.com/)
### OpenAI (Beta)
- β οΈ Beta support
- β
High-quality reviews
- β οΈ Higher cost
- π Get your API key: [OpenAI Platform](https://platform.openai.com/)
## π§ Usage
### Command Line
```bash
# Review current branch changes
npx review-copilot review
# Review specific pull request
npx review-copilot review --pr 123
# Initialize configuration
npx review-copilot init
# Show help
npx review-copilot --help
```
### File Filtering
Control which files are reviewed using glob patterns:
```yaml
filePatterns:
# Include patterns
- '**/*.{ts,tsx,js,jsx}'
- '**/*.{py,java,go,rs}'
# Exclude patterns
- '!**/node_modules/**'
- '!**/dist/**'
- '!**/build/**'
- '!**/*.test.*'
- '!**/*.spec.*'
```
## ποΈ CI/CD Integration
### GitHub Actions
Create `.github/workflows/review.yml`:
```yaml
name: Code Review
on:
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created]
jobs:
review:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || contains(github.event.comment.body, '@review-copilot')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm install -g review-copilot
- name: Run Review
env:
AI_API_KEY_DEEPSEEK: ${{ secrets.AI_API_KEY_DEEPSEEK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: review-copilot review
```
### Repository Secrets
Add your API key to GitHub repository secrets:
1. Go to **Settings** β **Secrets and variables** β **Actions**
2. Click **New repository secret**
3. Name: `AI_API_KEY_DEEPSEEK`
4. Value: Your DeepSeek API key
> **π Security Note**: Never commit API keys directly to your repository. Always use GitHub Secrets or environment variables.
## π Examples
### Manual Review Trigger
Comment `@review-copilot` on any pull request to trigger a manual review:

### Automated PR Reviews
ReviewCopilot automatically reviews code changes and posts detailed feedback:

For complete setup instructions, see our [examples directory](examples/README.md).
## πΌοΈ Screenshots
<details>
<summary>πΈ Click to view more screenshots</summary>
### Review Comment Example

### Manual Trigger Example

### Live Example
See a real review comment: [ReviewCopilot PR Review Example](https://github.com/AlexShan2008/review-copilot/pull/25#issuecomment-2922197158)
</details>
## π Troubleshooting
<details>
<summary>π§ Common Issues and Solutions</summary>
### API Key Issues
```bash
# Error: No API key found
# Solution: Check your .env file
echo "AI_API_KEY_DEEPSEEK=your-key" >> .env
```
### GitHub Actions Permissions
```yaml
# Add to your workflow if needed
permissions:
contents: read
pull-requests: write
issues: write
```
### File Pattern Issues
```yaml
# Make sure to escape special characters
filePatterns:
- '**/*.{ts,tsx}' # β
Correct
- '**/*.{ts,tsx}' # β May cause issues without quotes
```
### Common Error Messages
| Error | Solution |
|-------|----------|
| `No changes detected` | Ensure you're in a git repository with changes |
| `API key not found` | Check your `.env` file and environment variables |
| `Rate limit exceeded` | Wait a moment and try again, or upgrade your API plan |
| `File pattern error` | Verify your glob patterns in configuration |
</details>
## π€ Contributing
We welcome contributions! Here's how you can help:
### Development Setup
```bash
# Clone the repository
git clone https://github.com/AlexShan2008/review-copilot.git
cd review-copilot
# Install dependencies
pnpm install
# Run tests
pnpm test
# Build the project
pnpm build
```
### Ways to Contribute
- π **Report bugs** by opening an issue
- β¨ **Suggest features** or improvements
- π **Improve documentation**
- π§ **Submit pull requests**
- π§ͺ **Add test cases**
Please read our [Contributing Guide](CONTRIBUTING.md) for detailed guidelines.
## π Project Status
> **Current Status**
> - β
**GitHub integration**: Fully supported
> - π§ **GitLab integration**: In development
> - β
**DeepSeek provider**: Stable
> - β οΈ **OpenAI provider**: Beta (PRs welcome!)
## π Community & Support
<div align="center">
[](https://github.com/AlexShan2008/review-copilot/stargazers)
[](https://github.com/AlexShan2008/review-copilot/network/members)
[](https://github.com/AlexShan2008/review-copilot/issues)
</div>
### π Get Help
- π **Documentation**: Check our [examples](examples/README.md)
- π **Bug Reports**: [Open an issue](https://github.com/AlexShan2008/review-copilot/issues/new?template=bug_report.md)
- π‘ **Feature Requests**: [Request a feature](https://github.com/AlexShan2008/review-copilot/issues/new?template=feature_request.md)
- π¬ **Questions**: [Ask in Issues](https://github.com/AlexShan2008/review-copilot/issues)
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
<p align="center">
<strong>Made with β€οΈ by the ReviewCopilot team</strong>
</p>
<p align="center">
<a href="https://github.com/AlexShan2008/review-copilot/issues">Report Bug</a> β’
<a href="https://github.com/AlexShan2008/review-copilot/issues">Request Feature</a> β’
<a href="https://github.com/AlexShan2008/review-copilot">β Star Us</a>
</p>