Skip to content

Commit 9f0724b

Browse files
authored
Merge pull request #47 from GrinZero/feature/gemini-cli
feat: gemini-cli
2 parents b2347cb + e17db1b commit 9f0724b

File tree

7 files changed

+833
-1
lines changed

7 files changed

+833
-1
lines changed

.github/workflows/gemini-cli.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Run gemini-cli
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
permissions: write-all
8+
9+
jobs:
10+
gemini-code-review:
11+
runs-on: ubuntu-latest
12+
if: |
13+
github.event.issue.pull_request &&
14+
contains(github.event.comment.body, '/gemini-cli')
15+
steps:
16+
- name: Run Gemini CLI
17+
uses: google-github-actions/[email protected]
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
name: "🔀 Gemini Dispatch"
2+
3+
on:
4+
pull_request_review_comment:
5+
types:
6+
- "created"
7+
pull_request_review:
8+
types:
9+
- "submitted"
10+
pull_request:
11+
types:
12+
- "opened"
13+
issues:
14+
types:
15+
- "opened"
16+
- "reopened"
17+
issue_comment:
18+
types:
19+
- "created"
20+
21+
defaults:
22+
run:
23+
shell: "bash"
24+
25+
jobs:
26+
debugger:
27+
if: |-
28+
${{ fromJSON(vars.DEBUG || vars.ACTIONS_STEP_DEBUG || false) }}
29+
runs-on: "ubuntu-latest"
30+
permissions:
31+
contents: "read"
32+
steps:
33+
- name: "Print context for debugging"
34+
env:
35+
DEBUG_event_name: "${{ github.event_name }}"
36+
DEBUG_event__action: "${{ github.event.action }}"
37+
DEBUG_event__comment__author_association: "${{ github.event.comment.author_association }}"
38+
DEBUG_event__issue__author_association: "${{ github.event.issue.author_association }}"
39+
DEBUG_event__pull_request__author_association: "${{ github.event.pull_request.author_association }}"
40+
DEBUG_event__review__author_association: "${{ github.event.review.author_association }}"
41+
DEBUG_event: "${{ toJSON(github.event) }}"
42+
run: |-
43+
env | grep '^DEBUG_'
44+
45+
dispatch:
46+
# For PRs: only if not from a fork
47+
# For issues: only on open/reopen
48+
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
49+
if: |-
50+
(
51+
github.event_name == 'pull_request' &&
52+
github.event.pull_request.head.repo.fork == false
53+
) || (
54+
github.event_name == 'issues' &&
55+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
56+
) || (
57+
github.event.sender.type == 'User' &&
58+
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
59+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association)
60+
)
61+
runs-on: "ubuntu-latest"
62+
permissions:
63+
contents: "read"
64+
issues: "write"
65+
pull-requests: "write"
66+
outputs:
67+
command: "${{ steps.extract_command.outputs.command }}"
68+
request: "${{ steps.extract_command.outputs.request }}"
69+
additional_context: "${{ steps.extract_command.outputs.additional_context }}"
70+
issue_number: "${{ github.event.pull_request.number || github.event.issue.number }}"
71+
steps:
72+
- name: "Mint identity token"
73+
id: "mint_identity_token"
74+
if: |-
75+
${{ vars.APP_ID }}
76+
uses: "actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b" # ratchet:actions/create-github-app-token@v2
77+
with:
78+
app-id: "${{ vars.APP_ID }}"
79+
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
80+
permission-contents: "read"
81+
permission-issues: "write"
82+
permission-pull-requests: "write"
83+
84+
- name: "Extract command"
85+
id: "extract_command"
86+
uses: "actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea" # ratchet:actions/github-script@v7
87+
env:
88+
EVENT_TYPE: "${{ github.event_name }}.${{ github.event.action }}"
89+
REQUEST: "${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}"
90+
with:
91+
script: |
92+
const eventType = process.env.EVENT_TYPE;
93+
const request = process.env.REQUEST;
94+
core.setOutput('request', request);
95+
96+
if (eventType === 'pull_request.opened') {
97+
core.setOutput('command', 'review');
98+
} else if (['issues.opened', 'issues.reopened'].includes(eventType)) {
99+
core.setOutput('command', 'triage');
100+
} else if (request.startsWith("@gemini-cli /review")) {
101+
core.setOutput('command', 'review');
102+
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
103+
core.setOutput('additional_context', additionalContext);
104+
} else if (request.startsWith("@gemini-cli /triage")) {
105+
core.setOutput('command', 'triage');
106+
} else if (request.startsWith("@gemini-cli")) {
107+
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
108+
core.setOutput('command', 'invoke');
109+
core.setOutput('additional_context', additionalContext);
110+
} else {
111+
core.setOutput('command', 'fallthrough');
112+
}
113+
114+
- name: "Acknowledge request"
115+
env:
116+
GITHUB_TOKEN: "${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}"
117+
ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
118+
MESSAGE: |-
119+
🤖 Hi @${{ github.actor }}, I've received your request, and I'm working on it now! You can track my progress [in the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.
120+
REPOSITORY: "${{ github.repository }}"
121+
run: |-
122+
gh issue comment "${ISSUE_NUMBER}" \
123+
--body "${MESSAGE}" \
124+
--repo "${REPOSITORY}"
125+
126+
review:
127+
needs: "dispatch"
128+
if: |-
129+
${{ needs.dispatch.outputs.command == 'review' }}
130+
uses: "./.github/workflows/gemini-review.yml"
131+
permissions:
132+
contents: "read"
133+
id-token: "write"
134+
issues: "write"
135+
pull-requests: "write"
136+
with:
137+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
138+
secrets: "inherit"
139+
140+
triage:
141+
needs: "dispatch"
142+
if: |-
143+
${{ needs.dispatch.outputs.command == 'triage' }}
144+
uses: "./.github/workflows/gemini-triage.yml"
145+
permissions:
146+
contents: "read"
147+
id-token: "write"
148+
issues: "write"
149+
pull-requests: "write"
150+
with:
151+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
152+
secrets: "inherit"
153+
154+
invoke:
155+
needs: "dispatch"
156+
if: |-
157+
${{ needs.dispatch.outputs.command == 'invoke' }}
158+
uses: "./.github/workflows/gemini-invoke.yml"
159+
permissions:
160+
contents: "read"
161+
id-token: "write"
162+
issues: "write"
163+
pull-requests: "write"
164+
with:
165+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
166+
secrets: "inherit"
167+
168+
fallthrough:
169+
needs:
170+
- "dispatch"
171+
- "review"
172+
- "triage"
173+
- "invoke"
174+
if: |-
175+
${{ always() && !cancelled() && (failure() || needs.dispatch.outputs.command == 'fallthrough') }}
176+
runs-on: "ubuntu-latest"
177+
permissions:
178+
contents: "read"
179+
issues: "write"
180+
pull-requests: "write"
181+
steps:
182+
- name: "Mint identity token"
183+
id: "mint_identity_token"
184+
if: |-
185+
${{ vars.APP_ID }}
186+
uses: "actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b" # ratchet:actions/create-github-app-token@v2
187+
with:
188+
app-id: "${{ vars.APP_ID }}"
189+
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
190+
permission-contents: "read"
191+
permission-issues: "write"
192+
permission-pull-requests: "write"
193+
194+
- name: "Send failure comment"
195+
env:
196+
GITHUB_TOKEN: "${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}"
197+
ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
198+
MESSAGE: |-
199+
🤖 I'm sorry @${{ github.actor }}, but I was unable to process your request. Please [see the logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.
200+
REPOSITORY: "${{ github.repository }}"
201+
run: |-
202+
gh issue comment "${ISSUE_NUMBER}" \
203+
--body "${MESSAGE}" \
204+
--repo "${REPOSITORY}"
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: "▶️ Gemini Invoke"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
additional_context:
7+
type: "string"
8+
description: "Any additional context from the request"
9+
required: false
10+
11+
concurrency:
12+
group: "${{ github.workflow }}-invoke-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number }}"
13+
cancel-in-progress: false
14+
15+
defaults:
16+
run:
17+
shell: "bash"
18+
19+
jobs:
20+
invoke:
21+
runs-on: "ubuntu-latest"
22+
permissions:
23+
contents: "read"
24+
id-token: "write"
25+
issues: "write"
26+
pull-requests: "write"
27+
steps:
28+
- name: "Mint identity token"
29+
id: "mint_identity_token"
30+
if: |-
31+
${{ vars.APP_ID }}
32+
uses: "actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b" # ratchet:actions/create-github-app-token@v2
33+
with:
34+
app-id: "${{ vars.APP_ID }}"
35+
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
36+
permission-contents: "read"
37+
permission-issues: "write"
38+
permission-pull-requests: "write"
39+
40+
- name: "Run Gemini CLI"
41+
id: "run_gemini"
42+
uses: "google-github-actions/run-gemini-cli@v0" # ratchet:exclude
43+
env:
44+
TITLE: "${{ github.event.pull_request.title || github.event.issue.title }}"
45+
DESCRIPTION: "${{ github.event.pull_request.body || github.event.issue.body }}"
46+
EVENT_NAME: "${{ github.event_name }}"
47+
GITHUB_TOKEN: "${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}"
48+
IS_PULL_REQUEST: "${{ !!github.event.pull_request }}"
49+
ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
50+
REPOSITORY: "${{ github.repository }}"
51+
ADDITIONAL_CONTEXT: "${{ inputs.additional_context }}"
52+
with:
53+
gcp_location: "${{ vars.GOOGLE_CLOUD_LOCATION }}"
54+
gcp_project_id: "${{ vars.GOOGLE_CLOUD_PROJECT }}"
55+
gcp_service_account: "${{ vars.SERVICE_ACCOUNT_EMAIL }}"
56+
gcp_workload_identity_provider: "${{ vars.GCP_WIF_PROVIDER }}"
57+
gemini_api_key: "${{ secrets.GEMINI_API_KEY }}"
58+
gemini_cli_version: "${{ vars.GEMINI_CLI_VERSION }}"
59+
gemini_debug: "${{ fromJSON(vars.DEBUG || vars.ACTIONS_STEP_DEBUG || false) }}"
60+
gemini_model: "${{ vars.GEMINI_MODEL }}"
61+
google_api_key: "${{ secrets.GOOGLE_API_KEY }}"
62+
use_gemini_code_assist: "${{ vars.GOOGLE_GENAI_USE_GCA }}"
63+
use_vertex_ai: "${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}"
64+
upload_artifacts: "${{ vars.UPLOAD_ARTIFACTS }}"
65+
workflow_name: "gemini-invoke"
66+
settings: |-
67+
{
68+
"model": {
69+
"maxSessionTurns": 25
70+
},
71+
"telemetry": {
72+
"enabled": true,
73+
"target": "local",
74+
"outfile": ".gemini/telemetry.log"
75+
},
76+
"mcpServers": {
77+
"github": {
78+
"command": "docker",
79+
"args": [
80+
"run",
81+
"-i",
82+
"--rm",
83+
"-e",
84+
"GITHUB_PERSONAL_ACCESS_TOKEN",
85+
"ghcr.io/github/github-mcp-server:v0.18.0"
86+
],
87+
"includeTools": [
88+
"add_issue_comment",
89+
"get_issue",
90+
"get_issue_comments",
91+
"list_issues",
92+
"search_issues",
93+
"create_pull_request",
94+
"pull_request_read",
95+
"list_pull_requests",
96+
"search_pull_requests",
97+
"create_branch",
98+
"create_or_update_file",
99+
"delete_file",
100+
"fork_repository",
101+
"get_commit",
102+
"get_file_contents",
103+
"list_commits",
104+
"push_files",
105+
"search_code"
106+
],
107+
"env": {
108+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
109+
}
110+
}
111+
},
112+
"tools": {
113+
"core": [
114+
"run_shell_command(cat)",
115+
"run_shell_command(echo)",
116+
"run_shell_command(grep)",
117+
"run_shell_command(head)",
118+
"run_shell_command(tail)"
119+
]
120+
}
121+
}
122+
prompt: "/gemini-invoke"

0 commit comments

Comments
 (0)