Skip to content

Commit 06796a4

Browse files
committed
Add gemini-cli GitHub Actions workflows
1 parent 0288dfa commit 06796a4

File tree

5 files changed

+1221
-0
lines changed

5 files changed

+1221
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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:
40+
"${{ github.event.pull_request.author_association }}"
41+
DEBUG_event__review__author_association: "${{ github.event.review.author_association }}"
42+
DEBUG_event: "${{ toJSON(github.event) }}"
43+
run: |-
44+
env | grep '^DEBUG_'
45+
46+
dispatch:
47+
# For PRs: only if not from a fork
48+
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
49+
# For issues: only on open/reopen
50+
if: |-
51+
(
52+
github.event_name == 'pull_request' &&
53+
github.event.pull_request.head.repo.fork == false
54+
) || (
55+
github.event.sender.type == 'User' &&
56+
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
57+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association)
58+
) || (
59+
github.event_name == 'issues' &&
60+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
61+
)
62+
runs-on: "ubuntu-latest"
63+
permissions:
64+
contents: "read"
65+
issues: "write"
66+
pull-requests: "write"
67+
outputs:
68+
command: "${{ steps.extract_command.outputs.command }}"
69+
request: "${{ steps.extract_command.outputs.request }}"
70+
additional_context: "${{ steps.extract_command.outputs.additional_context }}"
71+
issue_number: "${{ github.event.pull_request.number || github.event.issue.number }}"
72+
steps:
73+
- name: "Mint identity token"
74+
id: "mint_identity_token"
75+
if: |-
76+
${{ vars.APP_ID }}
77+
uses: "actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b" # ratchet:actions/create-github-app-token@v2
78+
with:
79+
app-id: "${{ vars.APP_ID }}"
80+
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
81+
permission-contents: "read"
82+
permission-issues: "write"
83+
permission-pull-requests: "write"
84+
85+
- name: "Extract command"
86+
id: "extract_command"
87+
uses: "actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea" # ratchet:actions/github-script@v7
88+
env:
89+
EVENT_TYPE: "${{ github.event_name }}.${{ github.event.action }}"
90+
REQUEST:
91+
"${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}"
92+
with:
93+
script: |
94+
const request = process.env.REQUEST;
95+
const eventType = process.env.EVENT_TYPE
96+
core.setOutput('request', request);
97+
98+
if (request.startsWith("@gemini-cli /review")) {
99+
core.setOutput('command', 'review');
100+
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
101+
core.setOutput('additional_context', additionalContext);
102+
} else if (request.startsWith("@gemini-cli /triage")) {
103+
core.setOutput('command', 'triage');
104+
} else if (request.startsWith("@gemini-cli")) {
105+
core.setOutput('command', 'invoke');
106+
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
107+
core.setOutput('additional_context', additionalContext);
108+
} else if (eventType === 'pull_request.opened') {
109+
core.setOutput('command', 'review');
110+
} else if (['issues.opened', 'issues.reopened'].includes(eventType)) {
111+
core.setOutput('command', 'triage');
112+
} else {
113+
core.setOutput('command', 'fallthrough');
114+
}
115+
116+
- name: "Acknowledge request"
117+
env:
118+
GITHUB_TOKEN:
119+
"${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}"
120+
ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
121+
MESSAGE: |-
122+
🤖 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.
123+
REPOSITORY: "${{ github.repository }}"
124+
run: |-
125+
gh issue comment "${ISSUE_NUMBER}" \
126+
--body "${MESSAGE}" \
127+
--repo "${REPOSITORY}"
128+
129+
review:
130+
needs: "dispatch"
131+
if: |-
132+
${{ needs.dispatch.outputs.command == 'review' }}
133+
uses: "./.github/workflows/gemini-review.yml"
134+
permissions:
135+
contents: "read"
136+
id-token: "write"
137+
issues: "write"
138+
pull-requests: "write"
139+
with:
140+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
141+
secrets: "inherit"
142+
143+
triage:
144+
needs: "dispatch"
145+
if: |-
146+
${{ needs.dispatch.outputs.command == 'triage' }}
147+
uses: "./.github/workflows/gemini-triage.yml"
148+
permissions:
149+
contents: "read"
150+
id-token: "write"
151+
issues: "write"
152+
pull-requests: "write"
153+
with:
154+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
155+
secrets: "inherit"
156+
157+
invoke:
158+
needs: "dispatch"
159+
if: |-
160+
${{ needs.dispatch.outputs.command == 'invoke' }}
161+
uses: "./.github/workflows/gemini-invoke.yml"
162+
permissions:
163+
contents: "read"
164+
id-token: "write"
165+
issues: "write"
166+
pull-requests: "write"
167+
with:
168+
additional_context: "${{ needs.dispatch.outputs.additional_context }}"
169+
secrets: "inherit"
170+
171+
fallthrough:
172+
needs:
173+
- "dispatch"
174+
- "review"
175+
- "triage"
176+
- "invoke"
177+
if: |-
178+
${{ always() && !cancelled() && (failure() || needs.dispatch.outputs.command == 'fallthrough') }}
179+
runs-on: "ubuntu-latest"
180+
permissions:
181+
contents: "read"
182+
issues: "write"
183+
pull-requests: "write"
184+
steps:
185+
- name: "Mint identity token"
186+
id: "mint_identity_token"
187+
if: |-
188+
${{ vars.APP_ID }}
189+
uses: "actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b" # ratchet:actions/create-github-app-token@v2
190+
with:
191+
app-id: "${{ vars.APP_ID }}"
192+
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
193+
permission-contents: "read"
194+
permission-issues: "write"
195+
permission-pull-requests: "write"
196+
197+
- name: "Send failure comment"
198+
env:
199+
GITHUB_TOKEN:
200+
"${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}"
201+
ISSUE_NUMBER: "${{ github.event.pull_request.number || github.event.issue.number }}"
202+
MESSAGE: |-
203+
🤖 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.
204+
REPOSITORY: "${{ github.repository }}"
205+
run: |-
206+
gh issue comment "${ISSUE_NUMBER}" \
207+
--body "${MESSAGE}" \
208+
--repo "${REPOSITORY}"

0 commit comments

Comments
 (0)