Skip to content

ramonpaolo/ai-codereviewer

 
 

Repository files navigation

AI Code Reviewer

AI Code Reviewer is a GitHub Action that leverages multiple AI providers (OpenAI, Anthropic, Google) to provide intelligent feedback and suggestions on your pull requests. This powerful tool helps improve code quality and saves developers time by automating the code review process.

Features

  • Supports multiple AI providers:
    • OpenAI (ChatGPT)
    • Anthropic (Claude)
    • Google (Gemini)
    • Custom (any OpenAI/Anthropic-compatible API - Ollama, Llama.cpp, MiniMax, GLM, LM Studio, vLLM, etc.)
  • Provides intelligent comments and suggestions for improving your code
  • Reviews only new changes in PR updates
  • Filters out files that match specified exclude patterns
  • Easy to set up and integrate into your GitHub workflow

Setup

  1. Choose your preferred AI provider and get an API key:

  2. Add the API key as a GitHub Secret in your repository:

    • OPENAI_API_KEY for OpenAI
    • ANTHROPIC_API_KEY for Claude
    • GOOGLE_AI_KEY for Google Gemini
    • AI_API_KEY for Custom AI(Ollama, Llama.cpp, MiniMax, GLM, LM Studio, vLLM, etc.) - This parameter can be empty
  3. Create .github/workflows/code-review.yml:

name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize]
permissions: write-all

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: AI Code Review
        uses: your-username/ai-code-reviewer@main # Example: ramonpaolo/ai-code-reviewer@main
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needs the permission to write comment, read code and approve PR
          
          # Choose your AI provider and key
          AI_PROVIDER: "openai" # or "anthropic" or "google" or "custom"
          AI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          AI_MODEL: "gpt-4o-mini" # or "minimax-m2.1" or "Qwen3-Coder-480B-A35B-Instruct"
          AI_TEMPERATURE: 0.3 # 0 to 1 - higher values = more creativity and variance; Obs: not affect some models and providers

          # Optional configurations
          APPROVE_REVIEWS: true
          MAX_COMMENTS: 10 # 0 to disable
          PROJECT_CONTEXT: "This is a Node.js TypeScript project"
          CONTEXT_FILES: "package.json,README.md"
          EXCLUDE_PATTERNS: "**/*.lock,**/*.json,**/*.md"

Configuration

Input Description Default
AI_PROVIDER AI provider to use (openai, anthropic, google, custom) openai
AI_API_KEY API key for chosen provider (optional for local/custom providers) Required
AI_BASE_URL Custom API base URL (required for custom providers - must include the full endpoint path like /v1 or /v1/text/chatcompletion_v2) ""
AI_MODEL Model to use (see supported models below) Provider's default
AI_TEMPERATURE Temperature for AI model 0
APPROVE_REVIEWS Whether to approve PRs automatically true
MAX_COMMENTS Maximum number of review comments 0
PROJECT_CONTEXT Project context for better reviews ""
CONTEXT_FILES Files to include in review (comma-separated) "package.json,README.md"
EXCLUDE_PATTERNS Files to exclude (glob patterns, comma-separated) "**/*.lock,**/*.json,**/*.md"

Supported Models

All models supported by the provider should be supported.

Using Custom Providers (Ollama, LM Studio, MiniMax, vLLM, etc.)

When using the custom provider, you must provide the complete URL to the API endpoint, including the full path (e.g., /api/chat, /v1/text/chatcompletion_v2, etc.):

# Example with Ollama (local)
- name: AI Code Review (Ollama)
  uses: your-username/ai-code-reviewer@main
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    AI_PROVIDER: "custom"
    AI_BASE_URL: "http://some-ollama-url:11434/api/chat"
    AI_MODEL: "llama3.2"
    AI_API_KEY: "" # Not needed for Ollama

# Example with MiniMax
- name: AI Code Review (MiniMax)
  uses: your-username/ai-code-reviewer@main
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    AI_PROVIDER: "custom"
    AI_BASE_URL: "https://api.minimax.io/v1/text/chatcompletion_v2"
    AI_MODEL: "minimax-m2.1"
    AI_API_KEY: "your-minimax-api-key"

Important: For custom providers, AI_BASE_URL must include the complete endpoint path, not just the base domain.

Development

Create a .env file with your credentials:

GITHUB_TOKEN=your_github_token
AI_PROVIDER=openai  # or anthropic, google, custom
AI_API_KEY=your_api_key
AI_MODEL=your_preferred_model
AI_BASE_URL=url_api
# Install dependencies
yarn install

# Build TypeScript files
yarn build

# Run unit tests
yarn test

# Package for distribution
yarn package

# Generate test PR payload (for e2e testing)
yarn generate-pr-payload <owner> <repo> <pr_number>

# Run end-to-end tests
yarn test:e2e <owner> <repo> <pr_number>

Testing Locally

To test the action locally:

  1. Create a .env file with your credentials:
GITHUB_TOKEN=your_github_token
AI_PROVIDER=openai  # or anthropic, google, custom
AI_API_KEY=your_api_key
AI_MODEL=your_preferred_model
AI_BASE_URL=url_api
  1. Generate a test PR payload:
yarn generate-pr-payload <owner> <repo> 123
  1. Run the e2e test:
yarn test:e2e <owner> <repo> 123

Note: Make sure you have write access to the repository you're testing with.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT License - see LICENSE for details.

About

Advanced AI-powered code reviews with multiple model support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 89.2%
  • JavaScript 10.8%