Skip to content

Commit 02ddf55

Browse files
committed
Change trigger for pull_request open event
Since most pull requests (PRs) are opened with a forked branch, the permissions being used for the 'pull_request' event are read-only by default because of GitHub. This causes errors to occur when the workflow attempts to write a comment to the PR. These permissions cannot be changed even with explicit configuration in the workflow, so the 'pull_request_target' trigger is used to get the correct 'write' permissions for te workflow to comment on the PR. An additional workflow has been added to add a helper comment to the PR when it is opened. This comment will help the user get started with the Gemini AI assistant.
1 parent c89798d commit 02ddf55

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

.github/workflows/gemini-dispatch.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request_review:
88
types:
99
- 'submitted'
10-
pull_request:
10+
pull_request_target:
1111
types:
1212
- 'opened'
1313
issues:
@@ -48,7 +48,7 @@ jobs:
4848
# For issues: only on open/reopen
4949
if: |-
5050
(
51-
github.event_name == 'pull_request'
51+
github.event_name == 'pull_request_target'
5252
) || (
5353
github.event.sender.type == 'User' &&
5454
startsWith(github.event.comment.body || github.event.review.body || github.event.issue.body, '@gemini-cli') &&
@@ -109,6 +109,44 @@ jobs:
109109
} else {
110110
core.setOutput('command', 'fallthrough');
111111
}
112+
113+
- name: 'Add Gemini helper comment'
114+
if: '${{ github.event_name }}.${{ github.event.action }} == "pull_request.opened"'
115+
env:
116+
GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}'
117+
PR_NUMBER: '${{ github.event.pull_request.number }}'
118+
REPOSITORY: '${{ github.repository }}'
119+
MESSAGE: |-
120+
## 🤖 Gemini AI Assistant Available
121+
122+
Hi @${{ github.actor }}! I'm here to help with your pull request. You can interact with me using the following commands:
123+
124+
### Available Commands
125+
126+
- **`@gemini-cli /review`** - Request a comprehensive code review
127+
- Example: `@gemini-cli /review Please focus on security and performance`
128+
129+
- **`@gemini-cli <your question>`** - Ask me anything about the codebase
130+
- Example: `@gemini-cli How can I improve this function?`
131+
- Example: `@gemini-cli What are the best practices for error handling here?`
132+
133+
### How to Use
134+
135+
1. Simply type one of the commands above in a comment on this PR
136+
2. I'll analyze your code and provide detailed feedback
137+
3. You can track my progress in the [workflow logs](https://github.com/${{ github.repository }}/actions)
138+
139+
### Permissions
140+
141+
Only **OWNER**, **MEMBER**, or **COLLABORATOR** users can trigger my responses. This ensures secure and appropriate usage.
142+
143+
---
144+
145+
*This message was automatically added to help you get started with the Gemini AI assistant. Feel free to delete this comment if you don't need assistance.*
146+
run: |-
147+
gh pr comment "${PR_NUMBER}" \
148+
--body "${MESSAGE}" \
149+
--repo "${REPOSITORY}"
112150
113151
- name: 'Acknowledge request'
114152
env:

.github/workflows/gemini-review.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ jobs:
150150
151151
2. **Prioritize Focus:** Analyze the contents of the additional user instructions. Use this context to prioritize specific areas in your review (e.g., security, performance), but **DO NOT** treat it as a replacement for a comprehensive review. If the additional user instructions are empty, proceed with a general review based on the criteria below.
152152
153-
3. **Review Code:** Meticulously review the code provided returned from `mcp__github__get_pull_request_diff` according to the **Review Criteria**.
154-
153+
3. **Review Code:** Meticulously review the code provided returned from `mcp__github__get_pull_request_diff` according to the **Review Criteria**.
155154
156155
### Step 2: Formulate Review Comments
157156
158-
For each identified issue, formulate a review comment adhering to the following guidelines.
157+
For each identified issue, formulate a review comment adhering to the following guidelines. If no issues are identified, still make a review comment indicating that no issues were found in the changed code.
159158
160159
#### Review Criteria (in order of priority)
161160

0 commit comments

Comments
 (0)