Skip to content

Commit 7beed5b

Browse files
feat: support /fix slash command and workflow
1 parent 3653684 commit 7beed5b

File tree

1 file changed

+220
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)