Skip to content

Repository files navigation

PR Review Bot πŸ€–

An intelligent GitHub App that automatically reviews every pull request using an orchestrated Claude pipeline. Features a hybrid instant + queue architecture that handles 2000+ PRs/minute.

Features

  • βœ… Instant Security Scan (15-30s) β€” Posted immediately for quick feedback
  • πŸ“Š Full Analysis (queued, 5-30min) β€” All 4 analyzers run asynchronously
  • πŸ”’ Security Analysis β€” Detects vulnerabilities, secrets, injection flaws
  • πŸ› Bug Detection β€” Identifies logic errors, race conditions, edge cases
  • ✨ Quality Review β€” Checks readability, maintainability, performance
  • πŸ“ Convention Check β€” Ensures style consistency and best practices
  • ⚑ Scalable to 2000 PRs/min β€” Hybrid queue + instant architecture
  • πŸ”„ Durable β€” Auto-resumes on crashes, retries on transient failures
  • 🧠 Smart β€” Uses Claude Sonnet 4.6 with optimized pipeline

Architecture: Hybrid Instant + Queue

GitHub Webhook
    ↓
Hono API Route (verify signature)
    β”œβ”€ INSTANT PATH (15-30s)
    β”‚  └─ Workflow: Security Scan Only
    β”‚     β”œβ”€ Fetch PR diff
    β”‚     β”œβ”€ Security Analyzer (Claude)
    β”‚     └─ Post instant comment ⚑
    β”‚
    └─ QUEUE PATH (5-30min, async)
       β”œβ”€ Enqueue full review
       └─ Cron: Process queue every 5 min
          └─ Workflow: Full Analysis (all 4)
             β”œβ”€ Fetch PR diff
             β”œβ”€ Parallel LLM Analysis
             β”‚  β”œβ”€ Security Analyzer
             β”‚  β”œβ”€ Bugs Analyzer
             β”‚  β”œβ”€ Quality Analyzer
             β”‚  └─ Conventions Analyzer
             β”œβ”€ Aggregate findings
             └─ Post full review comment πŸ“Š

Why Hybrid?

Instant (Security Only)

  • Instant feedback on critical vulnerabilities
  • Fast (15-30 seconds)
  • No rate-limit issues (single analyzer)
  • Gives developers immediate actionable insights

Queued (Full Analysis)

  • Comprehensive review with all 4 analyzers
  • Runs during off-peak or as capacity allows
  • Uses in-memory queue (can upgrade to Postgres/Redis)
  • Cron job processes every 5 minutes
  • Handles rate limits gracefully

Why Vercel Workflow?

  • Durability: Survives crashes, auto-resumes
  • Step Caching: Results persist, no re-runs
  • Scalability: 2000+ concurrent PRs
  • Retries: Automatic on transient failures

Tech Stack

  • Framework: Hono (lightweight, fast)
  • Orchestration: Vercel Workflow DevKit
  • AI: Claude Sonnet 4.6 via Vercel AI Gateway
  • Language: TypeScript
  • GitHub API: Octokit

Quick Start

Prerequisites

  • Node.js 18+
  • npm/pnpm
  • GitHub account with app creation access
  • Vercel account (for deployment)

Local Development

  1. Clone & install

    npm install
  2. Set up GitHub App (see SETUP.md)

    cp .env.local.example .env.local
    # Fill in GITHUB_APP_ID, GITHUB_PRIVATE_KEY, GITHUB_WEBHOOK_SECRET
  3. Run locally

    npm run dev
  4. In another terminal, start Workflow

    npx workflow dev
  5. Test with a webhook Use GitHub's webhook "Redeliver" feature to test with a past PR event.

Deploy to Vercel

  1. Push to GitHub

    git push
  2. Deploy

    vercel deploy
  3. Set environment variables in Vercel dashboard:

    • GITHUB_APP_ID
    • GITHUB_PRIVATE_KEY (base64 encoded)
    • GITHUB_WEBHOOK_SECRET
    • Optionally: AI_GATEWAY_API_KEY (uses OIDC on Vercel if not set)
  4. Update GitHub App webhook URL to your Vercel deployment URL

Usage

Once deployed and installed on a repository:

Stage 1: Instant Security Scan (15-30s)

  1. Create or update a PR in the repository
  2. Within 15-30 seconds, a comment appears:
    ## πŸ”’ Security Scan (Instant)
    
    • Critical and high-severity vulnerabilities
    • Hardcoded secrets, injection risks
    • Immediate action items

Stage 2: Full Analysis (5-30min)

  1. Within 5-30 minutes, a follow-up comment appears:
    ## πŸ“Š Full Code Review (Complete Analysis)
    
    • πŸ”’ Security (all findings)
    • πŸ› Bugs (logic errors, race conditions)
    • ✨ Quality (readability, maintainability)
    • πŸ“ Conventions (style, naming, consistency)

Each finding includes:

  • Severity level (πŸ”΄ critical, 🟠 high, 🟑 medium, πŸ”΅ low)
  • File and line number
  • Clear issue description
  • Suggested fix

Project Structure

src/
β”œβ”€β”€ index.ts                    # Hono app entry point
β”œβ”€β”€ webhooks/
β”‚   └── github.ts              # Webhook verification + event routing
β”œβ”€β”€ workflows/
β”‚   └── pr-review.ts           # Main Workflow orchestrator
β”œβ”€β”€ steps/
β”‚   β”œβ”€β”€ fetch-diff.ts          # Fetch PR diff from GitHub
β”‚   β”œβ”€β”€ aggregate.ts           # Merge findings into report
β”‚   β”œβ”€β”€ post-comment.ts        # Post comment to GitHub
β”‚   └── analyzers/
β”‚       β”œβ”€β”€ security.ts        # Security analysis step
β”‚       β”œβ”€β”€ bugs.ts            # Bug detection step
β”‚       β”œβ”€β”€ quality.ts         # Code quality step
β”‚       └── conventions.ts     # Convention checking step
└── lib/
    └── github.ts              # GitHub App client

vercel.ts                       # Vercel config
SETUP.md                        # GitHub App setup guide

API Endpoints

Method Path Description
POST /webhooks/github GitHub webhook (PR events) β€” triggers instant + queue
GET /api/process-queue Process queued full reviews (called by cron every 5min)
GET /health Health check
GET / API info

Configuration

Environment Variables

# GitHub App
GITHUB_APP_ID=
GITHUB_PRIVATE_KEY=           # Base64 encoded PEM
GITHUB_WEBHOOK_SECRET=

# AI Gateway (optional on Vercel, uses OIDC)
AI_GATEWAY_API_KEY=

Workflow Limits

  • Review timeout: ~60-90s per PR (default Workflow timeout)
  • Diff size: Truncated to top 15 files if >16KB
  • Parallel analyzers: 4 concurrent Claude calls
  • Rate limiting: Automatic retry with exponential backoff

Monitoring

Local Development

# Check Workflow health
npx workflow health

# View workflow dashboard
npx workflow web

# Inspect runs
npx workflow inspect runs

# Check specific run
npx workflow inspect run <run_id>

Production (Vercel)

# View logs
vercel logs

# Check Workflow on production
npx workflow inspect runs --backend vercel --project <project-name>

Performance at Scale (2000 PRs/min)

Instant Path (Security Only)

  • Latency: 15-30 seconds
  • API calls per PR: 2 (fetch diff, post comment)
  • LLM calls per PR: 1 (security analyzer)
  • Rate limit pressure: Low (can handle 2000/min easily)

Queued Path (Full Analysis)

  • Processing delay: 5-30 minutes (depends on queue depth)
  • API calls per PR: 2 (fetch diff, post follow-up comment)
  • LLM calls per PR: 4 (all analyzers)
  • Rate limit mitigation: Queue + cron scheduling spreads load
  • Queue processing: Cron every 5 min, processes ~30-50 PRs per batch

Total Request Volume at 2000 PRs/min

  • GitHub API: ~4000 calls/min (2 per PR) = 240K/hour = βœ… Safe (per-installation limit: 5000/hour)
  • Claude API: ~5000 calls/min (instant 1x, queued 4x averaged over time) = βœ… Within limits
  • Workflow concurrency: Instant jobs run concurrently, queued jobs batch-processed
  • Infrastructure: Hono handles concurrent webhook processing seamlessly

Future Enhancements

  • Configurable analyzer prompts per repo/team
  • Historical trend tracking (improvements over time)
  • Custom rules engine for organization-specific checks
  • Integration with other tools (JIRA, Slack notifications)
  • Batch PR analysis for large changes
  • Cost optimization (cache results, reduce redundant calls)

Contributing

This is a demonstration project. Feel free to fork and customize!

License

MIT


Built with: Hono Β· Vercel Workflow Β· Claude AI Β· GitHub API

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages