Skip to content

An AI-powered tool that reviews your pull requests — summarizes changes, highlights issues, and speeds up the review process with helpful suggestions.

Notifications You must be signed in to change notification settings

DevloperAmanSingh/ReviewBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 AI PR Reviewer

Enterprise-grade GitHub App for intelligent code review automation

FastAPI Python OpenAI GitHub App

A production-ready GitHub App that provides intelligent, AI-powered code reviews for pull requests. Built with functional programming principles and modern FastAPI architecture, this system automatically analyzes code changes, identifies bugs, security vulnerabilities, and performance issues, then provides actionable feedback directly in GitHub PRs.

🎯 Key Features

🔍 Intelligent Code Analysis

  • AI-Powered Bug Detection: Uses OpenAI GPT-3.5 to identify critical bugs, security flaws, and logic errors
  • Multi-Language Support: Supports Python, JavaScript, TypeScript, Java, C++, Go, Rust, and 15+ languages
  • Context-Aware Analysis: Analyzes code changes with surrounding context for accurate issue detection
  • Severity Classification: Categorizes issues by severity (error/warning/info) and type (bug/security/performance)

🚀 Real-time User Experience

  • CodeRabbit-Style Progress: Live progress indicators showing review status
  • Instant Feedback: Comments appear as analysis completes
  • Non-blocking Webhooks: Async processing ensures fast webhook responses
  • Commit Validation: Ensures reviews target the latest commit

🔐 Production Security

  • GitHub App Authentication: Secure JWT-based GitHub App integration
  • Webhook Signature Verification: HMAC-SHA256 signature validation
  • Input Sanitization: Comprehensive payload validation and size limits
  • OWASP Compliance: Security-first design with safe defaults

Performance & Reliability

  • Functional Architecture: Pure functions, no classes - easier testing and maintenance
  • Async/Await: Non-blocking I/O for high concurrency
  • Structured Logging: Comprehensive logging with contextual information
  • Error Recovery: Graceful error handling with detailed status reporting

🏗️ Architecture Overview

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   GitHub PR     │    │    PR Reviewer   │    │   OpenAI API    │
│   (Webhook)     │───▶│    FastAPI App   │───▶│   (Analysis)    │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                                │
                                ▼
                       ┌──────────────────┐
                       │  GitHub Comments │
                       │   & Status API   │
                       └──────────────────┘

Core Components

Component Purpose Key Features
webhooks.py GitHub event handling Signature verification, event routing
handlers.py PR processing logic Metadata extraction, commit validation
review.py Review orchestration Progress tracking, workflow management
analysis.py AI-powered code analysis OpenAI integration, issue classification
diff_parser.py Diff processing Line-by-line parsing, context extraction
auth.py GitHub authentication JWT generation, installation tokens

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • GitHub App with webhook permissions
  • OpenAI API key

1. Setup Environment

# Clone repository
git clone <your-repo>
cd pr-reviewer

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Configure Environment Variables

# Create .env file
cat > .env << EOF
# GitHub App Configuration
GITHUB_APP_ID=your_app_id
GITHUB_PRIVATE_KEY_PATH=./private-key.pem
GITHUB_WEBHOOK_SECRET=your_webhook_secret

# OpenAI Configuration
OPENAI_API_KEY=your_openai_key

# Application Configuration
ENVIRONMENT=development
HOST=0.0.0.0
PORT=8000
LOG_LEVEL=INFO

# Security Configuration
ALLOWED_HOSTS=localhost,127.0.0.1
ALLOWED_ORIGINS=http://localhost:3000
RATE_LIMIT=100
EOF

3. Setup GitHub App

  1. Create a GitHub App with these permissions:
    • Pull requests: Read & Write
    • Commit statuses: Write
    • Contents: Read
  2. Generate and download private key
  3. Install app on target repositories
  4. Configure webhook URL: https://your-domain.com/webhook

4. Run Application

# Development
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

# Production
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4

📊 API Endpoints

Endpoint Method Purpose
/health GET Health check with service status
/webhook POST GitHub webhook handler
/docs GET Interactive API documentation (dev only)

🔧 Configuration

Environment Variables

Variable Required Description Default
GITHUB_APP_ID GitHub App ID -
GITHUB_PRIVATE_KEY_PATH Path to private key file -
GITHUB_WEBHOOK_SECRET Webhook secret for validation -
OPENAI_API_KEY OpenAI API key -
ENVIRONMENT Environment (development/production) development
LOG_LEVEL Logging level INFO
ALLOWED_HOSTS Comma-separated allowed hosts localhost,127.0.0.1
RATE_LIMIT Requests per minute 100

🧪 Development

Project Structure

pr-reviewer/
├── app/
│   ├── main.py              # FastAPI application entry point
│   ├── config.py            # Configuration management
│   ├── server.py            # Server setup and middleware
│   └── github/
│       ├── webhooks.py      # Webhook handling and validation
│       ├── handlers.py      # PR event processing
│       ├── review.py        # AI review workflow
│       ├── analysis.py      # OpenAI code analysis
│       ├── diff_parser.py   # Diff parsing and processing
│       ├── auth.py          # GitHub App authentication
│       ├── api.py           # GitHub API client
│       ├── inline_comments.py # Comment generation
│       ├── summary.py       # Review summarization
│       └── prompts.py       # AI prompts and templates
├── requirements.txt         # Python dependencies
├── pyproject.toml          # Project configuration
└── README.md               # This file

Code Quality Standards

  • Functional Programming: No classes, pure functions only
  • Type Hints: Full type annotations for better IDE support
  • Error Handling: Comprehensive exception handling with logging
  • Security: Input validation, secure defaults, OWASP compliance
  • Testing: Unit tests for critical functions (add tests as needed)

🎯 Review Process Flow

graph TD
    A[PR Webhook] --> B[Signature Validation]
    B --> C[Parse Payload]
    C --> D[Extract PR Metadata]
    D --> E[Fetch Latest Commit]
    E --> F[Get PR Diff]
    F --> G[Parse Changed Lines]
    G --> H[AI Analysis per Line]
    H --> I[Generate Issues]
    I --> J[Post Inline Comments]
    J --> K[Update PR Status]
    K --> L[Post Summary Comment]
Loading

Built with: Python 3.10+, FastAPI, OpenAI GPT-3.5, GitHub App API | Features: Functional programming, async/await, security-first design, real-time analysis

About

An AI-powered tool that reviews your pull requests — summarizes changes, highlights issues, and speeds up the review process with helpful suggestions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages