Skip to content

Commit 402d2d3

Browse files
feat: support /fix slash command and workflow
1 parent 3653684 commit 402d2d3

1 file changed

Lines changed: 215 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)