Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

AI Code Review

Reusable GitHub Actions workflow for AI-powered code review with auto-merge support.

Features

  • Multi-AI provider support (Gemini, OpenAI, Claude)
  • Multi-language project support (any codebase)
  • Security vulnerability scanning with Trivy
  • Configurable approval threshold
  • Auto-merge for approved PRs
  • Smart diff handling (auto-approve docs-only changes)
  • Multi-language review output (Chinese/English)
  • Detailed review comments on PR

Quick Start

1. Add Secret

In your repository, go to Settings > Secrets and variables > Actions and add:

  • GEMINI_API_KEY: Your Google Gemini API key (or OPENAI_API_KEY / ANTHROPIC_API_KEY)

2. Create Workflow

Create .github/workflows/code-review.yml in your repository:

name: Code Reviewon:
pull_request:
branches: [main]jobs:
review:
uses: your-org/CodeReview/.github/workflows/ai-code-review.yml@mainsecrets:
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }}

That's it! PRs to main will now be automatically reviewed.

Configuration

All inputs are optional:

InputDescriptionDefault
ai-providerAI provider (gemini, openai, claude)gemini
ai-modelAI model name (empty for default)``
min-scoreMinimum score for approval (0-10)7
max-filesMax files for auto-merge20
max-linesMax lines for auto-merge500
auto-mergeEnable auto-mergetrue
merge-methodMerge method (merge/squash/rebase)squash
languageReview language (zh/en)zh
run-security-scanRun Trivy security scantrue
exclude-patternsFiles to exclude from review*.md,*.txt,*.json,*.lock,*.yaml,*.yml
custom-promptAdditional review instructions``

Default Models

ProviderDefault Model
geminigemini-2.0-flash
openaigpt-4o
claudeclaude-sonnet-4-20250514

Full Example

name: Code Reviewon:
pull_request:
branches: [main, develop]jobs:
review:
uses: your-org/CodeReview/.github/workflows/ai-code-review.yml@mainsecrets:
AI_API_KEY: ${{ secrets.OPENAI_API_KEY }}with:
ai-provider: 'openai'ai-model: 'gpt-4o'min-score: 8# Stricter approvalmax-files: 10# Smaller PRs onlymax-lines: 300auto-merge: false # Review only, no auto-mergelanguage: 'en'# English commentsrun-security-scan: trueexclude-patterns: '*.md,*.txt,docs/*'custom-prompt: 'Focus on error handling and edge cases'

Outputs

The workflow provides these outputs for downstream jobs:

OutputDescription
scoreAI review score (0-10)
approvedWhether PR passed review
mergedWhether PR was auto-merged

Using Outputs

jobs:
review:
uses: your-org/CodeReview/.github/workflows/ai-code-review.yml@mainsecrets:
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }}notify:
needs: reviewruns-on: ubuntu-lateststeps:
- run: | echo "Score: ${{ needs.review.outputs.score }}" echo "Approved: ${{ needs.review.outputs.approved }}"

Review Criteria

The AI evaluates PRs on 5 dimensions (0-10 each):

  1. Code Quality - Readability, complexity, naming
  2. Security - Vulnerabilities, input validation
  3. Performance - Algorithm efficiency, resource usage
  4. Testing - Test coverage
  5. Best Practices - Following conventions

Special Behaviors

Empty Diff Handling

PRs with only documentation/config changes (matching exclude-patterns) are auto-approved with score 10.

Sensitive File Filtering

Files matching these patterns are automatically excluded from AI review:

  • .env*
  • *secret*
  • *.pem, *.key

Comment Updates

When a PR is updated, the existing AI review comment is updated instead of creating a new one.

Requirements

  • GitHub Actions enabled
  • AI API key (Gemini/OpenAI/Anthropic)
  • Repository permissions: contents: write, pull-requests: write

License

MIT

About

Reusable GitHub Actions workflow for AI-powered code review

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors