Skip to content

Latest commit

ย 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– PR Review Agent

AI PR Reviewer GitHub Actions Node.js LLM Providers

AI-powered, GitHub-native pull request review automation.
Review your PRs automatically. Get actionable feedback directly where the code changed.

PR โ†’ Diff โ†’ AI Review โ†’ Findings โ†’ GitHub Comments




โœจ What Is This?

PR Review Agent is an automated AI code-review system that runs inside GitHub Actions whenever a pull request is opened or updated.

Instead of manually inspecting every changed file first, the agent handles the repetitive review workflow:

Important: The current M1โ€“M5 implementation is a reviewer, not an autonomous code editor. It identifies problems and comments on them; the developer remains responsible for changing the code.




๐Ÿƒ Quick Start

1๏ธโƒฃ Run the installer

From the root of your GitHub repository:

npx @debangsu__/create-pr-review-agent

You don't need to manually clone the reviewer implementation first; the package can be fetched by npx.


2๏ธโƒฃ Choose your AI provider

The installer asks which model provider should perform reviews:

== AI PR Review Agent - installer ==

Installed:
  .github/workflows/pr-review.yml
  scripts/*.js

Which LLM will the agent use to review PRs?
  1) Anthropic (Claude)
  2) OpenAI (GPT)

Choose 1 or 2:

Choose the provider for which you have an API key.


3๏ธโƒฃ Configure the API key ๐Ÿ”‘

The API key should be stored as a GitHub Actions repository secret.

Go to:

GitHub Repository
   โ†“
Settings
   โ†“
Secrets and variables
   โ†“
Actions
   โ†“
New repository secret

For Anthropic:

ANTHROPIC_API_KEY

For OpenAI:

OPENAI_API_KEY

๐Ÿ”’ Never commit an API key into source code, .env files, workflow YAML, README files, or PR comments.

The intended secret flow is:

๐Ÿ” GitHub Secret
      โ”‚
      โ–ผ
โš™๏ธ GitHub Actions
      โ”‚
      โ–ผ
๐Ÿงฉ Provider Adapter
      โ”‚
      โ–ผ
๐Ÿง  Claude / GPT

4๏ธโƒฃ Commit and push

git add .
git commit -m "Add AI PR review agent"
git push

5๏ธโƒฃ Open a pull request ๐ŸŽ‰

Create a normal PR on GitHub.

That's it.

The workflow takes over automatically.


๐Ÿ‘€ What Happens After I Open a PR?

Here is the complete runtime workflow:

flowchart TD
    A["๐Ÿ‘จโ€๐Ÿ’ป Developer opens / updates PR"] --> B["๐Ÿ™ GitHub PR event"]
    B --> C["โš™๏ธ GitHub Actions"]
    C --> D["๐Ÿ“ฅ Fetch PR diff"]
    D --> E["โœ‚๏ธ Chunk diff by file"]
    E --> F["๐Ÿงฉ Build review context"]
    F --> G["๐Ÿง  Claude / GPT"]
    G --> H["๐Ÿ“ฆ Structured findings"]
    H --> I["๐ŸŽš๏ธ Apply severity threshold"]
    I --> J{"๐Ÿ“ Exact line available?"}
    J -->|Yes| K["๐Ÿ’ฌ Inline PR comment"]
    J -->|No| L["๐Ÿ“ Summary / fallback comment"]
    K --> M["๐Ÿ‘จโ€๐Ÿ’ป Human validates finding"]
    L --> M
    M --> N["โœ๏ธ Human fixes code"]
    N --> O["๐Ÿ“ค Push new commit"]
    O --> B
Loading

๐Ÿง  How the Review Works

The reviewer does more than blindly send the entire pull request to an LLM.

Step 1 โ€” Fetch

The agent retrieves the pull-request change set through GitHub's API.

PR
 โ”œโ”€โ”€ changed file A
 โ”œโ”€โ”€ changed file B
 โ”œโ”€โ”€ changed file C
 โ””โ”€โ”€ ...

Step 2 โ€” Chunk

Large PRs are split into focused review units.

                 โ”Œโ”€โ”€ File A review
                 โ”‚
PR diff โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€ File B review
                 โ”‚
                 โ”œโ”€โ”€ File C review
                 โ”‚
                 โ””โ”€โ”€ File N review

This keeps individual review prompts more manageable and focused.


Step 3 โ€” Build context

For the current file, the agent builds a focused review context.

Conceptually:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Current file diff                 โ”‚
โ”‚                                   โ”‚
โ”‚ + changed code                    โ”‚
โ”‚ - removed code                    โ”‚
โ”‚                                   โ”‚
โ”‚ Other changed symbols             โ”‚
โ”‚ โ€ข functionA()                     โ”‚
โ”‚ โ€ข validateToken()                 โ”‚
โ”‚ โ€ข UserRepository.findById()       โ”‚
โ”‚                                   โ”‚
โ”‚ Review instructions               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Why cross-file context?

Suppose:

auth.js
  โ””โ”€โ”€ rename validateToken() โ†’ verifyToken()

server.js
  โ””โ”€โ”€ still calls validateToken()

A purely isolated file review can miss that relationship.

The agent instead supplies a compact list of symbols touched elsewhere in the same PR, allowing the model to reason about relevant cross-file relationships without blindly sending every other diff in full.


๐Ÿงฉ Architecture

High-Level System

flowchart LR
    A["๐Ÿ™ GitHub PR"] --> B["โš™๏ธ GitHub Actions"]
    B --> C["๐Ÿ“ฅ fetch-diff.js"]
    C --> D["โœ‚๏ธ chunk-diff.js"]
    D --> E["๐Ÿง  review-chunk.js"]
    E --> F{"LLM Provider"}
    F --> G["Anthropic / Claude"]
    F --> H["OpenAI / GPT"]
    G --> I["๐Ÿ“ฆ Structured results"]
    H --> I
    I --> J["๐Ÿงฎ aggregate.js"]
    J --> K["๐ŸŽš๏ธ Severity filter"]
    K --> L["๐Ÿ’ฌ post-comment.js"]
    L --> M["๐Ÿ™ GitHub PR feedback"]
Loading

๐Ÿ—๏ธ Repository Structure

PR-Review-Agent/
โ”‚
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ pr-review.yml         โš™๏ธ GitHub Actions entry point
โ”‚
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ fetch-diff.js             ๐Ÿ“ฅ PR diff acquisition
โ”‚   โ”œโ”€โ”€ chunk-diff.js             โœ‚๏ธ Diff decomposition
โ”‚   โ”œโ”€โ”€ review-chunk.js           ๐Ÿง  Review execution
โ”‚   โ”œโ”€โ”€ aggregate.js              ๐Ÿงฎ Result aggregation
โ”‚   โ”œโ”€โ”€ aggregate-lib.js          ๐Ÿงฉ Aggregation utilities
โ”‚   โ”œโ”€โ”€ post-comment.js           ๐Ÿ’ฌ GitHub feedback publishing
โ”‚   โ”œโ”€โ”€ run-review.js             ๐ŸŽ›๏ธ Pipeline orchestration
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ providers/
โ”‚       โ”œโ”€โ”€ anthropic.js          ๐Ÿง  Anthropic adapter
โ”‚       โ”œโ”€โ”€ openai.js             ๐Ÿง  OpenAI adapter
โ”‚       โ””โ”€โ”€ prompt.js             ๐Ÿ“ Prompt construction
โ”‚
โ”œโ”€โ”€ test/
โ”‚   โ””โ”€โ”€ fixtures/
โ”‚       โ”œโ”€โ”€ sample.diff           ๐Ÿงช Diff fixture
โ”‚       โ””โ”€โ”€ chunk-results/
โ”‚           โ”œโ”€โ”€ index.json        ๐Ÿงช Result fixture
โ”‚           โ””โ”€โ”€ validate.json     ๐Ÿงช Validation fixture
โ”‚
โ””โ”€โ”€ .genesis/                     ๐Ÿ“š Project process / development docs

โš™๏ธ Optional Configuration

Create this file in your repository root:

.pr-review.yml

Example:

max_files: 15
severity_threshold: warning

max_files

Controls the configured maximum number of files considered by the reviewer.

severity_threshold

Controls the minimum severity surfaced to the developer.

If the file is omitted, documented defaults apply.



โš ๏ธ Current Limitations

Be precise about what the system can and cannot guarantee.

It is not a human-review replacement

AI can produce:

  • false positives
  • false negatives
  • incorrect reasoning
  • incomplete understanding of business requirements

Always validate important findings.

It is not full-repository semantic analysis

Cross-file awareness is intentionally compact.

It does not auto-fix

The current implementation does not:

  • edit source files
  • create fix commits
  • push fixes
  • auto-merge

It depends on external LLM providers

The selected provider requires the corresponding API access.

Exact line placement is not guaranteed

Model-generated locations may not always correspond perfectly to a GitHub commentable diff position.

The fallback comment path exists for this reason.


๐Ÿ—บ๏ธ Future Roadmap

The current architecture naturally supports several extensions.

๐Ÿ“ Suggested changes

Move from:

๐Ÿ’ฌ Finding

toward:

๐Ÿ’ฌ Finding
   +
๐Ÿงฉ Suggested patch
   +
๐Ÿ‘จโ€๐Ÿ’ป Human approval

A human should remain the acceptance gate.


๐Ÿง  Better repository context

Future context could combine:

PR diff
+
relevant symbols
+
dependency relationships
+
repository conventions
+
tests

without blindly sending the entire repository to the model.


๐Ÿงช Test-aware review

A future reviewer could compare:

Changed implementation
        +
Changed tests
        +
Existing tests

and identify changes that appear to lack corresponding test coverage.


โ™ป๏ธ Finding deduplication

Future versions could fingerprint findings using information such as:

file
+
line
+
finding type
+
commit

to avoid noisy repetition.



๐Ÿ”— Project Links

GitHub

https://github.com/Sahoo999/PR-Review-Agent

npm installer

npx @debangsu__/create-pr-review-agent

๐Ÿค– Review faster. ๐Ÿ’ฌ Comment where it matters. ๐Ÿ‘จโ€๐Ÿ’ป Keep humans in control.

Built around a simple idea: AI should shorten the feedback loop, not replace engineering judgment.

About

๐Ÿค– Automated AI code review for GitHub PRs โ€” analyze diffs with Claude/GPT and get actionable, line-level feedback directly in your pull requests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages