77 pull_request_review :
88 types :
99 - ' submitted'
10- pull_request :
11- types :
12- - ' opened'
13- - ' ready_for_review'
14- issues :
15- types :
16- - ' opened'
17- - ' reopened'
1810 issue_comment :
1911 types :
2012 - ' created'
@@ -44,19 +36,11 @@ jobs:
4436 env | grep '^DEBUG_'
4537
4638 dispatch :
47- # For PRs: only if not from a fork
48- # For issues: only on open/reopen
49- # For comments: only if user types @gemini-cli and is OWNER/MEMBER/COLLABORATOR
39+ # Only trigger if user types @gemini-cli and author association is OWNER, MEMBER, or COLLABORATOR
5040 if : |-
51- (
52- github.event_name == 'pull_request' &&
53- github.event.pull_request.head.repo.fork == false &&
54- github.event.pull_request.draft == false
55- ) || (
56- github.event.sender.type == 'User' &&
57- startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
58- contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association)
59- )
41+ github.event.sender.type == 'User' &&
42+ startsWith(github.event.comment.body || github.event.review.body, '@gemini-cli') &&
43+ contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association)
6044 runs-on : ' ubuntu-latest'
6145 permissions :
6246 contents : ' read'
@@ -82,22 +66,43 @@ jobs:
8266
8367 - name : ' Extract command'
8468 id : ' extract_command'
85- uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea ' # ratchet:actions/github-script@v7
69+ uses : ' actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd ' # ratchet:actions/github-script@v8.0.0
8670 env :
87- EVENT_TYPE : ' ${{ github.event_name }}.${{ github.event.action }}'
88- REQUEST : ' ${{ github.event.comment.body || github.event.review.body || github.event. issue.body }}'
71+ REQUEST : ' ${{ github.event.comment.body || github.event.review.body }}'
72+ IS_PR : ' ${{ !!( github.event.pull_request || github.event.issue.pull_request) }}'
8973 with :
9074 script : |
91- const eventType = process.env.EVENT_TYPE;
9275 const request = process.env.REQUEST;
76+ const isPr = process.env.IS_PR === 'true';
9377 core.setOutput('request', request);
9478
95- if (eventType === 'pull_request.opened' || eventType === 'pull_request.ready_for_review') {
96- core.setOutput('command', 'review');
97- } else if (request.startsWith("@gemini-cli /review")) {
98- core.setOutput('command', 'review');
99- const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
100- core.setOutput('additional_context', additionalContext);
79+ // Ensure request is on a PR targeting the main branch
80+ let baseRef = '';
81+ if (context.eventName === 'pull_request_review' || context.eventName === 'pull_request_review_comment') {
82+ baseRef = context.payload.pull_request.base.ref;
83+ } else if (context.eventName === 'issue_comment' && context.payload.issue.pull_request) {
84+ const pr = await github.rest.pulls.get({
85+ owner: context.repo.owner,
86+ repo: context.repo.repo,
87+ pull_number: context.payload.issue.number
88+ });
89+ baseRef = pr.data.base.ref;
90+ }
91+
92+ if (isPr && baseRef !== 'main') {
93+ console.log(`Skipping: PR targets '${baseRef}', but only 'main' is allowed.`);
94+ core.setOutput('command', 'fallthrough');
95+ return;
96+ }
97+
98+ if (request.startsWith("@gemini-cli /review")) {
99+ if (isPr) {
100+ core.setOutput('command', 'review');
101+ const additionalContext = request.replace(/^@gemini-cli \/review/, '').trim();
102+ core.setOutput('additional_context', additionalContext);
103+ } else {
104+ core.setOutput('command', 'fallthrough');
105+ }
101106 } else if (request.startsWith("@gemini-cli")) {
102107 const additionalContext = request.replace(/^@gemini-cli/, '').trim();
103108 core.setOutput('command', 'invoke');
0 commit comments