δΈζζζ‘£ | English
An intelligent Pull Request code review bot based on Gemini AI that automatically performs in-depth code reviews on GitHub PRs and provides constructive improvement suggestions.
- π€ Intelligent code review based on Google Gemini AI
- π Automatic generation of detailed review reports with issue identification and improvement suggestions
- π Support for automatic Webhook triggers and manual comment triggers (
/review) - π Smart file context analysis for more accurate review opinions
- π·οΈ Automatic addition of review labels
- β‘ Support for retry mechanisms and error handling
- π οΈ Flexible environment variable configuration
View actual operation results: Example PR Review
git clone <repository-url>
cd pr-review-botpip install -r requirements.txtCopy the example configuration file and fill in actual values:
cp env.example .envThen edit the .env file, or directly set the following environment variables:
# GitHub Personal Access Token (requires repo permissions)
# How to get: GitHub Settings β Developer settings β Personal access tokens β Tokens
# Required permissions: Pull requests, Issues
GITHUB_TOKEN=your_github_token
# Google Gemini API Key
GEMINI_API_KEY=your_gemini_api_key# AI model configuration
AI_MODEL_NAME=gemini-2.5-pro # Default: gemini-2.5-pro
# Review configuration
REVIEW_LABEL=ReviewedByUllrAI # Default: ReviewedByUllrAI
MAX_PROMPT_LENGTH=200000 # Default: 200000
INCLUDE_FILE_CONTEXT=true # Default: true
CONTEXT_MAX_LINES=400 # Default: 400
CONTEXT_SURROUNDING_LINES=50 # Default: 50
MAX_FILES_PER_REVIEW=50 # Default: 50
# Output language configuration
OUTPUT_LANGUAGE=english # Default: english (can be any language like "Chinese", "Japanese", etc.)
# Network and retry configuration
MAX_RETRY_ATTEMPTS=3 # Default: 3
RETRY_DELAY=2.0 # Default: 2.0
REQUEST_TIMEOUT=60 # Default: 60
# Server configuration
PORT=5001 # Default: 5001python app.pyThe service will start on the specified port (default 5001).
Configure Webhook in your GitHub repository:
- Go to repository settings β Webhooks β Add webhook
- Payload URL:
http://your-server:5001/webhook - Content type:
application/json - Events: Select
Pull requestsandIssue comments
Note: Currently no Webhook signature verification is required, no need to configure secret.
The bot will automatically review the following events:
- When PR is created (
pull_request.opened) - When PR is updated (
pull_request.synchronize) - When PR is reopened (
pull_request.reopened)
Enter /review in PR comments to manually trigger code review.
GITHUB_TOKEN: GitHub Personal Access Token, requiresrepopermissionsGEMINI_API_KEY: Google Gemini API key
AI_MODEL_NAME: Gemini model name to useMAX_PROMPT_LENGTH: Maximum prompt length sent to AIINCLUDE_FILE_CONTEXT: Whether to include complete file context for analysis
CONTEXT_MAX_LINES: Maximum line limit for complete filesCONTEXT_SURROUNDING_LINES: Number of context lines for code snippetsMAX_FILES_PER_REVIEW: Maximum number of files per review
OUTPUT_LANGUAGE: Specifies the language for AI review comments (default: english). Can be set to any language like "Chinese", "Japanese", "French", etc. If set to "english" or not configured, no language instruction will be added to AI prompts.
MAX_RETRY_ATTEMPTS: Number of retries when API calls failRETRY_DELAY: Retry interval time (seconds)REQUEST_TIMEOUT: HTTP request timeout (seconds)
GET /healthReturns service status and configuration information.
POST /webhookReceives GitHub Webhook events and handles PR reviews.
The application uses structured logging to record all operations, including:
- GitHub API calls
- AI model calls
- Review process status
- Error and exception information
Log level is INFO, error logs will include complete stack traces.
- Use Gunicorn or uWSGI as WSGI server
- Configure reverse proxy (like Nginx)
- Set up appropriate log rotation
- Monitor service health status
Create Dockerfile:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app.py .
CMD ["python", "app.py"]Refer to the env.example file, which contains detailed descriptions and example values for all configuration items.
- Permission errors: Ensure GITHUB_TOKEN has sufficient permissions
- API limits: Check GitHub API rate limits and Gemini API quotas
- Network timeouts: Adjust
REQUEST_TIMEOUTand retry configuration - Memory usage: Large PRs may require adjusting
MAX_PROMPT_LENGTHandMAX_FILES_PER_REVIEW
View application logs for detailed error information:
python app.py 2>&1 | tee app.log