Skip to content

Commit c496e7a

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

File tree

2 files changed

+427
-410
lines changed

2 files changed

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

0 commit comments

Comments
 (0)