Build a GitHub PR Reviewer Bot that Summarizes & Fixes Code Automatically
Pull Request (PR) reviews are vital for maintaining code quality, but they can quickly become a bottleneck for busy engineering teams. Senior developers spend hours checking syntax, reviewing boilerplate logic, and hunting for common security oversights.
In this guide, we will build an automated GitHub PR Reviewer using GitHub Actions, Python, and Velona's unified AI Gateway. When a developer opens or updates a Pull Request, our bot will automatically analyze the git diff, write a concise summary, and post actionable code fix suggestions directly as a PR comment. With a low-cost coding model, each review costs about one paisa.
Architecture Overview
The automated review workflow runs inside your CI/CD pipeline:
- A developer opens or updates a Pull Request on GitHub.
- GitHub Actions triggers a workflow that fetches the PR diff using the GitHub REST API.
- The Python script sends the diff to a coding model via Velona's
/gateway/v1/inference/runendpoint. - The AI evaluates security, readability, and logic, then formats a structured Markdown review.
- The bot posts the feedback back to the Pull Request.
Step 1: Set Up Your Velona Account and API Key
To power the AI reviewer backend:
- Create an account on the Velona Registration Page.
- Navigate to your Wallet Dashboard and top up ₹10 or more via UPI, RuPay, or GPay.
- Go to API Key Management and generate a dedicated key named
GitHub-PR-Reviewer. - Set a spending budget (for example ₹200) on the key to prevent unexpected API costs during busy sprint cycles.
Step 2: Create the Python Review Script
Create a file named review_pr.py in your repository. This script fetches the PR diff, sends it to Velona's gateway, and posts the resulting analysis back to GitHub.
import os
import requests
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
PR_NUMBER = os.environ["PR_NUMBER"]
REPO = os.environ["GITHUB_REPOSITORY"]
VELONA_API_KEY = os.environ["VELONA_API_KEY"]
MODEL = os.getenv("REVIEW_MODEL", "deepseek/deepseek-v4-flash")
MAX_DIFF_CHARS = 8000 # keep very large diffs within budget
# 1. Fetch the Pull Request diff from the GitHub API
diff_response = requests.get(
f"https://api.github.com/repos/{REPO}/pulls/{PR_NUMBER}",
headers={
"Authorization": f"token {GITHUB_TOKEN}",
"Accept": "application/vnd.github.v3.diff",
},
timeout=30,
)
diff_response.raise_for_status()
pr_diff = diff_response.text[:MAX_DIFF_CHARS]
# 2. Build the review prompt
prompt = f"""You are an expert Senior Staff Software Engineer reviewing a GitHub Pull Request.
Analyze the following git diff and produce a clean Markdown review containing:
1. **Summary**: Brief summary of changes.
2. **Key Risks and Bugs**: Potential security flaws, edge cases, or performance issues.
3. **Suggested Fixes**: Specific code snippets improving readability or correctness.
Git Diff:
```diff
{pr_diff}
```"""
# 3. Call the Velona gateway
ai_response = requests.post(
"https://velona.in/gateway/v1/inference/run",
headers={
"Authorization": f"Bearer {VELONA_API_KEY}",
"Content-Type": "application/json",
},
json={"model": MODEL, "turns": [{"role": "user", "content": prompt}]},
timeout=120,
)
ai_response.raise_for_status()
# The native endpoint returns the reply text in data.output
review_markdown = ai_response.json()["data"]["output"]
# 4. Post the review comment back to the PR
requests.post(
f"https://api.github.com/repos/{REPO}/issues/{PR_NUMBER}/comments",
headers={
"Authorization": f"token {GITHUB_TOKEN}",
"Accept": "application/vnd.github.v3+json",
},
json={"body": review_markdown},
timeout=30,
).raise_for_status()
print("PR review posted successfully!")
Prefer the OpenAI SDK? Point it at https://velona.in/v1 with your Velona key and use the same model IDs. The Python guide shows how.
Step 3: Configure the GitHub Action Workflow
Create a workflow file at .github/workflows/pr-reviewer.yml inside your repository:
name: AI Pull Request Reviewer
on:
pull_request:
types: [opened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Dependencies
run: pip install requests
- name: Run AI PR Reviewer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
VELONA_API_KEY: ${{ secrets.VELONA_API_KEY }}
run: python review_pr.py
Note: Store your VELONA_API_KEY in your repository's Settings, Secrets and variables, Actions section. The permissions block is needed so the default token is allowed to comment on the PR.
Step 4: Choosing the Best Model for Code Review
A typical review sends about 2,700 input tokens (prompt plus an 8,000 character diff) and gets back about 800 output tokens. Here is what that costs on Velona at the time of writing:
| Model ID | Cost per review | 200 reviews a month | Best for |
|---|---|---|---|
deepseek/deepseek-v4-flash | ₹0.013 | ₹2.50 | Default reviewer, strong coding score at the lowest price |
deepseek/deepseek-v4-pro | ₹0.09 | ₹19 | Deeper logic and algorithm checks |
qwen/qwen3-coder | ₹0.17 | ₹33 | Code-specialised second opinion |
moonshotai/kimi-k2.6 | ₹0.60 | ₹120 | Agentic and multi-file reasoning |
anthropic/claude-sonnet-5 | ₹1.39 | ₹278 | Architecture-level reviews on critical repos |
A sensible setup is DeepSeek V4 Flash on every PR, and a stronger model only on PRs labelled needs-deep-review, by setting REVIEW_MODEL in the workflow. Check live rupee prices on the Velona pricing page, and see the cheapest AI models for coding agents for a longer comparison.
Debugging and Free Developer Utilities
When tweaking prompts or testing string escapes for diff payloads, use Velona's free developer tools. Utilities like the JSON Formatter, Text Diff Tool, and Regex Evaluator are free and never touch your wallet balance.
If you want to test prompt iterations before deploying the GitHub Action, compare outputs across multiple models in the Model Evaluator.
Conclusion
Automating first-pass PR reviews reduces developer workload and catches security oversights before code reaches production. With Velona, Indian engineering teams can use top coding models and pay in rupees with UPI, with no international card needed.
Ready to automate your CI/CD workflow? Create a free Velona account, add ₹10, and your first few hundred PR reviews are covered.