-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add Gemini AI-powered PR code review workflow and docs #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7a80b4
feat: add Gemini AI-powered PR code review workflow and docs
Sunny-Mor 29e3d19
Merge branch 'master' into feat/gemini-review
Sunny-Mor f6544c8
Merge branch 'master' into feat/gemini-review
clouddrove-ci dbb471c
Merge branch 'master' into feat/gemini-review
Sunny-Mor 3766eb2
Update: Workflow and docs for gemini-review for user prompt
Sunny-Mor 05b79e8
Merge branch 'master' into feat/gemini-review
anmolnagpal ecc6da0
fix: yamllint for auto merge workflow
Sunny-Mor b0d4606
fix: yamllint for auto merge workflow
Sunny-Mor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| name: Gemini Code Review ✨ | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| review_prompt: | ||
| required: true | ||
| type: string | ||
| description: "📝 Prompt text for the Gemini review" | ||
| gemini_model: | ||
| default: "gemini-2.5-pro" | ||
| required: false | ||
| type: string | ||
| description: "🤖 Gemini model to use (default: gemini-2.5-pro)" | ||
| github_token: | ||
| default: ${{ github.TOKEN }} | ||
| required: false | ||
| type: string | ||
| description: "🔒 GitHub token (default: GITHUB_TOKEN)" | ||
| secrets: | ||
| GEMINI_API_KEY: | ||
| required: true | ||
| description: "🔑 API key for authenticating requests to the Gemini model used for code review." | ||
|
|
||
| jobs: | ||
| review: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| contents: read | ||
| steps: | ||
| - name: 📥 Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: 🔍 Get PR diff | ||
| id: diff | ||
| run: | | ||
| BASE_BRANCH="${{ github.event.pull_request.base.ref }}" | ||
| PR_BRANCH="${{ github.event.pull_request.head.ref }}" | ||
|
|
||
| echo "🔗 Base: $BASE_BRANCH, PR: $PR_BRANCH" | ||
| git fetch origin $BASE_BRANCH $PR_BRANCH | ||
| git diff origin/$BASE_BRANCH...origin/$PR_BRANCH > pr.diff | ||
| echo "diff_file=pr.diff" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: 🤖 Run Gemini Review | ||
| id: gemini | ||
| uses: google-github-actions/run-gemini-cli@v0.1.12 | ||
| with: | ||
| gemini_api_key: ${{ secrets.GEMINI_API_KEY }} | ||
| gemini_model: "gemini-2.5-pro" | ||
| files: ${{ steps.diff.outputs.diff_file }} | ||
| prompt: | | ||
| ${{ inputs.review_prompt }} | ||
|
|
||
| - name: 💬 Comment Review on PR | ||
| if: steps.gemini.outputs.summary != '' | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const summary = ${{ toJSON(steps.gemini.outputs.summary) }}; | ||
| const review = `### ✨ Gemini Code Review ✨\n\n${summary}`; | ||
|
|
||
| const issue_number = context.payload.pull_request.number; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number, | ||
| body: review | ||
| }); | ||
| ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # 📖 Gemini Code Review Workflow Guide | ||
|
|
||
| ## 🎯 Objective | ||
| Automate AI-powered code reviews for every Pull Request using Google’s Gemini model. | ||
| This ensures consistent, high-quality review feedback on style, correctness, performance, and best practices. | ||
|
|
||
| --- | ||
|
|
||
| ## ✨ Features | ||
| - 🚀 **Auto Review** — Runs automatically on PR open, update, or reopen. | ||
| - 🤖 **AI Suggestions** — Uses Google Gemini (`gemini-2.5-pro`) for detailed review. | ||
| - 📂 **Diff Based** — Reviews only the code changes in the PR. | ||
| - 🔄 **Reusable Workflow** — Centralized workflow callable from multiple repos. | ||
| - 🔑 **Configurable** — Supports overriding model or GitHub token if needed. | ||
|
|
||
| --- | ||
|
|
||
| ## ❓ Why use this? | ||
| - ✅ Catch issues early without waiting for human reviewers. | ||
| - ✅ Standardize review quality across repos. | ||
| - ✅ Reduce review time for repetitive issues (formatting, common bugs, performance hints). | ||
| - ✅ Easy to integrate and maintain via a reusable workflow. | ||
|
|
||
| --- | ||
|
|
||
| ## 🔑 Setup: Google API Key | ||
| The Gemini CLI requires a Google API key. | ||
|
|
||
| 1. Visit **[Google AI Studio](https://aistudio.google.com/)** | ||
| 2. Click **Create API Key** | ||
| 3. Copy the key and add it to your repo’s GitHub secrets: | ||
| - Navigate to **Settings → Secrets and variables → Actions** | ||
| - Add a new secret: | ||
| - **Name:** `GEMINI_API_KEY` | ||
| - **Value:** *(your API key from Google AI Studio)* | ||
|
|
||
| --- | ||
|
|
||
| ## ✍️ Customizing the Review Prompt | ||
|
|
||
| The **review prompt** controls *how Gemini reviews your code*. | ||
| By default, a general-purpose prompt is used, but you can override it in the caller workflow. | ||
|
|
||
| ### 🔹 Example | ||
| ```yaml | ||
| with: | ||
| review_prompt: | | ||
| 🧑💻 You are an AI code reviewer. Review the provided **git diff** in pr.diff. | ||
| Focus on: | ||
| - 📂 Mentioning the file name and line number | ||
| - ⚠️ Describing the issue clearly | ||
| - ❓ Explaining why it is problematic | ||
| - 🛠 Suggesting a fix | ||
| If multiple issues exist, list them separately. | ||
| ``` | ||
| --- | ||
|
|
||
| ## ▶️ Example Caller File | ||
|
|
||
| ```yaml | ||
| --- | ||
| name: PR Gemini Review 🚀 | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| jobs: | ||
| call-gemini-review: | ||
| name: 🤖 Run Gemini Code Review | ||
| uses: clouddrove/github-shared-workflows/.github/workflows/gemini-code-review.yml@master | ||
| with: | ||
| gemini_model: "gemini-2.5-pro" # ✨ optional, default already set | ||
| github_token: ${{ github.TOKEN }} # 🔑 optional override | ||
| review_prompt: | | ||
| 🧑💻 You are an AI code reviewer. Review the provided **git diff** in pr.diff. | ||
| For each issue you find: | ||
| - 📂 Mention the file name and line number | ||
| - ⚠️ Describe the issue | ||
| - ❓ Explain why it is problematic | ||
| - 🛠 Suggest a fix | ||
| If multiple issues exist, list them separately. | ||
| secrets: | ||
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | ||
| ``` | ||
|
|
||
| ## 📌 Notes | ||
|
|
||
| - Default GitHub token (github.TOKEN) is used unless overridden. | ||
| - You can change the model via with.gemini_model. | ||
| - Works best on small to medium PRs — large diffs may exceed token limits. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.