Skip to content

Commit a20a354

Browse files
committed
NO-JIRA: Replace the Gemini PR review workflow with a streamlined Gemini Dispatch workflow
1 parent 381e5b5 commit a20a354

File tree

2 files changed

+426
-410
lines changed

2 files changed

+426
-410
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
name: '🔀 Gemini Dispatch'
3+
4+
"on":
5+
pull_request_review_comment:
6+
types:
7+
- 'created'
8+
pull_request_review:
9+
types:
10+
- 'submitted'
11+
pull_request:
12+
types:
13+
- 'opened'
14+
issues:
15+
types:
16+
- 'opened'
17+
- 'reopened'
18+
issue_comment:
19+
types:
20+
- 'created'
21+
22+
defaults:
23+
run:
24+
shell: 'bash'
25+
26+
jobs:
27+
debugger:
28+
if: |-
29+
${{ fromJSON(vars.DEBUG || vars.ACTIONS_STEP_DEBUG || false) }}
30+
runs-on: 'ubuntu-latest'
31+
permissions:
32+
contents: 'read'
33+
steps:
34+
- name: 'Print context for debugging'
35+
env:
36+
DEBUG_event_name: '${{ github.event_name }}'
37+
DEBUG_event__action: '${{ github.event.action }}'
38+
DEBUG_event__comment__author_association: '${{ github.event.comment.author_association }}'
39+
DEBUG_event__issue__author_association: '${{ github.event.issue.author_association }}'
40+
DEBUG_event__pull_request__author_association: '${{ 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 or when author is collaborator
48+
# For issues: only on open/reopen
49+
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
50+
if: |-
51+
(
52+
github.event_name == 'pull_request' &&
53+
(
54+
github.event.pull_request.head.repo.fork == false ||
55+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association)
56+
)
57+
) || (
58+
github.event_name == 'issues' &&
59+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
60+
) || (
61+
github.event.sender.type == 'User' &&
62+
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
63+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association)
64+
)
65+
runs-on: 'ubuntu-latest'
66+
permissions:
67+
contents: 'read'
68+
issues: 'write'
69+
pull-requests: 'write'
70+
outputs:
71+
command: '${{ steps.extract_command.outputs.command }}'
72+
request: '${{ steps.extract_command.outputs.request }}'
73+
additional_context: '${{ steps.extract_command.outputs.additional_context }}'
74+
issue_number: '${{ github.event.pull_request.number || github.event.issue.number }}'
75+
steps:
76+
- name: 'Mint identity token'
77+
id: 'mint_identity_token'
78+
if: |-
79+
${{ vars.APP_ID }}
80+
uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2
81+
with:
82+
app-id: '${{ vars.APP_ID }}'
83+
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
84+
permission-contents: 'read'
85+
permission-issues: 'write'
86+
permission-pull-requests: 'write'
87+
88+
- name: 'Extract command'
89+
id: 'extract_command'
90+
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
91+
env:
92+
EVENT_TYPE: '${{ github.event_name }}.${{ github.event.action }}'
93+
REQUEST: '${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}'
94+
with:
95+
script: |
96+
const eventType = process.env.EVENT_TYPE;
97+
const request = process.env.REQUEST;
98+
core.setOutput('request', request);
99+
100+
if (eventType === 'pull_request.opened') {
101+
core.setOutput('command', 'review');
102+
} else if (['issues.opened', 'issues.reopened'].includes(eventType)) {
103+
core.setOutput('command', 'triage');
104+
} else if (request.startsWith("@gemini-cli /review")) {
105+
core.setOutput('command', 'review');
106+
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
107+
core.setOutput('additional_context', additionalContext);
108+
} else if (request.startsWith("@gemini-cli /triage")) {
109+
core.setOutput('command', 'triage');
110+
} else if (request.startsWith("@gemini-cli")) {
111+
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
112+
core.setOutput('command', 'invoke');
113+
core.setOutput('additional_context', additionalContext);
114+
} else {
115+
core.setOutput('command', 'fallthrough');
116+
}
117+
118+
- name: 'Acknowledge request'
119+
env:
120+
GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}'
121+
ISSUE_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}'
122+
MESSAGE: |-
123+
🤖 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.
124+
REPOSITORY: '${{ github.repository }}'
125+
run: |-
126+
gh issue comment "${ISSUE_NUMBER}" \
127+
--body "${MESSAGE}" \
128+
--repo "${REPOSITORY}"
129+
130+
review:
131+
needs: 'dispatch'
132+
if: |-
133+
${{ needs.dispatch.outputs.command == 'review' }}
134+
uses: './.github/workflows/gemini-pr-review.yml'
135+
permissions:
136+
contents: 'read'
137+
id-token: 'write'
138+
issues: 'write'
139+
pull-requests: 'write'
140+
with:
141+
additional_context: '${{ needs.dispatch.outputs.additional_context }}'
142+
secrets: 'inherit'
143+
144+
# triage:
145+
# needs: 'dispatch'
146+
# if: |-
147+
# ${{ needs.dispatch.outputs.command == 'triage' }}
148+
# uses: './.github/workflows/gemini-triage.yml'
149+
# permissions:
150+
# contents: 'read'
151+
# id-token: 'write'
152+
# issues: 'write'
153+
# pull-requests: 'write'
154+
# with:
155+
# additional_context: '${{ needs.dispatch.outputs.additional_context }}'
156+
# secrets: 'inherit'
157+
#
158+
# invoke:
159+
# needs: 'dispatch'
160+
# if: |-
161+
# ${{ needs.dispatch.outputs.command == 'invoke' }}
162+
# uses: './.github/workflows/gemini-invoke.yml'
163+
# permissions:
164+
# contents: 'read'
165+
# id-token: 'write'
166+
# issues: 'write'
167+
# pull-requests: 'write'
168+
# with:
169+
# additional_context: '${{ needs.dispatch.outputs.additional_context }}'
170+
# secrets: 'inherit'
171+
172+
fallthrough:
173+
needs:
174+
- 'dispatch'
175+
- 'review'
176+
# - 'triage'
177+
# - 'invoke'
178+
if: |-
179+
${{ always() && !cancelled() && (failure() || needs.dispatch.outputs.command == 'fallthrough') }}
180+
runs-on: 'ubuntu-latest'
181+
permissions:
182+
contents: 'read'
183+
issues: 'write'
184+
pull-requests: 'write'
185+
steps:
186+
- name: 'Mint identity token'
187+
id: 'mint_identity_token'
188+
if: |-
189+
${{ vars.APP_ID }}
190+
uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2
191+
with:
192+
app-id: '${{ vars.APP_ID }}'
193+
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
194+
permission-contents: 'read'
195+
permission-issues: 'write'
196+
permission-pull-requests: 'write'
197+
198+
- name: 'Send failure comment'
199+
env:
200+
GITHUB_TOKEN: '${{ 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)