Skip to content

Commit 8aa93f9

Browse files
authored
Enable gemini cli workflows (#711)
Copy gemini cli workflows
1 parent fe19930 commit 8aa93f9

File tree

5 files changed

+1255
-0
lines changed

5 files changed

+1255
-0
lines changed
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 comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
48+
# For issues: only on open/reopen
49+
if: |-
50+
(
51+
github.event_name == 'pull_request' &&
52+
github.event.pull_request.head.repo.fork == false
53+
) || (
54+
github.event.sender.type == 'User' &&
55+
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
56+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association)
57+
) || (
58+
github.event_name == 'issues' &&
59+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
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 request = process.env.REQUEST;
93+
const eventType = process.env.EVENT_TYPE
94+
core.setOutput('request', request);
95+
96+
if (request.startsWith("@gemini-cli /review")) {
97+
core.setOutput('command', 'review');
98+
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
99+
core.setOutput('additional_context', additionalContext);
100+
} else if (request.startsWith("@gemini-cli /triage")) {
101+
core.setOutput('command', 'triage');
102+
} else if (request.startsWith("@gemini-cli")) {
103+
core.setOutput('command', 'invoke');
104+
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
105+
core.setOutput('additional_context', additionalContext);
106+
} else if (eventType === 'pull_request.opened') {
107+
core.setOutput('command', 'review');
108+
} else if (['issues.opened', 'issues.reopened'].includes(eventType)) {
109+
core.setOutput('command', 'triage');
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}"

0 commit comments

Comments
 (0)