Skip to content

drew2a/ai-review

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Build and Test MIT License

AI Code Review Action

A GitHub Action that provides automated code review using AI to analyze pull request changes.

Features

  • Automatically reviews pull request changes using AI
  • Provides detailed code suggestions and improvements
  • Adds review comments directly to the PR
  • Works with any programming language
  • Supports different AI models and API endpoints
  • Optional review resolution statuses (e.g., "APPROVE", "REQUEST_CHANGES", "COMMENT")
  • Debug mode for enhanced logging

Supported models

This action uses LiteLLM, so it supports 100+ LLMs including:

  • OpenAI (GPT-4o, o1, etc.)
  • Anthropic (Claude 3.5 Sonnet, Claude 3.7 Sonnet, etc.)
  • Google VertexAI / Gemini (Gemini 1.5 Pro, Gemini 2.0 Flash, etc.)
  • Azure OpenAI
  • HuggingFace
  • Ollama
  • ... and many more.

See the LiteLLM Providers documentation for the full list of supported models and the required environment variables for each provider.

My (Subjective) Review of the Particular Models

I’ll grade them on a scale from 0 to 10, where:

  • 0 → Completely irrelevant comments
  • 3 → My fresh junior/mid-level colleague
  • 5 → My mid-level colleague who reads Stack Overflow
  • 8 → Me
  • 10 → My very smart colleague

So, based on this (highly unscientific) scale:

  • gpt-4o2
  • o13
  • claude-3-5-sonnet5
  • claude-3-7-sonnet6
  • gemini-2.0-flash2
  • gemini-2.5-pro3

Inputs

Name Description Required Default
github_token GitHub token for authentication true -
debug Enable debug mode (true/false) false false
add_review_resolution Add review resolution (APPROVE, REQUEST_CHANGES, COMMENT) false false
add_joke Add a joke to the review comment false false
author_customization YAML configuration for customizing reviews based on PR author false -

Environment Variables

The action relies on environment variables for LLM configuration, handled by litellm.

Name Description Required
LLM_MODEL The model name to use (e.g. gpt-4o, claude-3-5-sonnet, gemini/gemini-1.5-pro) Yes
OPENAI_API_KEY API Key for OpenAI (if using OpenAI models) Conditional
ANTHROPIC_API_KEY API Key for Anthropic (if using Claude models) Conditional
GEMINI_API_KEY API Key for Google Gemini (if using Gemini models) Conditional
OPENAI_API_BASE Custom API endpoint (if needed) Optional

Note: Check the LiteLLM documentation for the specific environment variables required for your chosen provider.

Usage

To use this action in your GitHub workflow, add the following step:

- uses: drew2a/ai-review@v1
  env:
    LLM_MODEL: gpt-4o
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    debug: false
    add_review_resolution: false
    add_joke: false
    author_customization: |
      torvalds: "This is an experienced developer. Focus on architecture and design patterns."
      defunkt: "This is a junior developer. Provide educational feedback and explanations."

Example Workflow

name: AI Code Review

on: [ pull_request ]

permissions:
  pull-requests: write

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

      - uses: drew2a/ai-review@v1
        env:
          LLM_MODEL: ${{ secrets.LLM_MODEL }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          # Add other env vars required by litellm for your specific provider
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          debug: true
          add_review_resolution: false
          add_joke: false

Author Customization

The author_customization parameter allows you to customize the review behavior based on the PR author's GitHub username. This is useful for providing different types of feedback for team members with different experience levels or roles.

Configuration Format

The customization is provided as YAML using actual GitHub usernames:

torvalds: "Custom review guidance for this user"
defunkt: "Different guidance for another user"

Example Configuration

Here's an example for a team with users who get customized behavior:

author_customization: |
  torvalds: "Use a more friendly manner since they're beginners. Give more examples and explanations to help them learn."
  defunkt: "Use a super formal tone and provide low-level grounding. Focus on technical precision and detailed analysis."

Role-Based Example

You can also organize by roles using GitHub usernames:

author_customization: |
  torvalds: "Focus on architectural decisions and design patterns. This developer prefers concise, high-level feedback."
  defunkt: "Provide educational explanations and learning opportunities. Focus on best practices and code quality fundamentals."
  octocat: "Be welcoming and provide clear explanations. Focus on project conventions and coding standards."

Usage in Workflow

- uses: drew2a/ai-review@v1
  with:
    # ... other parameters ...
    author_customization: |
      torvalds: "Focus on performance and security concerns"
      defunkt: "Educational feedback welcomed"

License

Released under the MIT License.

About

A GitHub Action that provides automated code review using AI to analyze pull request changes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •