Skip to content

Latest commit

Β 

History

58 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


πŸ›‘οΈ PRGuard

Your code's last line of defense

AI-powered Pull Request reviewer that scores, comments, auto-fixes, and blocks bad code from reaching production.


Live Demo Python FastAPI Groq Railway License



πŸ“– What is PRGuard?

PRGuard is a GitHub bot that automatically reviews every Pull Request using LLaMA 3.3 running on Groq. It scores your code 0–10, posts inline comments on problem lines, creates auto-fix branches with AI-applied corrections, and sets a green βœ… or red ❌ commit status β€” all within seconds of opening a PR.

No configuration required. Just add the webhook and it works.


⚑ How PRGuard Works

Here is the complete step-by-step flow from PR to review:

Developer pushes code β†’ GitHub sends webhook β†’ PRGuard reviews β†’ Results posted

Step 1 β€” Developer opens a Pull Request

A developer pushes code to a branch and opens a PR on GitHub.

Step 2 β€” GitHub sends a webhook event

GitHub instantly sends a POST request to PRGuard's webhook endpoint with the PR payload.

Step 3 β€” Signature verified

PRGuard verifies the HMAC-SHA256 webhook signature to confirm the request is genuine.

Step 4 β€” Diff fetched

PRGuard calls the GitHub API to fetch the full code diff of the PR.

Step 5 β€” Custom rules loaded

PRGuard checks if a prguard.yml file exists in the repo root and loads any custom rules and threshold.

Step 6 β€” AI reviews the code

The diff + custom rules are sent to LLaMA 3.3 via Groq. The model scores the code 0–10 and identifies issues across 8 categories.

Step 7 β€” Inline comments posted

PRGuard posts a comment directly on each problem line in the diff with severity, category, description, and fix.

Step 8 β€” Summary comment posted

A formatted summary comment is posted on the PR with the score bar, verdict, and all issues in collapsible sections.

Step 9 β€” Auto-fix branch created (if PR failed)

PRGuard creates a new branch prguard/fix-pr-{number}-{sha}, applies AI corrections to each affected file, and pushes the fixes.

Step 10 β€” Review saved to database

The review result is saved to PostgreSQL for dashboard analytics and chat history.

Step 11 β€” Commit status set

GitHub commit status is set to βœ… success (score β‰₯ threshold) or ❌ failure (score < threshold).

Step 12 β€” Developer can chat with the bot

Developer comments /prguard <question> on the PR and the bot replies with a context-aware answer.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     PRGuard Pipeline                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Step 1  β”‚  Step 2  β”‚  Step 3  β”‚  Step 4  β”‚    Step 5      β”‚
β”‚  PR Open β”‚ Webhook  β”‚ Verify   β”‚  Fetch   β”‚  Load Rules    β”‚
β”‚          β”‚  Event   β”‚   Sig    β”‚   Diff   β”‚  prguard.yml   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Step 6  β”‚  Step 7  β”‚  Step 8  β”‚  Step 9  β”‚   Step 10-12  β”‚
β”‚ AI Reviewβ”‚ Inline   β”‚ Summary  β”‚ Auto-Fix β”‚  Save + Status β”‚
β”‚  Groq    β”‚Comments  β”‚ Comment  β”‚  Branch  β”‚  + Chat        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

Feature Description
πŸ€– AI Code Review Scores every PR 0–10 across 8 quality categories
πŸ’¬ Inline Comments Posts issues directly on the affected line in the diff
πŸ”₯ Auto-Fix Branch Creates a prguard/fix-pr-* branch with AI-applied corrections
πŸ“Š Team Dashboard Live dashboard with score trends, pass rates, and issue breakdown
βš™οΈ Custom Rules Define team standards in prguard.yml β€” bot enforces them automatically
πŸ’¬ PR Chat Comment /prguard <question> to ask the bot anything about the review
πŸ”„ Smart Retry Handles API rate limits with exponential backoff (4 attempts)
βœ… Commit Status Sets GitHub green βœ… or red ❌ check on every PR

πŸ” Review Categories

PRGuard checks 8 categories on every PR β€” plus any custom rules you define:

Category What It Checks
🏷️ Naming Single letters, abbreviations, misleading variable names
🧩 Complexity Functions >30 lines, deeply nested conditionals
♻️ Duplication Repeated logic blocks without abstraction
⚠️ Error Handling Missing try/except on I/O, network, and DB calls
πŸ”’ Magic Values Hardcoded strings/numbers that should be constants or config
πŸ” Security Secrets in code, SQL injection, missing input validation
πŸ›‘οΈ Type Safety Missing type hints in Python, implicit any in TypeScript
πŸ’€ Dead Code Commented-out blocks, unused imports and variables
πŸ“‹ Custom Your team's own rules from prguard.yml

πŸ“Š Scoring System

Score Grade Meaning
9–10 ⭐ Excellent Near-perfect. Ready to merge.
7–8 βœ… Good Acceptable. Minor issues only.
5–6 ⚠️ Borderline Real problems. Fix before merging.
3–4 ❌ Poor Multiple critical issues. Do not merge.
0–2 🚨 Unacceptable Rewrite required.

Multiple HIGH severity issues cannot score above 6.


βš™οΈ Custom Rules (prguard.yml)

Drop a prguard.yml file in your repo root to enforce team-specific standards:

rules:
  - "All functions must have docstrings"
  - "No print() statements allowed in production code"
  - "All HTTP calls must have timeout set explicitly"
  - "Database calls must use transactions"
threshold: 8

PRGuard picks this up automatically on every PR β€” no restarts needed.


πŸ’¬ PR Chat

Comment /prguard <question> directly on any PR:

/prguard what is the most critical issue to fix first?
/prguard how do I fix the complexity issue in main.py?
/prguard why did this PR fail?

The bot replies with a detailed, context-aware answer based on the actual review results.


πŸ—οΈ Architecture

GitHub PR Event
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Webhook   │────▢│  FastAPI App │────▢│  Groq API   β”‚
β”‚  (GitHub)   β”‚     β”‚  (Railway)   β”‚     β”‚ LLaMA 3.3   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό            β–Ό            β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Inline  β”‚ β”‚ Auto-Fix β”‚ β”‚Dashboard β”‚
        β”‚ Comments β”‚ β”‚  Branch  β”‚ β”‚(Postgres)β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

PRGuard/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py           # FastAPI app & webhook handler
β”‚   β”œβ”€β”€ ai_reviewer.py    # Groq review engine + retry logic
β”‚   β”œβ”€β”€ auto_fixer.py     # Auto-fix branch creator
β”‚   β”œβ”€β”€ github_client.py  # GitHub API wrapper
β”‚   β”œβ”€β”€ formatter.py      # PR comment formatting
β”‚   β”œβ”€β”€ database.py       # PostgreSQL storage
β”‚   β”œβ”€β”€ dashboard.html    # Mission Control UI
β”‚   β”œβ”€β”€ home.html         # Landing page
β”‚   β”œβ”€β”€ rules.py          # prguard.yml parser
β”‚   β”œβ”€β”€ chat.py           # /prguard chat handler
β”‚   β”œβ”€β”€ models.py         # Pydantic data models
β”‚   └── config.py         # Settings & env vars
β”œβ”€β”€ prguard.yml           # Custom rules example
β”œβ”€β”€ Procfile              # Railway start command
└── requirements.txt

πŸš€ Getting Started

Prerequisites

  • Python 3.11+
  • GitHub account & personal access token
  • Groq API key (free tier available)
  • ngrok for local development

1. Clone & Install

git clone https://github.com/AtharvaVavhal/PRGuard.git
cd PRGuard
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configure Environment

Create a .env file in the project root:

GITHUB_TOKEN=your_github_personal_access_token
GITHUB_WEBHOOK_SECRET=your_webhook_secret
GROQ_API_KEY=your_groq_api_key
GROQ_MODEL=llama-3.3-70b-versatile
PASS_SCORE_THRESHOLD=7
LOG_LEVEL=INFO
DATABASE_URL=postgresql://...        # Railway provides this automatically

3. Run Locally

# Start ngrok tunnel
ngrok http 8000

# Start the server
uvicorn app.main:app --port 8000

4. Set Up GitHub Webhook

  1. Go to your repo β†’ Settings β†’ Webhooks β†’ Add webhook
  2. Payload URL: https://your-ngrok-url/webhook/github
  3. Content type: application/json
  4. Secret: your webhook secret
  5. Events: select Pull requests and Issue comments

5. Add Custom Rules (Optional)

# prguard.yml β€” place in your repo root
rules:
  - "All functions must have docstrings"
  - "No hardcoded API keys"
threshold: 7

☁️ Deploy to Railway

# 1. Fork this repo on GitHub
# 2. Go to railway.app β†’ New Project β†’ Deploy from GitHub repo
# 3. Add PostgreSQL database to the project
# 4. Set all environment variables in the Variables tab
# 5. Railway auto-deploys on every push βœ…

Update your GitHub webhook URL to https://your-app.up.railway.app/webhook/github.


πŸ”§ Tech Stack

Layer Technology
API Framework FastAPI + Uvicorn
AI Model LLaMA 3.3 70B via Groq
GitHub Integration GitHub REST API v3
Database PostgreSQL
HTTP Client httpx
Config Parsing PyYAML
Deployment Railway
Language Python 3.11

🀝 Contributing

Contributions are welcome!

# 1. Fork the repo
# 2. Create your feature branch
git checkout -b feature/my-feature

# 3. Commit your changes
git commit -m 'add my feature'

# 4. Push and open a PR
git push origin feature/my-feature

PRGuard will automatically review your PR. Meta. πŸ€–


πŸ“„ License

MIT License β€” see LICENSE for details.


Built with ❀️  ·  Powered by Groq + LLaMA 3.3  ·  Deployed on Railway


⭐ Star this repo if PRGuard saved your codebase!


🌐 Live Demo Β Β·Β  πŸ› Report Bug Β Β·Β  πŸ’‘ Request Feature

About

πŸ›‘οΈ AI-powered GitHub bot that reviews PRs, scores code quality, posts inline comments, auto-fixes issues, and blocks bad code from merging β€” powered by LLaMA 3.3 on Groq.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages