Skip to content

Commit a1ac5be

Browse files
authored
refactor(ci): prioritize event triggers in dispatch workflow (#366)
Refactor the gemini-dispatch workflow to make command handling more robust. The logic is reordered to check for event-based triggers (e.g., `pull_request.opened`, `issues.opened`) before parsing the content of a comment or issue body.
1 parent 879fbe9 commit a1ac5be

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

.github/workflows/gemini-dispatch.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ jobs:
4444
4545
dispatch:
4646
# For PRs: only if not from a fork
47-
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
4847
# For issues: only on open/reopen
48+
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
4949
if: |-
5050
(
5151
github.event_name == 'pull_request' &&
5252
github.event.pull_request.head.repo.fork == false
53+
) || (
54+
github.event_name == 'issues' &&
55+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
5356
) || (
5457
github.event.sender.type == 'User' &&
5558
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
5659
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)
6060
)
6161
runs-on: 'ubuntu-latest'
6262
permissions:
@@ -89,11 +89,15 @@ jobs:
8989
REQUEST: '${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}'
9090
with:
9191
script: |
92+
const eventType = process.env.EVENT_TYPE;
9293
const request = process.env.REQUEST;
93-
const eventType = process.env.EVENT_TYPE
9494
core.setOutput('request', request);
9595
96-
if (request.startsWith("@gemini-cli /review")) {
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")) {
97101
core.setOutput('command', 'review');
98102
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
99103
core.setOutput('additional_context', additionalContext);
@@ -102,13 +106,9 @@ jobs:
102106
} else if (request.startsWith("@gemini-cli /fix")) {
103107
core.setOutput('command', 'fix');
104108
} else if (request.startsWith("@gemini-cli")) {
105-
core.setOutput('command', 'invoke');
106109
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
110+
core.setOutput('command', 'invoke');
107111
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');
112112
} else {
113113
core.setOutput('command', 'fallthrough');
114114
}

examples/workflows/gemini-dispatch/gemini-dispatch.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ jobs:
4444
4545
dispatch:
4646
# For PRs: only if not from a fork
47-
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
4847
# For issues: only on open/reopen
48+
# For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
4949
if: |-
5050
(
5151
github.event_name == 'pull_request' &&
5252
github.event.pull_request.head.repo.fork == false
53+
) || (
54+
github.event_name == 'issues' &&
55+
contains(fromJSON('["opened", "reopened"]'), github.event.action)
5356
) || (
5457
github.event.sender.type == 'User' &&
5558
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
5659
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)
6060
)
6161
runs-on: 'ubuntu-latest'
6262
permissions:
@@ -89,24 +89,24 @@ jobs:
8989
REQUEST: '${{ github.event.comment.body || github.event.review.body || github.event.issue.body }}'
9090
with:
9191
script: |
92+
const eventType = process.env.EVENT_TYPE;
9293
const request = process.env.REQUEST;
93-
const eventType = process.env.EVENT_TYPE
9494
core.setOutput('request', request);
9595
96-
if (request.startsWith("@gemini-cli /review")) {
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")) {
97101
core.setOutput('command', 'review');
98102
const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
99103
core.setOutput('additional_context', additionalContext);
100104
} else if (request.startsWith("@gemini-cli /triage")) {
101105
core.setOutput('command', 'triage');
102106
} else if (request.startsWith("@gemini-cli")) {
103-
core.setOutput('command', 'invoke');
104107
const additionalContext = request.replace(/^@gemini-cli/, '').trim();
108+
core.setOutput('command', 'invoke');
105109
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');
110110
} else {
111111
core.setOutput('command', 'fallthrough');
112112
}

0 commit comments

Comments
 (0)