Skip to content

Commit 25c9af0

Browse files
feat: support /fix slash command and workflow
1 parent 3653684 commit 25c9af0

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
name: '🧙 Gemini Issue Fixer'
2+
3+
on:
4+
issue_comment:
5+
types: ['created']
6+
issues:
7+
types: ['opened', 'assigned']
8+
workflow_dispatch:
9+
inputs:
10+
issue_number:
11+
description: 'Issue to fix'
12+
required: true
13+
type: 'number'
14+
15+
concurrency:
16+
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
17+
cancel-in-progress: true
18+
19+
defaults:
20+
run:
21+
shell: 'bash'
22+
23+
permissions:
24+
contents: 'write'
25+
id-token: 'write'
26+
issues: 'write'
27+
pull-requests: 'write'
28+
statuses: 'write'
29+
actions: 'read'
30+
checks: 'read'
31+
repository-projects: 'read'
32+
33+
jobs:
34+
create-pr:
35+
if: |-
36+
github.event_name == 'workflow_dispatch' ||
37+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@gemini-cli /fix')) ||
38+
(github.event_name == 'issues' && contains(github.event.issue.body, '@gemini-cli /fix'))
39+
timeout-minutes: 20
40+
runs-on: 'ubuntu-latest'
41+
42+
steps:
43+
# Mint a token so that the comments show up as gemini-cli instead of
44+
# github-actions.
45+
- name: 'Generate GitHub App Token'
46+
id: 'generate_token'
47+
if: |-
48+
${{ vars.APP_ID }}
49+
uses: 'actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e' # ratchet:actions/create-github-app-token@v2
50+
with:
51+
app-id: '${{ vars.APP_ID }}'
52+
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
53+
54+
- name: 'Checkout repository'
55+
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5
56+
with:
57+
fetch-depth: 1
58+
59+
- name: 'Generate Timestamp'
60+
id: 'timestamp'
61+
run: 'echo "value=$(date -u +%Y-%m-%d_%H-%M)" >> $GITHUB_OUTPUT'
62+
63+
- name: 'Run Gemini PR Create'
64+
uses: './'
65+
id: 'gemini_pr_create'
66+
env:
67+
GITHUB_TOKEN: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
68+
REPOSITORY: '${{ github.repository }}'
69+
with:
70+
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
71+
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
72+
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
73+
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
74+
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
75+
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
76+
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
77+
settings: |-
78+
{
79+
"debug": ${{ fromJSON(env.DEBUG || env.ACTIONS_STEP_DEBUG || false) }},
80+
"maxSessionTurns": 20,
81+
"mcpServers": {
82+
"github": {
83+
"command": "docker",
84+
"args": [
85+
"run",
86+
"-i",
87+
"--rm",
88+
"-e",
89+
"GITHUB_PERSONAL_ACCESS_TOKEN",
90+
"ghcr.io/github/github-mcp-server"
91+
],
92+
"env": {
93+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
94+
}
95+
}
96+
},
97+
"telemetry": {
98+
"enabled": true,
99+
"target": "gcp"
100+
}
101+
}
102+
prompt: |-
103+
<prompt>
104+
<role>
105+
You are an expert software engineer. Your task is to resolve a GitHub issue by understanding the problem, implementing a robust solution, and creating a pull request. You are meticulous, adhere to project standards, and communicate your plan clearly.
106+
</role>
107+
108+
<context>
109+
<description>
110+
This information is from the GitHub event that triggered your execution. Do not fetch this data again; use it as the primary source of truth for the task.
111+
</description>
112+
<github_event>
113+
<event_type>${{ github.event_name }}</event_type>
114+
<triggering_user>${{ github.triggering_actor }}</triggering_user>
115+
<issue>
116+
<number>${{ github.event.issue.number }}</number>
117+
<title>${{ github.event.issue.title }}</title>
118+
<body>
119+
<![CDATA[
120+
${{ github.event.issue.body || github.event.comment.body || github.event.review.body }}
121+
]]>
122+
</body>
123+
</issue>
124+
</github_event>
125+
</context>
126+
127+
<instructions>
128+
<description>Follow these steps sequentially to resolve the issue.</description>
129+
<steps>
130+
<step id="1" name="Understand Project Standards">
131+
The initial context provided to you includes a file tree. If you see a `GEMINI.md` or `CONTRIBUTING.md` file, use the `get_file_contents` tool to read it first. This file may contain critical project-specific instructions, such as commands for building, testing, or linting.
132+
</step>
133+
<step id="2" name="Acknowledge and Plan">
134+
1. Use the `update_issue` tool to add the "gemini-cli-fix" label to the issue.
135+
2. Use the `gh issue comment` command to post an initial comment. In this comment, you must:
136+
- State the problem in your own words.
137+
- Briefly describe the current state of the relevant code.
138+
- Present a clear, actionable TODO list (using markdown checklists `[ ]`) outlining your plan to fix the issue.
139+
</step>
140+
<step id="3" name="Create Branch">
141+
Use the `create_branch` tool to create a new branch for your work. Name it `gemini-fix-${{ github.event.issue.number }}-${{ steps.timestamp.outputs.value }}`.
142+
</step>
143+
<step id="4" name="Investigate and Implement">
144+
Use tools, like the GitHub MCP `search_code` and `get_file_contents` tools, to explore the codebase and implement the necessary code changes. As your plan evolves, you must keep the TODO list in your initial comment updated. To do this, use the `gh` command-line tool directly, as the MCP toolset does not support editing comments. Use the following command: `gh issue comment --edit-last --body "..."`
145+
</step>
146+
<step id="5" name="Verify Solution">
147+
Follow the project-specific instructions from `GEMINI.md` or `CONTRIBUTING.md` to run builds, linters, and tests. Ensure your changes have not introduced any regressions.
148+
</step>
149+
<step id="6" name="Create Pull Request">
150+
Once the solution is fully implemented and verified, use the `create_pull_request` tool to open a PR. The PR description should clearly link to the issue and summarize the changes you made.
151+
</step>
152+
</steps>
153+
</instructions>
154+
155+
<guidelines>
156+
<rule>Be Respectful: Your communication should always be constructive and professional.</rule>
157+
<rule>Be Actionable: Your feedback and code should be specific and clear.</rule>
158+
<rule>Follow Conventions: Adhere strictly to the existing coding style and patterns in the repository.</rule>
159+
<rule>Use Tools: Rely on the provided tools for all interactions with the repository. Do not guess file contents or state.</rule>
160+
<rule>Handle Shell Variables Safely: When defining or using variables in shell commands, ensure they are properly quoted to prevent errors.</rule>
161+
</guidelines>
162+
163+
<example>
164+
<description>
165+
This is an example of the desired thought process and the initial comment you should post to the GitHub issue.
166+
</description>
167+
<user_request>
168+
<issue_title>Create Mortgage Paydown Calculator Page</issue_title>
169+
<issue_body>
170+
We need a new page for a mortgage paydown calculator. It should follow the style and functionality of our other calculator pages.
171+
</issue_body>
172+
</user_request>
173+
<agent_response>
174+
<thinking>
175+
1. **Goal:** The user wants a new mortgage calculator page that matches existing pages.
176+
2. **Action: Add Label:** First, I must label the issue as in-progress. `update_issue(add_label: "gemini-cli-fix")`.
177+
3. **Initial Context:** The file tree shows `CreditPaydown.tsx` and `StudentLoan.tsx`. This suggests a component-based frontend structure, likely React. There is also a `GEMINI.md`.
178+
4. **Action: Read `GEMINI.md`:** `get_file_contents('GEMINI.md')`. The file says to use `npm install`, `npm run test`, and `npm run build`.
179+
5. **Action: Investigate existing code:** `get_file_contents('CreditPaydown.tsx')`. I see it uses React, TypeScript, and Tailwind CSS. The logic is self-contained.
180+
6. **Plan Formation:** I will create a new file, `MortgageCalculator.tsx`, based on the structure of the existing calculator components. I will implement the mortgage calculation logic and ensure the UI matches. Then I will add a unit test and verify the project builds.
181+
7. **Formulate Comment:** Based on my plan, I will now draft the comment for the GitHub issue.
182+
</thinking>
183+
<output_comment>
184+
Hello! I'm here to help with the new Mortgage Paydown Calculator page.
185+
186+
**Problem**
187+
The goal is to create a new page that calculates a mortgage paydown schedule, ensuring its design and functionality are consistent with the existing calculator pages on the site.
188+
189+
**Current State**
190+
The repository already contains similar components for a `Credit PayDown Calculator` and a `Student Loan Pay Down Calculator`. These components are built with React, TypeScript, and Tailwind CSS, and contain self-contained business logic.
191+
192+
**My Plan**
193+
- [ ] Create a new file `src/pages/MortgageCalculator.tsx` modeled after the existing calculator components.
194+
- [ ] Implement the user interface for inputting mortgage details (principal, interest rate, term).
195+
- [ ] Implement the backend logic for the paydown calculation.
196+
- [ ] Add a new unit test file to validate the calculation logic.
197+
- [ ] Ensure the entire project builds successfully with `npm run build`.
198+
- [ ] Ensure all tests pass with `npm run test`.
199+
- [ ] Create the final pull request for review.
200+
201+
I will start working on this now and keep this checklist updated with my progress.
202+
</output_comment>
203+
</agent_response>
204+
</example>
205+
</prompt>
206+
- name: 'Post PR create failure comment'
207+
if: |-
208+
${{ failure() && steps.gemini_pr_create.outcome == 'failure' }}
209+
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea'
210+
with:
211+
github-token: '${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
212+
script: |
213+
github.rest.issues.createComment({
214+
owner: '${{ github.repository }}'.split('/')[0],
215+
repo: '${{ github.repository }}'.split('/')[1],
216+
issue_number: '${{ github.event.issue.number || github.event.pull_request.number }}',
217+
body: 'There is a problem with the Gemini CLI PR create. Please check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.'
218+
})

test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
value=2025-08-18_18-14

test1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
value=2025-08-18_18-14

test2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
value=2025-08-18_18-15

test3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
value=2025-08-18_18-15

0 commit comments

Comments
 (0)