Skip to content

Commit 92445e8

Browse files
Sunny-Morclouddrove-cianmolnagpal
authored
feat: add Gemini AI-powered PR code review workflow and docs (#247)
Co-authored-by: CloudDrove CI <[email protected]> Co-authored-by: Anmol Nagpal <[email protected]>
1 parent a57eb7a commit 92445e8

25 files changed

+199
-33
lines changed

β€Ž.github/workflows/auto_merge.ymlβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ jobs:
5353
checks: read
5454
pull-requests: read
5555
if: |
56-
github.actor == 'dependabot[bot]' &&
57-
inputs.azure_cloud == true &&
56+
github.actor == 'dependabot[bot]' &&
57+
inputs.azure_cloud == true &&
5858
inputs.tfchecks_azure != '[]'
5959
strategy:
6060
matrix:
@@ -81,8 +81,8 @@ jobs:
8181
needs: [static-checks, static-checks-azure]
8282
runs-on: ubuntu-latest
8383
if: |
84-
always() &&
85-
github.actor == 'dependabot[bot]' &&
84+
always() &&
85+
github.actor == 'dependabot[bot]' &&
8686
(needs.static-checks.result == 'success' || needs.static-checks-azure.result == 'success')
8787
steps:
8888
- name: Approve PR via GitHub Bot
@@ -101,9 +101,9 @@ jobs:
101101
runs-on: ubuntu-latest
102102
needs: autoapprove
103103
if: |
104-
always() &&
104+
always() &&
105105
needs.autoapprove.result == 'success' &&
106-
github.event_name == 'pull_request' &&
106+
github.event_name == 'pull_request' &&
107107
github.event.pull_request.draft == false
108108
steps:
109109
- name: Automerge
@@ -115,4 +115,4 @@ jobs:
115115
MERGE_DELETE_BRANCH: "true"
116116
MERGE_LABELS: "dependencies, github_actions"
117117
MERGE_REQUIRED_APPROVALS: ""
118-
...
118+
...
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: Gemini Code Review ✨
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
review_prompt:
8+
required: true
9+
type: string
10+
description: "πŸ“ Prompt text for the Gemini review"
11+
gemini_model:
12+
default: "gemini-2.5-pro"
13+
required: false
14+
type: string
15+
description: "πŸ€– Gemini model to use (default: gemini-2.5-pro)"
16+
github_token:
17+
default: ${{ github.TOKEN }}
18+
required: false
19+
type: string
20+
description: "πŸ”’ GitHub token (default: GITHUB_TOKEN)"
21+
secrets:
22+
GEMINI_API_KEY:
23+
required: true
24+
description: "πŸ”‘ API key for authenticating requests to the Gemini model used for code review."
25+
26+
jobs:
27+
review:
28+
runs-on: ubuntu-latest
29+
permissions:
30+
pull-requests: write
31+
contents: read
32+
steps:
33+
- name: πŸ“₯ Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: πŸ” Get PR diff
37+
id: diff
38+
run: |
39+
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
40+
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
41+
42+
echo "πŸ”— Base: $BASE_BRANCH, PR: $PR_BRANCH"
43+
git fetch origin $BASE_BRANCH $PR_BRANCH
44+
git diff origin/$BASE_BRANCH...origin/$PR_BRANCH > pr.diff
45+
echo "diff_file=pr.diff" >> $GITHUB_OUTPUT
46+
47+
- name: πŸ€– Run Gemini Review
48+
id: gemini
49+
uses: google-github-actions/[email protected]
50+
with:
51+
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
52+
gemini_model: "gemini-2.5-pro"
53+
files: ${{ steps.diff.outputs.diff_file }}
54+
prompt: |
55+
${{ inputs.review_prompt }}
56+
57+
- name: πŸ’¬ Comment Review on PR
58+
if: steps.gemini.outputs.summary != ''
59+
uses: actions/github-script@v6
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
62+
script: |
63+
const summary = ${{ toJSON(steps.gemini.outputs.summary) }};
64+
const review = `### ✨ Gemini Code Review ✨\n\n${summary}`;
65+
66+
const issue_number = context.payload.pull_request.number;
67+
68+
await github.rest.issues.createComment({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
issue_number,
72+
body: review
73+
});
74+
...

β€ŽREADME.mdβ€Ž

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,33 @@ Above example is just a simple example to call workflow from github shared workf
9898
8. [Docker Workflow](./docs/08.docker.md)
9999
* [Example for scan and push docker image on Dockerhub](./docs/08.docker.md#example-for-scan-and-push-docker-image-on-dockerhub)
100100
* [Example for scan and push docker image on ECR](./docs/08.docker.md#example-for-scan-and-push-docker-image-on-ecr)
101-
9. [Helm Workflow](./docs/09.helm.md)
102-
* [Example for AWS cloud provider](./docs/09.helm.md#example-for-aws-cloud-provider)
103-
* [Example for Azure cloud provider](./docs/09.helm.md)
104-
10. [Infracost workflow](./docs/10.infracost.md)
105-
11. [Lock Thread workflow](./docs/11.lock.md)
106-
12. [Powerpipe workflow](./docs/12.powerpipe.md)
107-
13. [PR Checks workflow](./docs/13.pr-checks.md)
108-
14. [Prowler workflow](./docs/14.prowler.md)
109-
15. [Prowler workflow (AWS)](./docs/15.prowlerAWS.md)
110-
16. [Prowler workflow (GCP)](./docs/16.prowlerGCP.md)
111-
17. [README Generation workflow](./docs/17.readme.md)
112-
18. [Remote SSH Command workflow](./docs/18.RemoteSSHCommand.md)
113-
19. [Slack Alert](./docs/19.slack.md)
114-
20. [Smurf Docker + Helm Workflow](./docs/20.smurf-docker-helm.md)
115-
21. [Smurf Terraform Workflow](./docs/21.smurf-terraform.md)
116-
22. [SST Workflow](./docs/22.sst.md)
117-
23. [Stale PR workflow](./docs/23.stale-pr.md)
118-
24. [Tag Release workflow](./docs/24.tag-release.md)
119-
25. [Terraform Checks Workflow](./docs/25.tf-checks.md)
120-
* [Example for terraform checks with azure cloud](./docs/25.tf-checks.md#example-for-terraform-checks-with-azure-cloud)
121-
* [Example for terraform checks with aws cloud](./docs/25.tf-checks.md#example-for-terraform-checks-with-aws-cloud)
122-
* [Example for terraform checks with digitalocean cloud](./docs/25.tf-checks.md#example-for-terraform-checks-with-digitalocean-cloud)
123-
26. [Terraform Lint Workflow](./docs/26.terraform-lint.md)
124-
27. [Terraform Workflow](./docs/27.terraform_workflow.md)
125-
28. [Terraform Module Tag Release Workflow (Shared)](./docs/28.tf-monorepo-tag-release.md)
126-
29. [Terraform PR Plan Diff workflow](./docs/29.tf-pr-checks.md)
101+
9. [Gemini Code Review Workflow](./docs/09.gemini-code-review.md)
102+
10. [Helm Workflow](./docs/10.helm.md)
103+
* [Example for AWS cloud provider](./docs/10.helm.md#example-for-aws-cloud-provider)
104+
* [Example for Azure cloud provider](./docs/10.helm.md)
105+
11. [Infracost workflow](./docs/11.infracost.md)
106+
12. [Lock Thread workflow](./docs/12.lock.md)
107+
13. [Powerpipe workflow](./docs/13.powerpipe.md)
108+
14. [PR Checks workflow](./docs/14.pr-checks.md)
109+
15. [Prowler workflow](./docs/15.prowler.md)
110+
16. [Prowler workflow (AWS)](./docs/16.prowlerAWS.md)
111+
17. [Prowler workflow (GCP)](./docs/17.prowlerGCP.md)
112+
18. [README Generation workflow](./docs/18.readme.md)
113+
19. [Remote SSH Command workflow](./docs/19.RemoteSSHCommand.md)
114+
20. [Slack Alert](./docs/20.slack.md)
115+
21. [Smurf Docker + Helm Workflow](./docs/21.smurf-docker-helm.md)
116+
22. [Smurf Terraform Workflow](./docs/22.smurf-terraform.md)
117+
23. [SST Workflow](./docs/23.sst.md)
118+
24. [Stale PR workflow](./docs/24.stale-pr.md)
119+
25. [Tag Release workflow](./docs/25.tag-release.md)
120+
26. [Terraform Checks Workflow](./docs/26.tf-checks.md)
121+
* [Example for terraform checks with azure cloud](./docs/26.tf-checks.md#example-for-terraform-checks-with-azure-cloud)
122+
* [Example for terraform checks with aws cloud](./docs/26.tf-checks.md#example-for-terraform-checks-with-aws-cloud)
123+
* [Example for terraform checks with digitalocean cloud](./docs/26.tf-checks.md#example-for-terraform-checks-with-digitalocean-cloud)
124+
27. [Terraform Lint Workflow](./docs/27.terraform-lint.md)
125+
28. [Terraform Workflow](./docs/28.terraform_workflow.md)
126+
29. [Terraform Module Tag Release Workflow (Shared)](./docs/29.tf-monorepo-tag-release.md)
127+
30. [Terraform PR Plan Diff workflow](./docs/30.tf-pr-checks.md)
127128
128129
## Feedback
129130
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/github-shared-workflows/issues), or feel free to drop us an email at [[email protected]](mailto:[email protected]).
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# πŸ“– Gemini Code Review Workflow Guide
2+
3+
## 🎯 Objective
4+
Automate AI-powered code reviews for every Pull Request using Google’s Gemini model.
5+
This ensures consistent, high-quality review feedback on style, correctness, performance, and best practices.
6+
7+
---
8+
9+
## ✨ Features
10+
- πŸš€ **Auto Review** β€” Runs automatically on PR open, update, or reopen.
11+
- πŸ€– **AI Suggestions** β€” Uses Google Gemini (`gemini-2.5-pro`) for detailed review.
12+
- πŸ“‚ **Diff Based** β€” Reviews only the code changes in the PR.
13+
- πŸ”„ **Reusable Workflow** β€” Centralized workflow callable from multiple repos.
14+
- πŸ”‘ **Configurable** β€” Supports overriding model or GitHub token if needed.
15+
16+
---
17+
18+
## ❓ Why use this?
19+
- βœ… Catch issues early without waiting for human reviewers.
20+
- βœ… Standardize review quality across repos.
21+
- βœ… Reduce review time for repetitive issues (formatting, common bugs, performance hints).
22+
- βœ… Easy to integrate and maintain via a reusable workflow.
23+
24+
---
25+
26+
## πŸ”‘ Setup: Google API Key
27+
The Gemini CLI requires a Google API key.
28+
29+
1. Visit **[Google AI Studio](https://aistudio.google.com/)**
30+
2. Click **Create API Key**
31+
3. Copy the key and add it to your repo’s GitHub secrets:
32+
- Navigate to **Settings β†’ Secrets and variables β†’ Actions**
33+
- Add a new secret:
34+
- **Name:** `GEMINI_API_KEY`
35+
- **Value:** *(your API key from Google AI Studio)*
36+
37+
---
38+
39+
## ✍️ Customizing the Review Prompt
40+
41+
The **review prompt** controls *how Gemini reviews your code*.
42+
By default, a general-purpose prompt is used, but you can override it in the caller workflow.
43+
44+
### πŸ”Ή Example
45+
```yaml
46+
with:
47+
review_prompt: |
48+
πŸ§‘β€πŸ’» You are an AI code reviewer. Review the provided **git diff** in pr.diff.
49+
Focus on:
50+
- πŸ“‚ Mentioning the file name and line number
51+
- ⚠️ Describing the issue clearly
52+
- ❓ Explaining why it is problematic
53+
- πŸ›  Suggesting a fix
54+
If multiple issues exist, list them separately.
55+
```
56+
---
57+
58+
## ▢️ Example Caller File
59+
60+
```yaml
61+
---
62+
name: PR Gemini Review πŸš€
63+
64+
on:
65+
pull_request:
66+
types: [opened, synchronize, reopened]
67+
68+
jobs:
69+
call-gemini-review:
70+
name: πŸ€– Run Gemini Code Review
71+
uses: clouddrove/github-shared-workflows/.github/workflows/gemini-code-review.yml@master
72+
with:
73+
gemini_model: "gemini-2.5-pro" # ✨ optional, default already set
74+
github_token: ${{ github.TOKEN }} # πŸ”‘ optional override
75+
review_prompt: |
76+
πŸ§‘β€πŸ’» You are an AI code reviewer. Review the provided **git diff** in pr.diff.
77+
For each issue you find:
78+
- πŸ“‚ Mention the file name and line number
79+
- ⚠️ Describe the issue
80+
- ❓ Explain why it is problematic
81+
- πŸ›  Suggest a fix
82+
If multiple issues exist, list them separately.
83+
secrets:
84+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
85+
```
86+
87+
## πŸ“Œ Notes
88+
89+
- Default GitHub token (github.TOKEN) is used unless overridden.
90+
- You can change the model via with.gemini_model.
91+
- 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.

0 commit comments

Comments
Β (0)