|
1 | 1 | ---
|
2 |
| -name: ✨ Gemini Code Review ✨ |
| 2 | +name: Gemini Code Review ✨ |
3 | 3 |
|
4 | 4 | on:
|
5 | 5 | workflow_call:
|
6 | 6 | inputs:
|
| 7 | + review_prompt: |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + description: "📝 Prompt text for the Gemini review" |
7 | 11 | gemini_model:
|
8 | 12 | default: "gemini-2.5-pro"
|
9 | 13 | required: false
|
|
21 | 25 |
|
22 | 26 | jobs:
|
23 | 27 | review:
|
24 |
| - name: 🕵️ Gemini Review |
25 | 28 | runs-on: ubuntu-latest
|
26 | 29 | permissions:
|
27 | 30 | pull-requests: write
|
28 | 31 | contents: read
|
29 |
| - |
30 | 32 | steps:
|
31 |
| - - name: 📥 Checkout code |
| 33 | + - name: 📥 Checkout |
32 | 34 | uses: actions/checkout@v4
|
33 | 35 |
|
34 |
| - - name: 📑 Get PR diff (via GitHub API, robust) |
| 36 | + - name: 🔍 Get PR diff |
35 | 37 | id: diff
|
36 |
| - env: |
37 |
| - GITHUB_TOKEN: ${{ inputs.github_token || github.TOKEN }} |
38 | 38 | 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 }}" |
64 | 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 |
65 | 45 | echo "diff_file=pr.diff" >> $GITHUB_OUTPUT
|
66 | 46 |
|
67 | 47 | - name: 🤖 Run Gemini Review
|
68 | 48 | id: gemini
|
69 | 49 | uses: google-github-actions/[email protected]
|
70 | 50 | with:
|
71 | 51 | gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
|
72 |
| - gemini_model: ${{ inputs.gemini_model }} |
| 52 | + gemini_model: "gemini-2.5-pro" |
73 | 53 | files: ${{ steps.diff.outputs.diff_file }}
|
74 | 54 | 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 }} |
83 | 56 |
|
84 | 57 | - name: 💬 Comment Review on PR
|
85 | 58 | if: steps.gemini.outputs.summary != ''
|
86 | 59 | uses: actions/github-script@v6
|
87 | 60 | with:
|
88 |
| - github-token: ${{ inputs.github_token || github.TOKEN }} |
| 61 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
89 | 62 | script: |
|
90 | 63 | 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 | +
|
92 | 66 | const issue_number = context.payload.pull_request.number;
|
93 | 67 |
|
94 | 68 | await github.rest.issues.createComment({
|
|
0 commit comments