Skip to content

buildthingsuseful/prbrain

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

🧠 PRBrain

AI-powered PR analysis for smarter code review

Free and open source. Built to help developers everywhere. 🌍

CI GitHub release MIT License

πŸš€ Quick Start

Get PRBrain running on your repository in 3 easy steps:

1. Add the Workflow File

Create .github/workflows/prbrain.yml in your repository:

name: PRBrain
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write
  issues: read

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: buildthingsuseful/prbrain@main
        with:
          openai-api-key: ${{ secrets.OPENAI_API_KEY }}
          github-token: ${{ secrets.GITHUB_TOKEN }}

2. Set OpenAI API Key

Add your OpenAI API key as a repository secret:

  • Go to Settings β†’ Secrets and variables β†’ Actions
  • Click New repository secret
  • Name: OPENAI_API_KEY
  • Paste your OpenAI API key

3. Open a Pull Request

That's it! PRBrain will automatically analyze every PR and post a comment.

✨ What PRBrain Does

Every time a PR is opened, PRBrain analyzes it and posts a comment like this:

## 🧠 PRBrain Analysis

πŸ€– **AI-Generated:** High confidence (72%)
*Signals: methodical approach, generic comments, perfect formatting*

πŸ“ **Inferred Intent:** "Add rate limiting to API endpoints"
🎯 **Summary:** Adds middleware-based rate limiting to all public API routes
πŸ“Š **Scope:** 4 files changed | +180 -12 | Medium change
⚠️ **Gaps:** No tests, hardcoded rate limits, no distributed support

### πŸ”„ Similar PRs/Issues
- #234 "API rate limiting" (92% similar) β€” OPEN
- #189 "Throttle requests" (78% similar) β€” CLOSED

### πŸ“ Vision Alignment
βœ… Aligned with project goals

### πŸ“Š Quality Score: 7/10
- βœ… Reasonable scope
- βœ… Well-structured changes
- ⚠️ No docs update
- ❌ Missing tests

Features

  • 🎯 Intent Extraction β€” Reverse-engineers the likely prompt/goal from the diff
  • πŸ€– AI Detection β€” Identifies AI-generated PRs with confidence scores
  • πŸ”„ Duplicate Detection β€” Finds similar open PRs and issues via embeddings
  • πŸ“ Vision Alignment β€” Checks PR against your project's VISION.md
  • πŸ“Š Quality Scoring β€” Scores PRs on tests, size, structure, docs, and complexity

���️ Configuration

Optionally create .prbrain.yml in your repository root:

# LLM model (default: gpt-4o-mini)
model: gpt-4o-mini

# Similarity threshold for duplicate detection (0.0 - 1.0)
similarity_threshold: 0.80

# Path to your project vision document
vision_doc: VISION.md

# Quality scoring settings
quality:
  require_tests: true
  max_files_changed: 50
  max_lines_changed: 1000

# Auto-apply labels
labels:
  ai_generated: "πŸ€– ai-generated"
  duplicate: "duplicate"
  vision_misaligned: "⚠️ scope-creep"

# Ignore patterns
ignore:
  paths: ["*.lock", "*.generated.*"]
  authors: ["dependabot[bot]", "renovate[bot]"]

See Configuration Reference for all options.

πŸ“ Vision Alignment

Add a VISION.md to your repo root describing your project's goals and principles. PRBrain will check every PR against it and flag scope creep. See VISION.md for an example template.

πŸ› οΈ Development

git clone https://github.com/buildthingsuseful/prbrain.git
cd prbrain
npm install
npm test          # Run tests (vitest)
npx tsc --noEmit  # Type check
npm run build     # Bundle with ncc

Project Structure

  • src/core/ β€” Analysis engines (intent, AI detection, dedup, quality, vision)
  • src/adapters/ β€” GitHub API, OpenAI, vector storage
  • src/utils/ β€” Diff parser, tokenizer, logger
  • test/ β€” Test suite with fixtures

πŸ“š Documentation

🀝 Contributing

Contributions welcome! See CONTRIBUTING.md.

πŸ“„ License

MIT License β€” see LICENSE for details.


Built with ❀️ to help open source maintainers manage the flood of AI-generated PRs.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors