Skip to content

About

A file-based code reviewer tool that is triggered when a pull request is created.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enzo.Helpers.CodeReviewer

Overview

Enzo.Helpers.CodeReviewer is a lightweight AI-assisted code reviewer implemented as a .NET 10 file-based C# application.

It reviews pull request diffs using external review skills and OpenAI, validates inline comment locations against the actual diff, prints a structured review report to stdout, and posts an advisory GitHub Pull Request Review using the Enzo Code Reviewer GitHub App identity. In GitHub, actionable findings are published directly as inline review comments on changed code. When Enzo can safely propose an exact localized fix, inline comments use GitHub's native commit-able suggestion Markdown.

Architecture

Consuming repository
        |
        | OPENAI_API_KEY
        | Enzo Code Reviewer GitHub App ID
        | Enzo Code Reviewer GitHub App private key
        v
Reusable GitHub Actions workflow
        |
        | creates installation token
        v
Code Reviewer
        |
        | sends PR diff and review skills
        v
OpenAI
        |
        | returns structured findings, remediation, and advice
        v
GitHub Pull Request Review summary plus valid inline issue comments or commit-able suggestions

The GitHub review is always submitted with the COMMENT event. It does not approve PRs, request changes, or block merges.

OpenAI performs the review analysis. Enzo.Ai.Skills provides external review guidance. The Enzo Code Reviewer GitHub App provides the GitHub identity used to publish PR reviews.

The reviewer intentionally separates issues from advice:

Issues
-> actionable problems worth fixing

Advice
-> useful non-blocking recommendations

Every successful GitHub Actions review publishes one Enzo Code Reviewer PR review. The overall body stays compact and contains review-level information such as statistics and Advice. Detailed findings are not duplicated in the overall body; each valid finding appears inline against the changed code. Some inline comments include GitHub native commit-able suggestions. Advice is included only in the overall report and is not posted inline.

Enzo.Ai.Skills

Review instructions are maintained separately in the public Enzo.Ai.Skills repository.

The reviewer is not coupled to how that repository is obtained. It only receives a filesystem path and recursively discovers files named SKILL.md.

Expected convention:

Enzo.Ai.Skills/
├── dotnet-backend/
│   └── SKILL.md
├── dotnet-testing/
│   └── SKILL.md
└── ef-core/
    └── SKILL.md

Those skill names are examples only. Nested directories are supported, and all discovered SKILL.md files are loaded.

Local Setup

Recommended local workspace:

workspace/
├── Enzo.Helpers.CodeReviewer/
└── Enzo.Ai.Skills/

Requirements:

  • .NET 10 SDK with C# file-based app support
  • A unified diff file to review
  • External skills containing at least one SKILL.md
  • An OpenAI API key provided through OPENAI_API_KEY

OpenAI Configuration

For review analysis, the reviewer reads OpenAI credentials from OPENAI_API_KEY.

PowerShell:

$env:OPENAI_API_KEY="<your-api-key>"

Bash:

export OPENAI_API_KEY="<your-api-key>"

Do not store API keys in repository files.

Local Usage

Run from the Enzo.Helpers.CodeReviewer directory:

dotnet reviewer.cs changes.diff --skills ../Enzo.Ai.Skills

changes.diff is an existing unified diff file, such as output from git diff.

--skills points to the external skills directory that contains SKILL.md files.

Local review generation does not require GitHub App credentials. If GitHub publishing context is unavailable, the reviewer prints detailed findings to stdout and skips GitHub publishing. This keeps local execution useful even though GitHub PR presentation is inline-only.

Example GitHub review body:

# 🤖 Enzo Code Reviewer

Found **1 actionable issue**. See the inline review comments for details.

## 📊 Statistics

**Added lines:** 80  
**Issues found:** 1  
**Issue density:** 1.3 findings per 100 added lines

- 🔴 High: 1
- 🟡 Medium: 0
- 🔵 Low: 0

Detailed issue descriptions, locations, actions, code suggestions, Conventional Commit recommendations, and coding-agent prompts are intentionally absent from the overall GitHub review body. They appear only in inline comments attached to the relevant changed code.

Severity is represented as 🔴 HIGH, 🟡 MEDIUM, and 🔵 LOW. The former Mermaid severity pie chart has been removed and no replacement chart is generated.

Remediation Modes

Every issue has a coding-agent prompt available as a fallback. When the fix is safe, exact, localized, and maps to changed lines in the PR diff, Enzo may also provide a GitHub native code suggestion.

Use a commit-able suggestion when Enzo can confidently provide the exact replacement for one changed line or a small contiguous changed range. Typical examples are null guards, incorrect conditions, wrong API calls, small async corrections, missing cancellation-token propagation, simple disposal fixes, straightforward validation, and small localized EF Core corrections.

Inline GitHub comments with a valid suggestion look like this:

🔴 **Possible null dereference**

`request.Name` can be accessed when `request` is null.

**Action**

Handle the null case before accessing `Name`.

```suggestion
if (request is null)
{
    throw new ArgumentNullException(nameof(request));
}

return request.Name;
```

**Suggested commit:** `fix: handle null request before accessing name`

GitHub exposes its native Commit suggestion experience for comments that contain a valid suggestion block on a pull request diff line or range. GitHub asks the person applying the suggestion to provide the commit message; Enzo cannot set that message through the review comment. Enzo therefore renders a recommended Conventional Commit message immediately below the suggestion.

Use the coding-agent prompt when an exact localized replacement would be unsafe or insufficient, including architectural changes, concurrency redesign, transaction-boundary issues, multi-file fixes, complex security changes, substantial refactoring, ambiguous implementation choices, or issues requiring broader repository context.

Fallback inline comments look like this:

🟡 **Concurrent DbContext usage**

The same scoped DbContext is currently used by concurrent operations.

**Action**

Change the implementation so operations sharing the context are not executed concurrently.

### 🤖 Use this prompt with your coding agent

> Fix the DbContext concurrency issue in `TransactionRepository.cs` around line 74. The same scoped DbContext is currently used by concurrent operations. Change the implementation so operations sharing the context are not executed concurrently. Preserve existing behavior and avoid unrelated refactoring. Add focused tests for the affected execution path and run the existing tests.

Enzo never automatically commits, pushes, merges, approves, or requests changes. Suggestions and commit messages are recommendations for the developer to inspect and apply.

The Statistics section is calculated by the application, not by the model. Added lines are counted from the unified diff across files and hunks while excluding diff headers, +++ lines, deleted lines, and metadata. Issue totals, severity counts, and density are based on successfully published inline findings after location validation.

Issue density means:

findings / added lines * 100

It is displayed as findings per 100 added lines. It is not an estimate of what percentage of the code is defective. If there are zero added lines, issue density is displayed as N/A.

If there are no issues but useful advice exists:

# 🤖 Enzo Code Reviewer

## 💡 Advice

- Using AsNoTracking() here would avoid unnecessary EF Core tracking because this query is read-only.

If there are no issues and no useful advice:

# 🤖 Enzo Code Reviewer

## ✨ Good job!

No actionable issues or specific recommendations found. 🚀

Findings are validated against changes.diff before creating inline comments. A finding must map to a changed new/right-side line in the PR diff. Suggestion ranges are also validated against contiguous changed new/right-side lines before Enzo publishes a suggestion block.

If a model-provided finding location is invalid or stale, Enzo skips that finding for GitHub publication and logs a concise warning instead of guessing a nearby line or moving the issue into the overall body. If the finding location is valid but the code suggestion range is not safe, Enzo keeps the inline comment and falls back to the coding-agent prompt.

GitHub Actions

Enzo.Helpers.CodeReviewer is intended to run as a reusable GitHub Actions workflow. Consuming repositories decide when to call it.

Recommended caller workflow:

name: Enzo Code Review

on:
  pull_request:
    types:
      - opened

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    uses: solakpetri/Enzo.Helpers.CodeReviewer/.github/workflows/review.yml@main
    with:
      ENZO_CODE_REVIEWER_APP_ID: ${{ vars.ENZO_CODE_REVIEWER_APP_ID }}
    secrets:
      OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
      ENZO_CODE_REVIEWER_PRIVATE_KEY: ${{ secrets.ENZO_CODE_REVIEWER_PRIVATE_KEY }}

Automatic review is recommended only for pull_request: opened:

PR created
    -> review automatically runs once

additional commit pushed
    -> nothing

user wants another review
    -> GitHub Actions -> Re-run jobs

The reusable workflow:

checks out source
-> checks out skills
-> generates diff
-> creates an Enzo Code Reviewer GitHub App installation token
-> runs reviewer
-> prints the Enzo Code Reviewer report
-> posts one COMMENT pull request review as the Enzo Code Reviewer GitHub App
-> includes compact overall statistics and Advice in the review body
-> includes every valid finding as an inline issue comment or commit-able suggestion in the same review

It uses GitHub-hosted ubuntu-latest, sets up .NET 10, checks out Enzo.Ai.Skills with actions/checkout, generates the PR diff, and runs:

dotnet reviewer/reviewer.cs changes.diff --skills skills

The diff is generated from the pull request base SHA to the pull request head SHA, so the reviewer receives only PR changes. The generated diff file is not committed. The reviewer parses this unified diff to count added lines for statistics and determine valid new/right-side inline comment targets. Findings that cannot be safely mapped to those targets are skipped for GitHub publication, and statistics represent only the findings that were published inline.

The reusable workflow grants only the permissions needed to read repository contents and write pull request reviews:

permissions:
  contents: read
  pull-requests: write

Consuming repositories should grant the same permissions to the caller workflow. The Enzo Code Reviewer GitHub App installation must also have repository contents read access and pull request write access for the target repository.

Reusable Workflow Contract

The reusable workflow accepts one non-secret input:

ENZO_CODE_REVIEWER_APP_ID

Store the App ID as a repository or organization variable, for example vars.ENZO_CODE_REVIEWER_APP_ID.

The reusable workflow explicitly accepts these secrets:

OPENAI_API_KEY
ENZO_CODE_REVIEWER_PRIVATE_KEY

Do not use secrets: inherit. Pass only the required secrets explicitly.

The GitHub App private key must be stored as a GitHub Actions secret and must never be committed. Consuming repositories provide their own OPENAI_API_KEY.

Authentication

The workflow creates a short-lived installation token with actions/create-github-app-token@v2 using:

ENZO_CODE_REVIEWER_APP_ID
ENZO_CODE_REVIEWER_PRIVATE_KEY

The private key is provided only to the token-generation step. The generated installation token is passed to the reviewer as GITHUB_TOKEN:

GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

The reviewer does not understand GitHub App authentication. It only uses GITHUB_TOKEN to publish the GitHub Pull Request Review request.

The OpenAI API key is passed to the reviewer unchanged:

OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Do not commit API keys, private keys, installation tokens, .env files containing credentials, or credential-containing application settings. PR reviews appear under the Enzo Code Reviewer GitHub App identity.

Current Limitations

The current version:

  • reviews PR diffs
  • loads external skills
  • runs through a reusable GitHub Actions workflow
  • prints the structured Enzo Code Reviewer report to workflow logs
  • posts a GitHub Pull Request Review using COMMENT as the Enzo Code Reviewer GitHub App
  • keeps detailed GitHub findings inline-only against valid changed-line locations
  • includes GitHub native commit-able suggestions when an exact localized replacement is safe and maps to the PR diff
  • recommends Conventional Commit messages with applicable inline suggestions
  • falls back to directly usable coding-agent prompts inline when suggestions are unsafe
  • skips unmappable findings instead of attaching them to unrelated code or repeating them in the review body
  • publishes advice-only and Good Job fallback reports when there are no issues
  • never approves PRs or requests changes

Current limitations:

  • manage duplicate reviews

Roadmap

Duplicate-review handling is planned for a later version. Manually re-running the workflow can create duplicate inline comments.

About

A file-based code reviewer tool that is triggered when a pull request is created.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages