A CLI tool for automated code review and PR description generation using LLM (Language Learning Model). This tool analyzes Git diffs, structures the changes, and leverages AI to provide insightful code reviews and PR descriptions.
- 🔍 Automated code review generation
- 📝 PR description generation with diagrams and topics
- 🎯 Multiple review modes (brief, detailed, description)
- 📊 Structured diff analysis
- 🚀 Command-line interface with rich options
- 📋 Comprehensive logging system
- 🛡️ Robust error handling
- Node.js (v14 or higher)
- npm (v6 or higher)
- Git installed and configured
- OpenAI API key
Set up your OpenAI API key as an environment variable:
# Linux/macOS
export OPEN_API_KEY=your_openai_api_key
# Windows (Command Prompt)
set OPEN_API_KEY=your_openai_api_key
# Windows (PowerShell)
$env:OPEN_API_KEY="your_openai_api_key"
- Install the required dependencies:
npm install commander winston
- Install the tool globally:
npm install -g .
pr-reviewer [options]
Options:
-V, --version output version number
-b, --branch <branch> branch name to review (required)
-m, --mode <mode> review mode (review/description) (default: "review")
-t, --target-branch <branch> target branch to compare against (default: "development")
-v, --verbose enable verbose logging
-o, --output <output> output folder (default: "tmp")
-h, --help display help for command
# Basic review of a feature branch
pr-reviewer -b feature/new-feature
# Generate detailed description comparing against main branch
pr-reviewer -b feature/new-feature -m description -t main
# Review with verbose logging
pr-reviewer -b feature/new-feature -v
# Show help
pr-reviewer --help
-
review (default)
- Performs a detailed code review
- Identifies potential issues
- Suggests improvements
- Reviews code style and best practices
-
description
- Generates comprehensive PR description
- Creates diagrams where applicable
- Lists key changes and impacts
- Provides technical context
-
brief
- Quick summary of changes
- High-level impact analysis
- Key points for reviewers
The tool generates several output files:
combined.log
: Complete execution logerror.log
: Error-specific logging- Temporary diff files (automatically cleaned up)
- LLM review output (saved to specified location)
-
Initialization
- Parses command-line arguments
- Validates input parameters
- Sets up logging system
-
Git Operations
- Fetches latest changes
- Checks out specified branch
- Generates diff against target branch
-
Diff Processing
- Parses Git diff output
- Structures changes by file
- Identifies additions and removals
-
LLM Integration
- Sends structured changes to LLM
- Processes LLM response
- Generates formatted output
-
Cleanup
- Removes temporary files
- Logs operation completion
- Handles any errors
The tool includes comprehensive error handling for:
- Git operation failures
- File system issues
- LLM communication problems
- Invalid input parameters
Errors are:
- Logged to error.log
- Displayed in console with context
- Handled gracefully with proper cleanup
pr-reviewer/
├── src/
│ ├── GitOperations.js
│ ├── DiffParser.js
│ ├── PRReviewer.js
│ ├── LLMAdapter.js
│ └── send_to_llm.js
├── logs/
│ ├── combined.log
│ └── error.log
└── package.json
- Follow the existing class structure
- Implement error handling
- Add appropriate logging
- Update tests if applicable
Common issues and solutions:
-
Git access errors
- Ensure Git is properly configured
- Check repository permissions
-
API key issues
- Verify OPEN_API_KEY is set
- Check key validity
-
Parsing errors
- Ensure branch exists
- Check for valid diff output
The tool uses customizable prompts for different review modes. These prompts can be modified by editing the MODE_FOR_PROMPT.js
file in the project root.
// prompts.js
module.exports = {
PROMPTS: {
review: `[Your custom review prompt]`,
brief: `[Your custom brief prompt]`,
description: `[Your custom description prompt]`,
},
};
- review: Used for detailed code reviews
- brief: Used for quick summaries
- description: Used for PR descriptions
To modify the prompts:
- Locate
MODE_FOR_PROMPT.js
in the project root - Edit the desired prompt in the
PROMPTS
object - Save the file - changes will take effect immediately
// prompts.js
module.exports = {
PROMPTS: {
review: `
As a senior developer, review this code focusing on:
- Performance implications
- Security concerns
- Best practices
- Potential edge cases
Please be constructive and specific.
`,
brief: `
Provide a 2-3 sentence summary of the changes.
Include:
- Main purpose 🎯
- Key technical changes 🔧
- Impact on users 👥
`,
description: `
Create a comprehensive PR description with:
1. Overview of changes
2. Technical implementation details
3. Testing considerations
4. Visual diagrams where applicable
`,
},
};
- Be Specific: Clearly define what you want the LLM to focus on
- Format Consistently: Use clear formatting for better readability
- Include Guidelines: Add specific instructions for output format
- Keep it Focused: Each prompt should have a single clear purpose
- Test Changes: Verify new prompts generate desired outputs
To add a new review mode:
-
Add your new prompt to the
PROMPTS
object:module.exports = { PROMPTS: { // Existing prompts... newMode: `Your new prompt here`, }, };
-
Use the new mode:
pr-reviewer -b feature/branch -m newMode
MIT License - see LICENSE.md for details
For bugs and feature requests, please create an issue in the repository.
Note: This tool is in active development. Please report any issues or suggestions for improvement.
# Increment version
npm version patch|minor|major
# Publish
npm publish