Skip to main content

A cross-platform code review tool using Gemini AI for GitHub, GitLab, and Azure DevOps.

Project description

Gemini AI Code Reviewer

A GitHub Action that automatically reviews pull requests using Google's Gemini AI.

Features

  • Review your PRs using Gemini API
  • Give use comments and suggestions to improve the source codes

Setup

  1. To use this GitHub Action, you need an Gemini API key. If you don't have one, sign up for an API key at Google AI Studio.

  2. Add the Gemini API key as a GitHub Secret in your repository with the name GEMINI_API_KEY. You can find more information about GitHub Secrets here.

  3. Create a .github/workflows/code-review.yml file in your repository and add the following content:

name: Gemini AI Code Reviewer

on:
  issue_comment:
    types: [created]

permissions: write-all

jobs:
  gemini-code-review:
    runs-on: ubuntu-latest
    if: |
      github.event.issue.pull_request &&
      contains(github.event.comment.body, '/gemini-review')
    steps:
      - name: PR Info
        run: |
          echo "Comment: ${{ github.event.comment.body }}"
          echo "Issue Number: ${{ github.event.issue.number }}"
          echo "Repository: ${{ github.repository }}"

      - name: Checkout Repo
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Get PR Details
        id: pr
        run: |
          PR_JSON=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})
          echo "head_sha=$(echo $PR_JSON | jq -r .head.sha)" >> $GITHUB_OUTPUT
          echo "base_sha=$(echo $PR_JSON | jq -r .base.sha)" >> $GITHUB_OUTPUT
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - uses: HoangNguyen0403/ai-pr-reviewer@v0.0.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
          GEMINI_MODEL: gemini-1.5-pro-002 # Optional, default is `gemini-1.5-flash-002`
          FILES_EXCLUDE: "*.md,*.txt,package-lock.json,*.yml,*.yaml"

if you don't set GEMINI_MODEL, the default model is gemini-1.5-flash-002. gemini-1.5-flash-002 can be used for generating code, extracting data, edit text, and more. Best for tasks balancing performance and cost. For the detailed information about the models, please refer to Gemini models.

  1. Commit codes to your repository, and working on your pull requests.
  2. When you're ready to review the PR, you can trigger the workflow by commenting /gemini-review in the PR.

How It Works

This GitHub Action uses the Gemini AI API to provide code review feedback. It works by:

  1. Analyzing the changes: It grabs the code modifications from your pull request and filters out any files you don't want reviewed.
  2. Consulting the Gemini model: It sends chunks of the modified code to the Gemini for analysis.
  3. Providing feedback: Gemini AI examines the code and generates review comments.
  4. Delivering the review: The Action adds the comments directly to your pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

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_pr_reviewer-0.0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

ai_pr_reviewer-0.0.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_pr_reviewer-0.0.1.tar.gz.

File metadata

  • Download URL: ai_pr_reviewer-0.0.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for ai_pr_reviewer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a597977270377d555bb3f362afbec3377c3a82a230ebbf8fac4a5a59160a94e5
MD5 c72129175d46b67beb84a4850bae6abb
BLAKE2b-256 bbbb9ab3928e59877857157cf24cb8b7606ac11824d25ee16d0985666ad151e6

See more details on using hashes here.

File details

Details for the file ai_pr_reviewer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ai_pr_reviewer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for ai_pr_reviewer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71bced297f1ae8bd914971d35752d7e6cc675196e5e3cd25f6bafb81804b2d72
MD5 f7cc11c76eeea61fd6d204b61aead512
BLAKE2b-256 fcc85d27704fd6a6caf75398a500e4d1d7308b6a617672608144de047e7abcde

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