An intelligent GitHub App that automatically reviews pull requests using Google's Gemini AI. Built with Python, Flask, and the GitHub API.
- π Automatic Code Review: Reviews code in pull requests using Gemini AI
- π Real-time Processing: Responds to PR events instantly via webhooks
- π‘οΈ Secure: Proper webhook signature verification and GitHub App authentication
- β‘ Async Support: Optional async version for better performance
- π§ͺ Local Testing: Easy local development with ngrok
- π¦ Easy Deployment: Ready for Vercel, Heroku, or any Python hosting
git clone <your-repo>
cd github-ai-reviewer-python
# Run the setup script
python setup.py
# Create virtual environment
python -m venv venv
source venv/bin/activate # On macOS/Linux
# venv\Scripts\activate # On Windows
# Install dependencies
pip install -r requirements.txt
# Copy environment template
cp .env.example .env
Edit .env
file with your values:
GITHUB_APP_ID=your_app_id_here
GITHUB_INSTALLATION_ID=your_installation_id_here
WEBHOOK_SECRET=your_webhook_secret_here
GEMINI_API_KEY=your_gemini_api_key_here
- Go to GitHub Settings β Developer settings β GitHub Apps β New GitHub App
- Fill in the details:
- Name: AI Code Reviewer (Dev)
- Homepage URL:
http://localhost:5000
- Webhook URL:
https://your-ngrok-url.ngrok.io/webhook
- Webhook Secret: Generate a random string
- Permissions:
- Repository permissions:
- Contents: Read
- Pull requests: Write
- Metadata: Read
- Repository permissions:
- Subscribe to events: Pull request
- Download the private key and save as
private-key.pem
# Terminal 1: Start ngrok
ngrok http 5000
# Terminal 2: Start the server
python server.py
# Or use the async version for better performance
python async_server.py
- Update your GitHub App webhook URL with the ngrok URL
- Create a test pull request in a repository where the app is installed
- Watch the magic happen! π
github-ai-reviewer-python/
βββ server.py # Main Flask server
βββ async_server.py # Async version with Quart
βββ setup.py # Setup script
βββ test_server.py # Unit tests
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ vercel.json # Vercel deployment config
βββ private-key.pem # GitHub App private key (you add this)
βββ README.md # This file
# Run unit tests
python test_server.py
# Test health endpoint
curl http://localhost:5000/health
# Test webhook (with proper signature)
curl -X POST http://localhost:5000/webhook \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: pull_request" \
-d '{"action": "opened", "pull_request": {...}}'
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prod
# Set environment variables in Vercel dashboard
# Create Heroku app
heroku create your-app-name
# Set environment variables
heroku config:set GITHUB_APP_ID=your_app_id
heroku config:set GITHUB_INSTALLATION_ID=your_installation_id
heroku config:set WEBHOOK_SECRET=your_webhook_secret
heroku config:set GEMINI_API_KEY=your_gemini_key
# Deploy
git push heroku main
# Build image
docker build -t github-ai-reviewer .
# Run container
docker run -p 5000:5000 --env-file .env github-ai-reviewer
The reviewer currently supports these file extensions:
- Python:
.py
- JavaScript/TypeScript:
.js
,.ts
,.jsx
,.tsx
- Java:
.java
- C/C++:
.c
,.cpp
- Go:
.go
- Rust:
.rs
- PHP:
.php
- Ruby:
.rb
Edit the review_with_gemini()
function to customize the AI prompts:
prompt = f"""
Please review this {filename} file for:
1. Code quality and best practices
2. Potential bugs or security issues
3. Performance improvements
4. Code style and readability
Your custom instructions here...
"""
- β Webhook signature verification
- β GitHub App authentication (more secure than personal tokens)
- β Environment variable protection
- β Input validation and sanitization
- β Error handling and logging
- Simple Flask implementation
- Synchronous processing
- Good for low-traffic scenarios
- Uses Quart (async Flask)
- Concurrent file processing
- Better for high-traffic scenarios
- Faster response times
-
"Invalid signature" error
- Check your
WEBHOOK_SECRET
matches GitHub App settings - Ensure webhook URL is correct
- Check your
-
"Authentication failed" error
- Verify
GITHUB_APP_ID
andGITHUB_INSTALLATION_ID
- Check
private-key.pem
file exists and is valid
- Verify
-
"Gemini API error"
- Verify
GEMINI_API_KEY
is correct - Check API quota and billing
- Verify
-
Webhook not receiving events
- Ensure ngrok is running and URL is updated in GitHub App
- Check GitHub App is installed on the repository
# Enable debug logging
export FLASK_ENV=development
python server.py
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details
- GitHub API and PyGithub library
- Google Gemini AI
- Flask/Quart web frameworks
- ngrok for local development
Happy coding! π If you find this useful, please give it a β!