Intelligent pull request code review tool powered by LLM providers that automatically analyzes diffs and provides actionable feedback
Project description
ReviewMindBot
An intelligent pull request code review tool powered by LLM providers that automatically analyzes diffs and provides actionable feedback on code changes.
Features
- Automated PR Review: Analyzes pull request diffs using AI-powered code review
- Multi-LLM Support: Integrates with multiple LLM providers (Gemini, OpenAI)
- Smart Diff Parsing: Parses unified diff format with support for hunks, added/removed lines, and context
- GitHub Integration: Fetch and review diffs directly from GitHub PRs
- Intelligent Chunking: Breaks large diffs into manageable chunks for better analysis
- Categorized Findings: Issues categorized by severity (low/medium/high) and type (bug/refactor/test/security)
- Modular Architecture: Extensible design with separate components for parsing, reviewing, routing, and aggregation
Project Structure
reviewmindbot/
├── app/
│ ├── cli.py # Command-line interface
│ ├── core/
│ │ └── diff_parser.py # Unified diff format parser
│ ├── engine/
│ │ ├── orchestrator.py # Coordinates review workflow
│ │ ├── reviewer.py # Performs code review analysis
│ │ ├── router.py # Routes files/hunks to appropriate handlers
│ │ ├── aggregator.py # Aggregates review findings
│ │ ├── file_router.py # File-specific routing logic
│ │ └── models.py # Data models for review results
│ ├── llm/
│ │ ├── base.py # Abstract LLM provider base class
│ │ ├── gemini.py # Google Gemini implementation
│ │ └── openai.py # OpenAI API implementation
│ ├── integration/
│ │ └── github.py # GitHub PR integration
│ └── examples/
│ └── simple_change.diff # Example diff file
├── main.py # Entry point
├── pyproject.toml # Project configuration
└── README.md # This file
Installation
Prerequisites
- Python >=3.12
- pip or uv package manager
Setup
# Clone the repository
git clone https://github.com/2001-Ankit/pr-review-mind-bot.git
cd reviewmindbot
# Install dependencies
pip install -e .
Configuration
LLM Provider Setup
Before using ReviewMindBot, configure your preferred LLM provider:
Google Gemini
# Set your API key as an environment variable
export GEMINI_API_KEY="your-api-key-here"
OpenAI
# Set your API key as an environment variable
export OPENAI_API_KEY="your-api-key-here"
Usage
Command-Line Interface
Review a Local Diff File
python -m app.cli path/to/your/diff/file.diff
Review a GitHub Pull Request
python -m app.cli --pr https://github.com/owner/repo/pull/123
Example
# Review the included example diff
python -m app.cli app/examples/simple_change.diff
Output
The tool outputs review findings in the following format:
=== Review Results ===
[HIGH] bug - Variable 'x' used before definition on line 5
[MEDIUM] refactor - Consider extracting this function for better readability
[LOW] test - Missing unit test for edge case
[HIGH] security - SQL injection vulnerability detected in query string
How It Works
- Diff Parsing: Reads unified diff format and extracts file changes, hunks, and line information
- Chunking: Splits large diffs into smaller chunks using recursive character splitting (500 chars, 50 char overlap)
- LLM Analysis: Sends chunks to the LLM with a system prompt asking for structured code review feedback
- JSON Parsing: Parses LLM responses into structured finding objects
- Aggregation: Combines findings from all chunks and returns categorized results
- Reporting: Displays findings sorted by severity
API Components
DiffParser
Parses unified diff format into structured FileChange objects with hunks and line information.
from app.core.diff_parser import DiffParser
parser = DiffParser()
files = parser.parse(diff_text)
Reviewer
Analyzes code chunks using an LLM provider.
from app.engine.reviewer import Reviewer
from app.llm.gemini import GeminiProvider
llm = GeminiProvider()
reviewer = Reviewer(llm)
findings = reviewer.review_chunk(code_chunk)
LLM Providers
All providers implement the LLMProvider base class:
from app.llm.base import LLMProvider
provider = GeminiProvider() # or OpenAIProvider()
response = provider.generate(system_prompt, user_prompt)
Data Models
Hunk
Represents a single diff hunk:
header: Hunk header lineraw_lines: Original diff linesadded_lines: Lines added in this hunkremoved_lines: Lines removed in this hunkcontext_lines: Unchanged context lines
FileChange
Represents changes to a single file:
file_name: Path to the filehunks: List of Hunk objectstotal_added: Total lines addedtotal_removed: Total lines removedis_new: Whether this is a new fileis_deleted: Whether this file was deleted
ReviewFinding
Represents a single review issue:
severity: low | medium | highcategory: bug | refactor | test | securitymessage: Actionable feedback
Architecture
ReviewMindBot uses a modular, extensible architecture:
- Separations of Concerns: Parsing, reviewing, routing, and aggregation are independent
- Provider Pattern: LLM implementations are pluggable via the provider interface
- Orchestrator Pattern: The Orchestrator coordinates the review workflow
- Router Pattern: FileRouter determines how to handle different files/hunks
Contributing
Contributions are welcome! The modular design makes it easy to:
- Add new LLM providers (extend
LLMProvider) - Improve diff parsing (enhance
DiffParser) - Add file-specific logic (enhance
FileRouter) - Implement new aggregation strategies (extend
Aggregator)
Technologies Used
- Python 3.12+: Core language
- LangChain: Text splitting and LLM abstraction
- Google Gemini API: LLM provider
- OpenAI API: LLM provider
- GitHub API: PR integration
Requirements
[project]
name = "reviewmindbot"
version = "0.1.0"
description = "Intelligent PR review bot powered by LLMs"
requires-python = ">=3.12"
dependencies = [
"langchain",
"langchain-text-splitters",
"google-generativeai", # For Gemini
"openai", # For OpenAI
"requests" # For GitHub integration
]
Roadmap
- Add support for more LLM providers (Claude, Llama)
- Implement caching for repeated reviews
- Add webhook integration for automatic PR reviews
- Create GitHub Action for CI/CD integration
- Add support for custom review rules and policies
- Add metrics and reporting
License
MIT License - See LICENSE file for details
Author
Support
For issues, questions, or contributions, please open an issue on GitHub.
Made with ❤️ for better code reviews
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reviewmindbot-0.1.0.tar.gz.
File metadata
- Download URL: reviewmindbot-0.1.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1124c5f84bfaecf47d321f32133439028b32c0a9d904b4140b662ce491e529f9
|
|
| MD5 |
fbcd47285eb50a9732df52b69a9137a7
|
|
| BLAKE2b-256 |
e29cd34013a87d6c0ac8f78ce654fafb53ee8e42a4b5d3a66dd07264fef36f45
|
File details
Details for the file reviewmindbot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reviewmindbot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b350d9b088f34c276d6a28c4d52873f498729d9b21dc48e0c17c617eba4614bd
|
|
| MD5 |
fa80f56aa7170dc469343d5e41706dc9
|
|
| BLAKE2b-256 |
7bf46765bd8df76141650ee9d0e35e280d7b57c3deffd0d9978922e3ad083006
|