Skip to content

Commit 3766eb2

Browse files
committed
Update: Workflow and docs for gemini-review for user prompt
1 parent dbb471c commit 3766eb2

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

.github/workflows/gemini-code-review.yml

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
---
2-
name: Gemini Code Review ✨
2+
name: Gemini Code Review ✨
33

44
on:
55
workflow_call:
66
inputs:
7+
review_prompt:
8+
required: true
9+
type: string
10+
description: "📝 Prompt text for the Gemini review"
711
gemini_model:
812
default: "gemini-2.5-pro"
913
required: false
@@ -21,74 +25,44 @@ on:
2125

2226
jobs:
2327
review:
24-
name: 🕵️ Gemini Review
2528
runs-on: ubuntu-latest
2629
permissions:
2730
pull-requests: write
2831
contents: read
29-
3032
steps:
31-
- name: 📥 Checkout code
33+
- name: 📥 Checkout
3234
uses: actions/checkout@v4
3335

34-
- name: 📑 Get PR diff (via GitHub API, robust)
36+
- name: 🔍 Get PR diff
3537
id: diff
36-
env:
37-
GITHUB_TOKEN: ${{ inputs.github_token || github.TOKEN }}
3838
run: |
39-
set -euo pipefail
40-
PR_NUMBER=${{ github.event.pull_request.number }}
41-
OWNER="${GITHUB_REPOSITORY%/*}"
42-
REPO="${GITHUB_REPOSITORY#*/}"
43-
44-
echo "🔍 Fetching PR diff for $OWNER/$REPO PR#$PR_NUMBER"
45-
46-
curl -sS -H "Accept: application/vnd.github.v3.diff" \
47-
-H "Authorization: token $GITHUB_TOKEN" \
48-
"https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER" -o pr.diff || true
49-
50-
if [ ! -s pr.diff ]; then
51-
echo "⚠️ Diff empty, trying patch format..."
52-
curl -sS -H "Accept: application/vnd.github.v3.patch" \
53-
-H "Authorization: token $GITHUB_TOKEN" \
54-
"https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER" -o pr.diff || true
55-
fi
56-
57-
echo "📏 PR diff size (bytes): $(wc -c < pr.diff || echo 0)"
58-
59-
if [ ! -s pr.diff ]; then
60-
echo "❌ ERROR: pr.diff is empty — cannot run review."
61-
echo "diff_file=" >> $GITHUB_OUTPUT
62-
exit 0
63-
fi
39+
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
40+
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
6441
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
6545
echo "diff_file=pr.diff" >> $GITHUB_OUTPUT
6646
6747
- name: 🤖 Run Gemini Review
6848
id: gemini
6949
uses: google-github-actions/[email protected]
7050
with:
7151
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
72-
gemini_model: ${{ inputs.gemini_model }}
52+
gemini_model: "gemini-2.5-pro"
7353
files: ${{ steps.diff.outputs.diff_file }}
7454
prompt: |
75-
You are an AI code reviewer 🕵️.
76-
Review the given **git diff**.
77-
For each issue:
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 all separately.
55+
${{ inputs.review_prompt }}
8356
8457
- name: 💬 Comment Review on PR
8558
if: steps.gemini.outputs.summary != ''
8659
uses: actions/github-script@v6
8760
with:
88-
github-token: ${{ inputs.github_token || github.TOKEN }}
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
8962
script: |
9063
const summary = ${{ toJSON(steps.gemini.outputs.summary) }};
91-
const review = `### 📝 Gemini Code Review\n\n${summary}`;
64+
const review = `### ✨ Gemini Code Review ✨\n\n${summary}`;
65+
9266
const issue_number = context.payload.pull_request.number;
9367
9468
await github.rest.issues.createComment({

docs/09.gemini-code-review.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,50 @@ The Gemini CLI requires a Google API key.
3636

3737
---
3838

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+
3958
## ▶️ Example Caller File
4059
4160
```yaml
4261
---
43-
name: 🚀 PR Gemini Review
62+
name: PR Gemini Review 🚀
4463

4564
on:
4665
pull_request:
4766
types: [opened, synchronize, reopened]
4867

4968
jobs:
50-
call-review:
69+
call-gemini-review:
5170
name: 🤖 Run Gemini Code Review
5271
uses: clouddrove/github-shared-workflows/.github/workflows/gemini-code-review.yml@master
5372
with:
5473
gemini_model: "gemini-2.5-pro" # ✨ optional, default already set
5574
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.
5683
secrets:
5784
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
5885
```

0 commit comments

Comments
 (0)