Skip to content

achalcipher/PR-solver

Repository files navigation


TypeScript OpenAI Anthropic GitHub Actions License: MIT


Automatically reviews every pull request using AI — tags issues by severity, scores PR health, and notifies your team on Slack.


Typing SVG

⚡ How It Works

flowchart TD
    A([👤 Developer opens a Pull Request]) --> B[GitHub triggers PR-Solver Action]
    B --> C{Filter files\nby path rules}
    C -->|Excluded files| D[⏭️ Skip]
    C -->|Valid files| E[📥 Fetch file content + diff]

    E --> F[🔀 Split diff into patches]

    F --> G[🤖 AI Summarize Stage]
    F --> H[🔍 AI Review Stage]

    G --> G1[Summarize each file diff]
    G1 --> G2[Generate final PR summary]
    G2 --> G3[Generate release notes]
    G2 --> G4{pr_score_enabled?}
    G4 -->|Yes| G5[📊 Score PR 0-100]
    G4 -->|No| G6

    H --> H1[Send file content for context]
    H1 --> H2[Send diff for context]
    H2 --> H3[Review each patch chunk]
    H3 --> H4{Detect severity}
    H4 -->|🔴 Critical| I1[Post Critical comment]
    H4 -->|🟡 Warning| I2[Post Warning comment]
    H4 -->|💡 Suggestion| I3[Post Suggestion comment]
    H4 -->|✅ LGTM| I4[Skip or post LGTM]

    G5 --> G6[💬 Post summary comment on PR]
    G3 --> G7[📝 Update PR description]
    G6 --> G8{Slack webhook\nconfigured?}
    G8 -->|Yes| G9[📣 Send Slack notification]
    G8 -->|No| G10([✅ Done])
    G9 --> G10

    style A fill:#6e40c9,color:#fff
    style G10 fill:#39d353,color:#fff
    style D fill:#555,color:#fff
    style I1 fill:#d73a49,color:#fff
    style I2 fill:#e3b341,color:#000
    style I3 fill:#388bfd,color:#fff
    style I4 fill:#39d353,color:#fff
Loading

🏗️ Architecture

graph LR
    subgraph GitHub["🐙 GitHub"]
        PR[Pull Request Event]
        API[GitHub API\nOctokit]
        Comments[PR Comments\n& Reviews]
    end

    subgraph Action["⚙️ PR-Solver Action"]
        Main[main.ts\nEntry Point]
        Bot[bot.ts\nConversation Manager]
        Review[review.ts\nReview Pipeline]
        Scorer[scorer.ts\nPR Health Score]
        Commenter[commenter.ts\nComment Manager]
        Options[options.ts\nConfig & Prompts]
    end

    subgraph AI["🤖 AI Providers"]
        OpenAI[OpenAI\nGPT-4o-mini / GPT-4o]
        Anthropic[Anthropic\nClaude 3.5 Sonnet]
    end

    subgraph Notify["🔔 Notifications"]
        Slack[Slack\nWebhook]
    end

    PR --> Main
    Main --> Bot
    Main --> Review
    Review --> Commenter
    Review --> Scorer
    Bot --> OpenAI
    Bot --> Anthropic
    Commenter --> API
    API --> Comments
    Scorer --> Slack

    style GitHub fill:#161b22,color:#fff,stroke:#30363d
    style Action fill:#0d1117,color:#fff,stroke:#6e40c9
    style AI fill:#1a1a2e,color:#fff,stroke:#412991
    style Notify fill:#1a2a1a,color:#fff,stroke:#39d353
Loading

🔄 Comment Reply Flow

sequenceDiagram
    actor Dev as 👤 Developer
    participant GH as 🐙 GitHub
    participant Bot as 🤖 PR-Solver
    participant AI as ✨ AI Provider

    Dev->>GH: Opens Pull Request
    GH->>Bot: Triggers pull_request event
    Bot->>GH: Fetch diff & file contents
    GH-->>Bot: Returns files + patches
    Bot->>AI: Summarize each file diff
    AI-->>Bot: File summaries
    Bot->>AI: Generate final summary + score
    AI-->>Bot: Summary + PR score (0-100)
    Bot->>GH: Post summary comment 💬
    Bot->>AI: Review each patch chunk
    AI-->>Bot: Severity-tagged feedback
    Bot->>GH: Post inline review comments 📝
    Bot->>GH: Update PR description 📋

    Dev->>GH: Replies "@openai explain this"
    GH->>Bot: Triggers pull_request_review_comment
    Bot->>GH: Fetch conversation chain
    Bot->>AI: Send context + comment
    AI-->>Bot: Response
    Bot->>GH: Post reply 💬
Loading

🚀 Quick Setup

Step 1 — Add the workflow file

Create .github/workflows/pr-solver.yml in your repo:

name: PR-Solver Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
  pull_request_review_comment:
    types: [created]

concurrency:
  group: ${{ github.repository }}-${{ github.event.number || github.head_ref || github.sha }}-${{ github.workflow }}
  cancel-in-progress: ${{ github.event_name != 'pull_request_review_comment' }}

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: achalcipher/PR-solver@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        with:
          ai_provider: openai
          openai_model: gpt-4o-mini
          pr_score_enabled: true
          review_comment_lgtm: false

Step 2 — Add secrets

Go to Settings → Secrets and variables → Actions

Secret Required Get it from
OPENAI_API_KEY ✅ OpenAI platform.openai.com/api-keys
ANTHROPIC_API_KEY ✅ Anthropic console.anthropic.com
SLACK_WEBHOOK_URL Optional Slack App → Incoming Webhooks

Step 3 — Open a PR and watch the magic 🪄


🎯 Severity System

graph TD
    R[AI reviews a patch] --> P{Parse severity\nfrom response}
    P --> C1["🔴 [CRITICAL]\nBug / Security / Breaking change"]
    P --> C2["🟡 [WARNING]\nCode smell / Performance / Risk"]
    P --> C3["💡 [SUGGESTION]\nImprovement / Style / Best practice"]
    P --> C4["✅ [LGTM]\nPatch looks correct"]

    C1 --> POST1[Always post comment]
    C2 --> POST2[Always post comment]
    C3 --> POST3[Always post comment]
    C4 --> CHECK{review_comment_lgtm\nenabled?}
    CHECK -->|Yes| POST4[Post LGTM comment]
    CHECK -->|No| SKIP[Skip — no noise]

    style C1 fill:#d73a49,color:#fff
    style C2 fill:#e3b341,color:#000
    style C3 fill:#388bfd,color:#fff
    style C4 fill:#39d353,color:#fff
    style SKIP fill:#555,color:#fff
Loading

📊 PR Health Score

pie title Scoring Criteria
    "Code Quality & Clarity" : 25
    "Test Coverage" : 20
    "Complexity & Size" : 20
    "Documentation" : 15
    "Error Handling" : 10
    "Security" : 10
Loading
Score Badge Meaning
80 – 100 🟢 Great PR — ready to merge
50 – 79 🟡 Decent but needs some work
0 – 49 🔴 Significant issues found

⚙️ Configuration

Input Default Description
ai_provider openai openai or anthropic
openai_model gpt-4o-mini Model name
openai_model_temperature 0.0 0 = deterministic
openai_retries 5 Retries with exponential backoff
openai_timeout_ms 60000 API timeout in ms
openai_concurrency_limit 4 Parallel API calls
pr_score_enabled false Enable health score
review_comment_lgtm false Post LGTM comments
max_files 60 Max files to review
debug false Log AI messages in CI

🔁 Retry Strategy

flowchart LR
    A[API Call] --> B{Success?}
    B -->|✅ Yes| C[Return response]
    B -->|❌ No| D{Max retries\nreached?}
    D -->|Yes| E[Throw error]
    D -->|No| F[Wait 2ⁿ seconds\n1s → 2s → 4s → 8s...]
    F --> A

    style C fill:#39d353,color:#fff
    style E fill:#d73a49,color:#fff
    style F fill:#e3b341,color:#000
Loading

🛠️ Tech Stack

Layer Technology
Language TypeScript
Runtime Node.js 20
CI Platform GitHub Actions
AI (OpenAI) GPT-4o-mini / GPT-4o via native fetch
AI (Anthropic) Claude 3.5 Sonnet via native fetch
GitHub API Octokit
Concurrency p-limit
Token Counting tiktoken
Notifications Slack Incoming Webhooks

🏃 Build Locally

git clone https://github.com/achalcipher/PR-solver.git
cd PR-solver
npm install
npm run build      # compile TypeScript → lib/
npm run package    # bundle → dist/index.js
npm test           # run 28 unit tests

Made with 🤖 + ❤️ by achalcipher

⭐ Star this repo if it helped you!

About

AI-powered GitHub Action that reviews pull requests, tags issues by severity, scores PR health, and sends Slack notifications — supports OpenAI and Anthropic Claude

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors