Skip to content

CHashtager/patchlens

Repository files navigation

Patchlens

Patchlens is a command-line reviewer for GitLab merge requests and GitHub pull requests. It fetches a change request diff, sends the patch to a configured LLM, and prints a structured review locally or posts a summary plus inline comments back to the MR/PR.

The project is intentionally small: one Go binary, no runtime service, and a user-level JSON config file.

Features

  • Review GitLab merge requests and GitHub pull requests from flags or a URL.
  • Post review summaries and inline comments back to GitLab or GitHub.
  • Use OpenAI, Anthropic, Ollama, or a custom OpenAI-compatible chat endpoint.
  • Choose focused review modes: syntax, logic, business, or comprehensive.
  • Add repository-specific business context from a local file.
  • Print human-readable output or machine-readable JSON.
  • Infer repository paths from git remote get-url origin when possible.

Status

Patchlens is early-stage software. It is useful today, but APIs, prompts, defaults, and output schemas may change before a stable release. Treat posted comments as assistant-generated review suggestions and keep a human reviewer in the loop.

Requirements

  • Go 1.24 or newer.
  • A GitLab or GitHub token with access to the target repository.
  • One LLM backend:
    • OpenAI-compatible chat completions endpoint.
    • Anthropic Messages API.
    • Ollama running locally.
    • A custom endpoint compatible with Patchlens' OpenAI-style request flow.

Installation

Build from source:

git clone https://github.com/CHashtager/patchlens.git
cd patchlens
make build

The binary is written to bin/patchlens.

You can also install with Go:

go install github.com/CHashtager/patchlens/cmd/patchlens@latest

For local development builds:

go build -o patchlens ./cmd/patchlens

Quick Start

Configure Patchlens once:

patchlens configure \
  --provider github \
  --github-token YOUR_GITHUB_TOKEN \
  --llm-provider openai \
  --llm-api-key YOUR_LLM_API_KEY \
  --llm-model gpt-4

Review a GitHub pull request without posting:

patchlens review --repo owner/repo --pr 123

Review a GitLab merge request without posting:

patchlens review --provider gitlab --project group/project --mr 123

Review from a URL and post the result:

patchlens review --url https://github.com/owner/repo/pull/123 --post
patchlens review --url https://gitlab.com/group/project/-/merge_requests/123 --post

Commands

patchlens configure

Stores user-level settings in your operating system config directory.

Common flags:

--provider gitlab|github
--gitlab-url https://gitlab.com
--gitlab-token TOKEN
--github-api-url https://api.github.com
--github-token TOKEN
--llm-provider openai|anthropic|ollama|custom
--llm-api-url URL
--llm-api-key TOKEN
--llm-model MODEL
--llm-reasoning-effort default|low|medium|high
--review-mode syntax|logic|business|comprehensive
--business-context-file PATH

If no flags are provided and stdin is interactive, Patchlens prompts for values.

patchlens config

Show the redacted config:

patchlens config show

Print the config path:

patchlens config path

patchlens review

Fetches a change request, asks the configured LLM to review the diff, and prints or posts the result.

Common flags:

--provider gitlab|github
--project group/project
--mr 123
--repo owner/repo
--pr 123
--url https://github.com/owner/repo/pull/123
--mode syntax|logic|business|comprehensive
--context path/to/context.md
--cwd /path/to/repo
--post
--json

Examples:

patchlens review --provider github --repo owner/repo --pr 123 --mode logic
patchlens review --provider gitlab --project group/project --mr 123 --json
patchlens review --url https://gitlab.example.com/team/app/-/merge_requests/42 --post

Review Modes

  • syntax: style, formatting, naming, imports, typos, and syntax issues.
  • logic: correctness, edge cases, error handling, algorithm behavior, and races.
  • business: domain correctness, requirement alignment, and validation.
  • comprehensive: syntax, logic, performance, security, maintainability, and tests.

The default mode is comprehensive.

Business Context

Patchlens can include a local context file in business and comprehensive reviews. By default it looks for:

.gitlab-ai-context.md

You can configure another default:

patchlens configure --business-context-file docs/review-context.md

Or override it per review:

patchlens review --repo owner/repo --pr 123 --context docs/review-context.md

Good context files are short and practical: product rules, domain terms, important invariants, security constraints, and known review preferences.

Configuration

Patchlens stores config at:

  • macOS: ~/Library/Application Support/patchlens/config.json
  • Linux: ~/.config/patchlens/config.json
  • Windows: %AppData%\patchlens\config.json

Example:

{
  "provider": "github",
  "gitlab": {
    "url": "https://gitlab.com",
    "token": "glpat_xxx"
  },
  "github": {
    "apiUrl": "https://api.github.com",
    "token": "github_pat_xxx"
  },
  "llm": {
    "provider": "openai",
    "apiUrl": "",
    "apiKey": "sk_xxx",
    "model": "gpt-4",
    "reasoningEffort": "default"
  },
  "review": {
    "mode": "comprehensive",
    "businessContextFile": ".gitlab-ai-context.md"
  }
}

Config files are written with user-only permissions where supported by the operating system. Do not commit real tokens.

Token Permissions

Use the least-privileged token that supports your workflow.

For GitLab, a personal access token with API access is required for fetching MRs and posting comments.

For GitHub, a classic token usually needs repository access for private repositories. A fine-grained token should have access to the target repository and enough pull request, issue, and contents permissions to read changed files and write comments when --post is used.

Patchlens sends diffs and optional business context to the configured LLM provider. Review your provider's data policy before using Patchlens on private code.

LLM Providers

OpenAI:

patchlens configure \
  --llm-provider openai \
  --llm-api-key YOUR_KEY \
  --llm-model gpt-4

Anthropic:

patchlens configure \
  --llm-provider anthropic \
  --llm-api-key YOUR_KEY \
  --llm-model YOUR_ANTHROPIC_MODEL

Ollama:

ollama serve
ollama pull llama3.1
patchlens configure \
  --llm-provider ollama \
  --llm-model llama3.1

Custom OpenAI-compatible endpoint:

patchlens configure \
  --llm-provider custom \
  --llm-api-url https://llm.example.com/v1 \
  --llm-api-key YOUR_KEY \
  --llm-model your-model

Development

Useful commands:

make help
make build
make test
make fmt
make vet
make check
make run ARGS="config show"

Project layout:

cmd/patchlens/       CLI entry point and command parsing
internal/config/     User config loading, defaults, validation, redaction
internal/llm/        LLM provider clients
internal/review/     Review prompt, result parsing, printing, comment formatting
internal/scm/        GitLab and GitHub API clients

Open Source

Roadmap

Ideas that fit the current project direction:

  • Tests for URL parsing, config validation, review parsing, and provider clients.
  • Better diff position mapping for inline comments.
  • Dry-run output for comments that would be posted.
  • Configurable output templates.
  • CI release builds for common platforms.
  • More precise provider documentation and examples.

License

Patchlens is released under the MIT License. See LICENSE.

About

MR/PR AI Reviewer

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors