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 .envEdit .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-reviewerThe 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_SECRETmatches GitHub App settings - Ensure webhook URL is correct
- Check your
-
"Authentication failed" error
- Verify
GITHUB_APP_IDandGITHUB_INSTALLATION_ID - Check
private-key.pemfile exists and is valid
- Verify
-
"Gemini API error"
- Verify
GEMINI_API_KEYis 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 ⭐!