An automated GitHub PR review agent powered by Google Gemini. It listens for GitHub webhook events, analyzes code diffs, and posts structured, actionable review comments directly on the PR.
- 🔐 Secure webhook handling — HMAC SHA-256 signature validation
- 🤖 Google Gemini-powered analysis — Gemini 1.5 Flash/Pro reviews your diff
- 🐛 Structured output — Bugs, suggestions, praise, and security concerns
- ⚡ Async queue — Non-blocking job processing via Redis + RQ
- 🗄️ Persistent logging — All reviews stored in PostgreSQL
- 🔁 Re-trigger command — Post
/reviewin any PR comment to re-run - 🐳 Docker Compose — One-command local setup
GitHub PR Event
│
▼
POST /webhook (FastAPI)
├─ Verify HMAC SHA-256 signature
├─ Validate event type (opened/synchronize/reopened)
└─ Enqueue job → Redis
│
▼
RQ Worker
├─ Fetch PR diff + metadata (GitHub REST API)
├─ Post "Review in progress..." comment
├─ Build prompt (context_builder)
├─ Call Google Gemini API
├─ Parse structured JSON response
├─ Update comment with full review (GitHub)
└─ Log to PostgreSQL
- Docker Desktop
- A GitHub account with a repository you can test on
- A Google AI Studio API key (Gemini)
- A GitHub Personal Access Token (PAT) with
reposcope
git clone <your-repo-url>
cd "AI GitHub PR Review Agent"
# Copy the env template
cp .env.example .envEdit .env and fill in your values:
GITHUB_TOKEN=ghp_your_token_here
GITHUB_WEBHOOK_SECRET=your_webhook_secret_here
GEMINI_API_KEY=your_gemini_key_here
GEMINI_MODEL=gemini-1.5-flash
DATABASE_URL=postgresql+asyncpg://postgres:postgres@postgres:5432/pr_review_agent
REDIS_URL=redis://redis:6379/0docker-compose up --buildThis starts:
| Service | Port | Description |
|---|---|---|
api |
8000 | FastAPI webhook receiver |
worker |
— | RQ background worker |
redis |
6379 | Job queue |
postgres |
5432 | Review log database |
Install ngrok and run:
ngrok http 8000Copy the https://xxxx.ngrok.io URL.
- Go to your test repo on GitHub → Settings → Webhooks → Add webhook
- Set Payload URL to:
https://xxxx.ngrok.io/webhook - Set Content type to:
application/json - Set Secret to the same value as
GITHUB_WEBHOOK_SECRETin your.env - Select Individual events → check Pull requests and Issue comments
- Click Add webhook
Open a PR on your test repo and watch the agent post a review comment!
Post the following comment on any PR to re-run the review:
/review
# Install dependencies locally
pip install -r requirements.txt
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run a specific test file
pytest tests/test_review_engine.py -v.
├── app/
│ ├── main.py # FastAPI entry point
│ ├── config.py # Settings (pydantic-settings)
│ ├── models/
│ │ └── db_models.py # SQLAlchemy ORM models
│ ├── db/
│ │ └── database.py # Async DB session management
│ ├── routers/
│ │ └── webhook.py # POST /webhook handler
│ ├── services/
│ │ ├── github_service.py # GitHub API integration
│ │ ├── gemini_service.py # Google Gemini LLM
│ │ ├── context_builder.py # Prompt construction + Markdown formatter
│ │ └── review_engine.py # Review pipeline orchestrator
│ └── workers/
│ └── pr_worker.py # RQ background job
├── migrations/
│ └── init.sql # PostgreSQL schema
├── tests/
│ ├── test_webhook.py
│ ├── test_gemini_service.py
│ └── test_review_engine.py
├── .env.example
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── README.md
| Variable | Required | Default | Description |
|---|---|---|---|
GITHUB_TOKEN |
✅ | — | GitHub PAT with repo scope |
GITHUB_WEBHOOK_SECRET |
✅ | — | Webhook secret (must match GitHub settings) |
GEMINI_API_KEY |
✅ | — | Google AI Studio API key |
GEMINI_MODEL |
❌ | gemini-1.5-flash |
Model to use (gemini-1.5-pro for higher quality) |
DATABASE_URL |
❌ | Local PostgreSQL | postgresql+asyncpg://... |
REDIS_URL |
❌ | redis://localhost:6379/0 |
Redis connection string |
LOG_LEVEL |
❌ | INFO |
DEBUG, INFO, WARNING, ERROR |
MAX_DIFF_BYTES |
❌ | 102400 (100KB) |
Max diff bytes sent to LLM |
MAX_DIFF_LINES |
❌ | 2000 |
Max diff lines sent to LLM |
| Method | Path | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/docs |
Swagger UI |
GET |
/redoc |
ReDoc UI |
POST |
/webhook |
GitHub webhook receiver |
- The webhook secret is required — all requests without a valid HMAC signature are rejected with
401 - Your
GITHUB_TOKENandGEMINI_API_KEYare never logged or exposed - Use a GitHub App instead of PAT for production deployments
- GitHub App authentication (production-grade)
- Inline file-level review comments
- Multi-agent analysis (security agent, performance agent)
- Configurable review rules per repository
- Dashboard UI for reviewing history
- GitLab / Bitbucket support