|
| 1 | +name: '🧙 Gemini Issue Fixer' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ github.event.issue.number }}' |
| 8 | + cancel-in-progress: true |
| 9 | + |
| 10 | +defaults: |
| 11 | + run: |
| 12 | + shell: 'bash' |
| 13 | + |
| 14 | +jobs: |
| 15 | + create-pr: |
| 16 | + timeout-minutes: 30 |
| 17 | + runs-on: 'ubuntu-latest' |
| 18 | + permissions: |
| 19 | + contents: 'write' # Enable reading and modifying code |
| 20 | + id-token: 'write' # Enable minting an identity token |
| 21 | + issues: 'write' # Enable updating issues, such as posting a comment |
| 22 | + pull-requests: 'write' # Enable creating pull requests |
| 23 | + |
| 24 | + steps: |
| 25 | + # Mint a token so that the comments show up as gemini-cli instead of github-actions. |
| 26 | + - name: 'Mint identity token' |
| 27 | + id: 'mint_identity_token' |
| 28 | + if: |- |
| 29 | + ${{ vars.APP_ID }} |
| 30 | + uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2 |
| 31 | + with: |
| 32 | + app-id: '${{ vars.APP_ID }}' |
| 33 | + private-key: '${{ secrets.APP_PRIVATE_KEY }}' |
| 34 | + permission-contents: 'write' |
| 35 | + permission-issues: 'write' |
| 36 | + permission-pull-requests: 'write' |
| 37 | + |
| 38 | + - name: 'Checkout repository' |
| 39 | + uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 |
| 40 | + |
| 41 | + - name: 'Run Gemini PR Create' |
| 42 | + uses: 'google-github-actions/run-gemini-cli@main' # ratchet:exclude |
| 43 | + id: 'gemini_pr_create' |
| 44 | + env: |
| 45 | + GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN }}' |
| 46 | + REPOSITORY: '${{ github.repository }}' |
| 47 | + ISSUE_NUMBER: '${{ github.event.issue.number }}' |
| 48 | + ISSUE_TITLE: '${{ github.event.issue.title }}' |
| 49 | + ISSUE_BODY: '${{ github.event.issue.body }}' |
| 50 | + BRANCH_NAME: 'gemini-fix-${{ github.event.issue.number }}' |
| 51 | + with: |
| 52 | + gemini_api_key: '${{ secrets.GEMINI_API_KEY }}' |
| 53 | + gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}' |
| 54 | + gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}' |
| 55 | + gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}' |
| 56 | + gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}' |
| 57 | + use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}' |
| 58 | + use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}' |
| 59 | + settings: |- |
| 60 | + { |
| 61 | + "debug": ${{ fromJSON(env.DEBUG || env.ACTIONS_STEP_DEBUG || false) }}, |
| 62 | + "maxSessionTurns": 200, |
| 63 | + "mcpServers": { |
| 64 | + "github": { |
| 65 | + "command": "docker", |
| 66 | + "args": [ |
| 67 | + "run", |
| 68 | + "-i", |
| 69 | + "--rm", |
| 70 | + "-e", |
| 71 | + "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 72 | + "ghcr.io/github/github-mcp-server" |
| 73 | + ], |
| 74 | + "env": { |
| 75 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}" |
| 76 | + } |
| 77 | + } |
| 78 | + }, |
| 79 | + "telemetry": { |
| 80 | + "enabled": ${{ vars.GOOGLE_CLOUD_PROJECT != '' }}, |
| 81 | + "target": "gcp" |
| 82 | + } |
| 83 | + } |
| 84 | + prompt: |- |
| 85 | + <prompt> |
| 86 | + <role> |
| 87 | + 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. |
| 88 | + </role> |
| 89 | + <context> |
| 90 | + <description> |
| 91 | + 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. |
| 92 | + </description> |
| 93 | + <github_event> |
| 94 | + <event_type>${{ github.event_name }}</event_type> |
| 95 | + <triggering_user>${{ github.triggering_actor }}</triggering_user> |
| 96 | + <issue> |
| 97 | + <repository>${{ env.REPOSITORY }}</repository> |
| 98 | + <number>${{ env.ISSUE_NUMBER }}</number> |
| 99 | + <title>The title exists in the ISSUE_TITLE environment variable. Run `echo $ISSUE_TITLE` to fetch it.</title> |
| 100 | + <body>The title exists in the ISSUE_BODY environment variable. Run `echo $ISSUE_BODY` to fetch it.</body> |
| 101 | + </issue> |
| 102 | + </github_event> |
| 103 | + </context> |
| 104 | + <instructions> |
| 105 | + <description>Follow these steps sequentially to resolve the issue.</description> |
| 106 | + <steps> |
| 107 | + <step id="0" name="Get Issue Title and Issue Body"> |
| 108 | + The issue's title and body are stored in the ISSUE_TITLE and ISSUE_BODY environment variables. Read them with `echo $ISSUE_TITLE` and `echo $ISSUE_BODY`. |
| 109 | + </step> |
| 110 | + <step id="1" name="Understand Project Standards"> |
| 111 | + The initial context provided to you includes a file tree. If you see a `GEMINI.md` or `CONTRIBUTING.md` file, use the GitHub MCP `get_file_contents` tool to read it first. This file may contain critical project-specific instructions, such as commands for building, testing, or linting. |
| 112 | + </step> |
| 113 | + <step id="2" name="Acknowledge and Plan"> |
| 114 | + 1. Use the GitHub MCP `update_issue` tool to add a "status/gemini-cli-fix" label to the issue. |
| 115 | + 2. Use the `gh issue comment` CLI tool command to post an initial comment. In this comment, you must: |
| 116 | + - State the problem in your own words. |
| 117 | + - Briefly describe the current state of the relevant code. |
| 118 | + - Present a clear, actionable TODO list (using markdown checklists `[ ]`) outlining your plan to fix the issue. |
| 119 | + </step> |
| 120 | + <step id="3" name="Create Branch locally"> |
| 121 | + Use the `git` CLI tool to checkout a new branch for your work. Name it `${{ env.BRANCH_NAME }}`. The command should be: `git checkout -b ${{ env.BRANCH_NAME }}`. |
| 122 | + </step> |
| 123 | + <step id="4" name="Create Branch remotely"> |
| 124 | + Use the GitHub MCP `create_branch` tool to create a new branch for your work. Name it `${{ env.BRANCH_NAME }}`. |
| 125 | + </step> |
| 126 | + <step id="5" name="Investigate and Implement"> |
| 127 | + Use tools, like the GitHub MCP `search_code` and GitHub MCP `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 "..."` |
| 128 | + </step> |
| 129 | + <step id="6" name="Verify Solution"> |
| 130 | + 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. |
| 131 | + </step> |
| 132 | + <step id="7" name="Commit the changes"> |
| 133 | + Commit the changes to the branch `${{ env.BRANCH_NAME }}`, using the Conventional Commits specification for commit messages. Use the `git` CLI tool, such as with `git status` to see changed/added/removed files, `git diff` to see changes, `git add .` to stage all changes files, and `git commit -m '<my commit message>'`. |
| 134 | + </step> |
| 135 | + <step id="8" name="Create Pull Request"> |
| 136 | + Once the solution is fully implemented and verified, use the GitHub MCP `create_pull_request` tool to open a PR. The PR description should clearly link to the issue and summarize the changes you made. |
| 137 | + </step> |
| 138 | + <step id="9" name="Get Pull Request Number"> |
| 139 | + Once you have created a pull request, use the GitHub MCP `list_pull_requests` tool to get the pull request number. |
| 140 | + </step> |
| 141 | + <step id="10" name="Amend your Plan"> |
| 142 | + Use the `gh issue comment --edit-last` CLI tool command to edit your initial comment. You should update the markdown checklist in the initial comment to check the boxes of what is complete with `[x]`, and update the plan if any changes occured - such as skipping or adding a step. Also, suffix a link to your pull request, but just mentioning `#<PULL_REQUEST_NUMBER>`, and GitHub will automatically link it. |
| 143 | + </step> |
| 144 | + </steps> |
| 145 | + </instructions> |
| 146 | + <guidelines> |
| 147 | + <rule>Be Respectful: Your communication should always be constructive and professional.</rule> |
| 148 | + <rule>Be Actionable: Your feedback and code should be specific and clear.</rule> |
| 149 | + <rule>Follow Conventions: Adhere strictly to the existing coding style and patterns in the repository.</rule> |
| 150 | + <rule>Use Tools: Rely on the provided tools for all interactions with the repository. Do not guess file contents or state.</rule> |
| 151 | + <rule>Handle Shell Variables Safely: When defining or using variables in shell commands, ensure they are properly quoted to prevent errors.</rule> |
| 152 | + <rule>If something prevents you from fixing the issue, such as a permissions issue, inform the user in your comment on the issue why you cannot complete the task. If you must inform the user of a limitation, use the `gh issue comment --edit-last` CLI tool command to edit your initial comment. Only create a pull request if it will fix the issue.</rule> |
| 153 | + </guidelines> |
| 154 | + <example> |
| 155 | + <description> |
| 156 | + This is an example of the desired thought process and the initial comment you should post to the GitHub issue. |
| 157 | + </description> |
| 158 | + <user_request> |
| 159 | + <issue_title>Create Mortgage Paydown Calculator Page</issue_title> |
| 160 | + <issue_body> |
| 161 | + We need a new page for a mortgage paydown calculator. It should follow the style and functionality of our other calculator pages. |
| 162 | + </issue_body> |
| 163 | + </user_request> |
| 164 | + <agent_response> |
| 165 | + <thinking> |
| 166 | + 1. **Goal:** The user wants a new mortgage calculator page that matches existing pages. |
| 167 | + 2. **Action: Add Label:** First, I must label the issue as in-progress. `update_issue(add_label: "status/gemini-cli-fix")`. |
| 168 | + 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`. |
| 169 | + 4. **Action: Read `GEMINI.md`:** `get_file_contents('GEMINI.md')`. The file says to use `npm install`, `npm run test`, and `npm run build`. |
| 170 | + 5. **Action: Investigate existing code:** `get_file_contents('CreditPaydown.tsx')`. I see it uses React, TypeScript, and Tailwind CSS. The logic is self-contained. |
| 171 | + 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. |
| 172 | + 7. **Formulate Comment:** Based on my plan, I will now draft the comment for the GitHub issue. |
| 173 | + </thinking> |
| 174 | + <output_comment> |
| 175 | + Hello! I'm here to help with the new Mortgage Paydown Calculator page. |
| 176 | +
|
| 177 | + **Problem** |
| 178 | + 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. |
| 179 | +
|
| 180 | + **Current State** |
| 181 | + 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. |
| 182 | +
|
| 183 | + **My Plan** |
| 184 | + - [ ] Create a new file `src/pages/MortgageCalculator.tsx` modeled after the existing calculator components. |
| 185 | + - [ ] Implement the user interface for inputting mortgage details (principal, interest rate, term). |
| 186 | + - [ ] Implement the backend logic for the paydown calculation. |
| 187 | + - [ ] Add a new unit test file to validate the calculation logic. |
| 188 | + - [ ] Ensure the entire project builds successfully with `npm run build`. |
| 189 | + - [ ] Ensure all tests pass with `npm run test`. |
| 190 | + - [ ] Commit the changes to my feature branch. |
| 191 | + - [ ] Create the final pull request for review. |
| 192 | +
|
| 193 | + I will start working on this now and keep this checklist updated with my progress. |
| 194 | + </output_comment> |
| 195 | + </agent_response> |
| 196 | + </example> |
| 197 | + </prompt> |
0 commit comments