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
-
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.
-
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. -
Create a
.github/workflows/code-reviewer-action.ymlfile in your repository and add the following content:
-
Github action:
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, '/ai-review') steps: - name: Checkout Repo uses: actions/checkout@v3 - name: Run Gemini AI Code Reviewer uses: HoangNguyen0403/ai_code_reviewer@latest with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} AI_MODEL: 'gemini-2.5-flash-preview-05-20' # Optional FILES_EXCLUDE: ['**/node_modules/**', '**/dist/**', '**/build/**'] # Optional
-
Gitlab CI:
workflow: rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_EVENT_TYPE == "opened"' # Or synchronize etc. when: always # Trigger on PR open/update if you want baseline analysis stages: - code-review gemini_code_review: stage: code-review image: python:3.10 before_script: - python -m pip install --upgrade pip - pip install --no-cache-dir --upgrade ai-pr-reviewer variables: GITLAB_API_URL: "https://gitlab.com/api/v4" CI_PROJECT_NAMESPACE: "$CI_PROJECT_NAMESPACE" CI_PROJECT_ID: "$CI_PROJECT_ID" CI_MERGE_REQUEST_IID: "$CI_MERGE_REQUEST_IID" GITLAB_TOKEN: "$CI_JOB_TOKEN" GEMINI_API_KEY: "$GEMINI_API_KEY" AI_MODEL: "gemini-2.5-flash-preview-05-20" # Optional FILES_EXCLUDE: "['**/node_modules/**', '**/dist/**', '**/build/**']" # Optional script: - | latest_comment=$(python -c "import gitlab; gl = gitlab.Gitlab('$GITLAB_URL', private_token='$GITLAB_TOKEN'); mr = gl.projects.get($CI_PROJECT_ID).mergerequests.get($CI_MERGE_REQUEST_IID); notes = mr.notes.list(order_by='created_at', sort='desc'); print(notes[0].body if notes else '')") echo "Latest comment: $latest_comment" if [[ "$latest_comment" != *"/ai-pr-reviewer"* ]]; then echo "No /ai-pr-reviewer comment found. Skipping job." exit 0 fi - ai-pr-reviewer gitlab
-
Azure Devops CI:
trigger: none # Prevents automatic triggers; pipeline is run manually or via REST API pr: none pool: vmImage: 'ubuntu-latest' steps: - task: UsePythonVersion@0 inputs: versionSpec: '3.10' - script: | python -m pip install --upgrade pip pip install --no-cache-dir --upgrade ai-pr-reviewer ai-pr-reviewer azure displayName: 'Run AI PR Reviewer' env: AZURE_ORG_URL: $(AZURE_ORG_URL) AZURE_PROJECT: $(AZURE_PROJECT) AZURE_REPO_ID: $(AZURE_REPO_ID) AZURE_PULL_REQUEST_ID: $(AZURE_PULL_REQUEST_ID) AZURE_PAT: $(AZURE_PAT) GEMINI_API_KEY: $(GEMINI_API_KEY) AI_MODEL: "gemini-2.5-flash-preview-05-20" # Optional FILES_EXCLUDE: "['**/node_modules/**', '**/dist/**', '**/build/**']" # Optional
if you don't set
GEMINI_MODEL, the default model isgemini-2.0-flash.gemini-2.0-flashcan 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.
-
Commit codes to your repository, and working on your pull requests.
-
When you're ready to review the PR, you can trigger the workflow by commenting
/ai-reviewin the PR.
How It Works
This GitHub Action uses the Gemini AI API to provide code review feedback. It works by:
- Analyzing the changes: It grabs the code modifications from your pull request and filters out any files you don't want reviewed.
- Consulting the Gemini model: It sends chunks of the modified code to the Gemini for analysis.
- Providing feedback: Gemini AI examines the code and generates review comments.
- 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.
Metadata
Release files for ai-pr-reviewer 0.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_pr_reviewer-0.0.13.tar.gz | 12.9 kB | Without provenance | Details for ai_pr_reviewer-0.0.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_pr_reviewer-0.0.13-py3-none-any.whl | Python 3 | none | any | Details for ai_pr_reviewer-0.0.13-py3-none-any.whl |
Total release size: 26.8 kB
Release files / ai_pr_reviewer-0.0.13.tar.gz
| Download URL | ai_pr_reviewer-0.0.13.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c21315fbb7f793ab83d190b0f5ff2e62a9accdc61e0ee97efe42fc9dc13a083
|
|
BLAKE2b-256 checksum How to use checksums |
7230e29f55e17e35a14fd339ef73f6c0b5d0e9ab4b942ac5556fa8a39909d7e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Release files / ai_pr_reviewer-0.0.13-py3-none-any.whl
| Download URL | ai_pr_reviewer-0.0.13-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63dc2956d152bf31b2dada29a0950fd3506b469ce449f93e03191241ff074f19
|
|
BLAKE2b-256 checksum How to use checksums |
bcf5b87c17d7cc2668caf2da34901ae74020db4b36939c02fd79e03b5e818629
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Security for ai-pr-reviewer 0.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.