Skip to main content

AI-powered code review tool with local Git, remote MR/PR analysis, and CI integration (GitLab or GitHub)

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

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
    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

โš™๏ธ 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 --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 group/project 123

Note: You can use docker instead of podman and 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 remains ai-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 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

# 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:

  1. ๐Ÿ”ด CLI Arguments (highest priority) - --provider anthropic --model claude-sonnet-4-20250514
  2. ๐ŸŸก Environment Variables - export AI_PROVIDER=anthropic
  3. ๐ŸŸข Configuration File - .ai_review/config.yml
  4. โšช 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-file flag

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 --provider anthropic  # Claude
ai-code-review project/123 --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

โšก 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

# Or with pip
pip install -e .

To install or learn more about uv, check here: uv

๐Ÿ”ง Common Issues

gRPC Warnings with Google Gemini

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-code-review --local 2>/dev/null
ai-generate-context . 2>/dev/null

# Or use alternative provider (no warnings)
ai-code-review --local --provider ollama

๐Ÿ“– Documentation

๐Ÿค– 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: Anthropic's language model (claude-sonnet-4-20250514)

Division of responsibilities:

AI (Cursor + Claude-Sonnet-4):

  • ๐Ÿ”ง 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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_code_review_cli-1.14.1.tar.gz (382.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_code_review_cli-1.14.1-py3-none-any.whl (119.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_code_review_cli-1.14.1.tar.gz.

File metadata

  • Download URL: ai_code_review_cli-1.14.1.tar.gz
  • Upload date:
  • Size: 382.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ai_code_review_cli-1.14.1.tar.gz
Algorithm Hash digest
SHA256 f1a4df6bbfca3ed46b255c8f8868dab05f311e3cf664be172b1dac50808a1fbd
MD5 af49eea4533174d389c3da4205d3732b
BLAKE2b-256 6a1a39c5f254a9925cc5b7e6d80079e990939c3b5118ae14146cd4c98299e9f9

See more details on using hashes here.

File details

Details for the file ai_code_review_cli-1.14.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_code_review_cli-1.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 abe6d9bad6882805d80758f6b4a8356f7f7feef669d7d3456d66eafd392ea0a2
MD5 e031a6d52860a6cfb5710cea06063c51
BLAKE2b-256 ef94555e3a30c3276ff868c396393ea3ad59d8d548aad5200617d954be4e0e08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page