AI-powered code review tool with local Git, remote MR/PR analysis, and CI integration (GitLab, GitHub or Forgejo)
Project description
AI Code Review
AI-powered code review tool with 3 powerful use cases:
- ๐ค CI Integration - Automated reviews in your CI/CD pipeline (GitLab or GitHub)
- ๐ Local Reviews - Review your local changes before committing
- ๐ Remote Reviews - Analyze existing MRs/PRs from the terminal
๐ Table of Contents
- ๐ Primary Use Case: CI/CD Integration
- โ๏ธ Secondary Use Cases
- ๐ง Configuration
- โก Smart Skip Review
- For Developers
- ๐ง Common Issues
- ๐ Documentation
- ๐ค AI Tools Disclaimer
- ๐ License
- ๐ฅ Author
๐ Primary Use Case: CI/CD Integration
This is the primary and recommended way to use the AI Code Review tool.
GitLab CI
Add to .gitlab-ci.yml:
ai-review:
stage: code-review
image: registry.gitlab.com/redhat/edge/ci-cd/ai-code-review:latest
variables:
AI_API_KEY: $GEMINI_API_KEY # Set in CI/CD variables
script:
- ai-code-review --post
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
allow_failure: true
GitHub Actions
Add to .github/workflows/ai-review.yml:
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
ai-review:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
continue-on-error: true
permissions:
contents: read
pull-requests: write
container:
image: registry.gitlab.com/redhat/edge/ci-cd/ai-code-review:latest
steps:
- name: Run AI Review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: ai-code-review --pr-number ${{ github.event.pull_request.number }} --post
Forgejo Actions
Add to .forgejo/workflows/ai-review.yml:
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
ai-review:
runs-on: codeberg-tiny # adjust for non-codeberg instances
continue-on-error: true
permissions:
contents: read
pull-requests: write
container:
image: registry.gitlab.com/redhat/edge/ci-cd/ai-code-review:latest
steps:
- name: Run AI Review
env:
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }} # set in Forgejo Actions secrets
run: ai-code-review --pr-number ${{ github.event.pull_request.number }} --post
โ๏ธ Secondary Use Cases
Local Usage (Container)
This is the recommended way to use the tool locally, as it doesn't require any installation on your system.
# Review local changes
podman run -it --rm -v .:/app -w /app \
registry.gitlab.com/redhat/edge/ci-cd/ai-code-review:latest \
ai-code-review --local
# Review a remote MR
podman run -it --rm -e GITLAB_TOKEN=$GITLAB_TOKEN -e AI_API_KEY=$AI_API_KEY \
registry.gitlab.com/redhat/edge/ci-cd/ai-code-review:latest \
ai-code-review group/project 123
Note: You can use
dockerinstead ofpodmanand the command should work the same.
Local Usage (CLI Tool)
This is a good option if you have Python installed and want to use the tool as a CLI command.
Note on package vs. command name: The package is registered on PyPI as
ai-code-review-cli, but for ease of use, the command to execute remainsai-code-review.
pipx is a more mature and well-known tool for the same purpose. It handles the package vs. command name difference automatically.
# Install pipx
pip install pipx
pipx ensurepath
# Install the package
pipx install ai-code-review-cli
# Run the command
ai-code-review --local
Remote Reviews
You can also analyze existing MRs/PRs from your terminal.
# GitLab MR
ai-code-review group/project 123
# GitHub PR
ai-code-review --platform-provider github owner/repo 456
# Save to file
ai-code-review group/project 123 -o review.md
# Post the review to the MR/PR
ai-code-review group/project 123 --post
๐ง Configuration
Required Setup
1. Platform Token (Not needed for local reviews)
# For GitLab remote reviews
export GITLAB_TOKEN=glpat_xxxxxxxxxxxxxxxxxxxx
# For GitHub remote reviews
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx
# For Forgejo remote reviews
export FORGEJO_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Local reviews don't need platform tokens! ๐
2. AI API Key
# Get key from: https://makersuite.google.com/app/apikey
export AI_API_KEY=your_gemini_api_key_here
Configuration Methods (Priority Order)
The tool supports 4 configuration methods with the following priority:
- ๐ด CLI Arguments (highest priority) -
--ai-provider anthropic --ai-model claude-sonnet-4-5 - ๐ก Environment Variables -
export AI_PROVIDER=anthropic - ๐ข Configuration File -
.ai_review/config.yml - โช Field Defaults (lowest priority) - Built-in defaults
Configuration File
Create a YAML configuration file for persistent settings:
# Create from template
cp .ai_review/config.yml.example .ai_review/config.yml
# Edit your project settings
nano .ai_review/config.yml
Key benefits:
- โ Project-specific settings - Different configs per repository
- โ Team sharing - Commit to git for consistent team settings
- โ Reduced typing - Set common options once
- โ Layered override - CLI arguments still override everything
File locations:
- Auto-detected:
.ai_review/config.yml(loaded automatically if exists) - Custom path:
--config-file path/to/custom.yml - Disable loading:
--no-config-fileflag
Environment Variables
For sensitive data and CI/CD environments:
# Copy template
cp env.example .env
# Edit and set your tokens
GITLAB_TOKEN=glpat_xxxxxxxxxxxxxxxxxxxx
AI_API_KEY=your_gemini_api_key_here
Common Options
# Different AI providers
ai-code-review project/123 --ai-provider anthropic # Claude
ai-code-review project/123 --ai-provider ollama # Local Ollama
# Custom server URLs
ai-code-review project/123 --gitlab-url https://gitlab.company.com
# Output options
ai-code-review project/123 -o review.md # Save to file
ai-code-review project/123 2>logs.txt # Logs to stderr
For all configuration options, troubleshooting, and advanced usage โ see User Guide
Team/Organization Context
For teams working on multiple projects, you can specify a shared team context that applies organization-wide:
# Remote team context (recommended - stored in central repo)
export TEAM_CONTEXT_FILE=https://gitlab.com/org/standards/-/raw/main/review.md
ai-code-review --local
# Or use CLI option
ai-code-review project/123 --team-context-file https://company.com/standards/review.md --post
# Local team context file
ai-code-review --team-context-file ../team-standards.md --local
Use cases:
- Organization-wide coding standards
- Security requirements and compliance rules
- Team conventions shared across projects
- Industry-specific guidelines (HIPAA, GDPR, etc.)
Priority order: Team context โ Project context โ Commit history
This allows maintaining org standards while individual projects add specific guidelines.
See User Guide - Team Context for complete documentation.
Intelligent Review Context (Two-Phase Synthesis)
The tool uses a two-phase approach to incorporate previous reviews and avoid repeating mistakes:
Phase 1 - Synthesis (automatic):
- Fetches ALL comments and reviews (including resolved ones)
- Uses a fast model (e.g.,
gemini-3-flash-preview) to synthesize key insights - Identifies author corrections to previous AI reviews
- Generates concise summary (<500 words)
Phase 2 - Main Review:
- Uses synthesis as context to avoid repeating mistakes
- Focuses on code changes with awareness of discussions
Benefits:
- โ Prevents repeating invalidated suggestions
- โ Reduces token usage (synthesis is much shorter than raw comments)
- โ Lower costs (fast model for preprocessing)
- โ Better quality (focused insights vs raw data)
Configuration:
# Enable/disable (default: enabled)
enable_review_context: true
enable_review_synthesis: true
# Custom synthesis model (optional)
synthesis_model: "gemini-3-flash-preview" # Default for Gemini
# synthesis_model: "claude-haiku-4-5" # For Anthropic
# synthesis_model: "gpt-4o-mini" # For OpenAI
Skips automatically when:
- No comments/reviews exist (first review)
- Feature is disabled
โก Smart Skip Review
AI Code Review automatically skips unnecessary reviews to reduce noise and costs:
- ๐ Dependency updates (
chore(deps): bump lodash 4.1.0 to 4.2.0) - ๐ค Bot changes (from
dependabot[bot],renovate[bot]) - ๐ Documentation-only changes (if enabled)
- ๐ท๏ธ Tagged PRs/MRs (
[skip review],[automated]) - ๐ Draft/WIP PRs/MRs (work in progress)
Result: Focus on meaningful changes, save API costs, faster CI/CD pipelines.
๐ Learn more: Configuration, customization, and CI integration โ User Guide - Skip Review
For Developers
Development Setup
# Install using uv (recommended)
uv sync --all-extras
# Or with pip
pip install -e .
To install or learn more about
uv, check here: uv
๐ง Common Issues
gRPC Warnings with Google Gemini (only for ai-generate-context)
When using Google Gemini provider, you may see harmless gRPC connection warnings:
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1759934851.372144 Other threads are currently calling into gRPC, skipping fork() handlers
These warnings are harmless and don't affect functionality. To suppress them:
# Suppress warnings by redirecting stderr
ai-generate-context . 2>/dev/null
# Or use alternative provider (no warnings)
ai-generate-context . --provider ollama
๐ Documentation
- User Guide - Complete usage, configuration, and troubleshooting
- Context Generator Guide - AI context generation for better reviews (requires Git repository)
- Context7 Integration Guide - Enhanced reviews with official library documentation (optional)
- Developer Guide - Development setup, architecture, and contributing
๐ค AI Tools Disclaimer
This project was developed with the assistance of artificial intelligence tools
Tools used:
- Cursor: Code editor with AI capabilities
- Claude-Sonnet-4.5: Anthropic's latest language model (claude-sonnet-4-5)
Division of responsibilities:
AI (Cursor + Claude-Sonnet-4.5):
- ๐ง Initial code prototyping
- ๐ Generation of examples and test cases
- ๐ Assistance in debugging and error resolution
- ๐ Documentation and comments writing
- ๐ก Technical implementation suggestions
Human (Juanje Ojeda):
- ๐ฏ Specification of objectives and requirements
- ๐ Critical review of code and documentation
- ๐ฌ Iterative feedback and solution refinement
- โ Final validation of concepts and approaches
Crotchety old human (Adam Williamson):
- ๐ด๐ป Adapted GitHub client and tests for Forgejo using 100% artisanal human brainpower
Collaboration philosophy: AI tools served as a highly capable technical assistant, while all design decisions, educational objectives, and project directions were defined and validated by the human.
๐ License
MIT License - see LICENSE file for details.
๐ฅ Author
- Author: Juanje Ojeda
- Email: juanje@redhat.com
- URL: https://gitlab.com/redhat/edge/ci-cd/ai-code-review
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_code_review_cli-2.2.0.tar.gz.
File metadata
- Download URL: ai_code_review_cli-2.2.0.tar.gz
- Upload date:
- Size: 116.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10ce0b91c089029183a619c5a3a2a794d667e78c4464882e9b589184cadb2509
|
|
| MD5 |
815878d44e4869b6ca3b6f12d375da82
|
|
| BLAKE2b-256 |
57be1fceb16d9a47125a89cb1bdc569a684950a5145b2ff99ca14f9b86120d2d
|
File details
Details for the file ai_code_review_cli-2.2.0-py3-none-any.whl.
File metadata
- Download URL: ai_code_review_cli-2.2.0-py3-none-any.whl
- Upload date:
- Size: 149.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc59261c520e9e62419521d7243a80f7be75a6d073b36529108dd536f7969c20
|
|
| MD5 |
48c289d0553f25c71b0b83c4c47af33a
|
|
| BLAKE2b-256 |
0280f11ca09ef67a1547af742abf677ed0be04b92121bfd92c69df5134d773e9
|