Skip to content

Commit 5aef154

Browse files
feat: support /fix slash command and workflow
1 parent 3653684 commit 5aef154

1 file changed

Lines changed: 235 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)