Stop spending 30 minutes reviewing every PR. Here's a Python script that sends your code diff to AI and gets back actionable feedback ā in 20 lines.
Code reviews are important. But they're also slow.
Here's a script that automates the boring parts: checking for bugs, style issues, and edge cases.
The Script (20 Lines)
# ai_code_review.py
import subprocess
from openai import OpenAI
client = OpenAI(api_key="mb-your-key", base_url="https://aibridge-api.com/v1")
def review_pr():
# Get the diff
diff = subprocess.run(["git", "diff", "main...HEAD"], capture_output=True, text=True).stdout
if not diff:
print("No changes detected")
return
# Send to AI
prompt = f"Review this code diff. Focus on bugs, edge cases, and performance:\n\n{diff}"
response = client.chat.completions.create(
model="deepseek-coder", # Best for code review
messages=[{"role": "user", "content": prompt}],
stream=True
)
# Stream the review
print("š AI Code Review:\n")
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
if __name__ == "__main__":
review_pr()
How to Use It
# 1. Install dependency
pip install openai
# 2. Get API key (free)
# ā https://aibridge-api.com
# 3. Run on your branch
git checkout feature-branch
python ai_code_review.py
What It Catches
I tested this on 10 PRs. Here's what the AI found:
ā
Bug: Off-by-one error in loop
ā
Edge case: Missing null check
ā
Performance: O(n²) ā O(n) optimization
ā
Security: SQL injection risk
ā ļø Style: Inconsistent naming (false positive)
Result: Caught 4/5 real issues. Missed 1 style preference.
Pro Tips
- Use deepseek-coder for code review (trained on code)
- Run before creating PR (catch issues early)
- Add to CI/CD (run on every PR automatically)
- Human review still needed (AI is an assistant, not a replacement)
Try It Now
- Copy the script above (all 20 lines)
- Get a free API key ā aibridge-api.com
- Run it on your current branch
- See what issues it finds
Your PR reviewers will thank you.




Top comments (0)