@@ -28,6 +28,11 @@ This document explains how to use the Gemini CLI on GitHub to automatically revi
28
28
- [ Security-Focused Review] ( #security-focused-review )
29
29
- [ Performance Review] ( #performance-review )
30
30
- [ Breaking Changes Check] ( #breaking-changes-check )
31
+ - [ Extending to Support Forks] ( #extending-to-support-forks )
32
+ - [ Understanding Fork Security Model] ( #understanding-fork-security-model )
33
+ - [ Implementation Approaches] ( #implementation-approaches )
34
+ - [ 1. Simple Fork Support (Recommended for Open Source)] ( #1-simple-fork-support-recommended-for-open-source )
35
+ - [ 2. Using ` pull_request_target ` Event] ( #2-using-pull_request_target-event )
31
36
32
37
## Overview
33
38
@@ -237,3 +242,102 @@ The AI prompt can be customized to:
237
242
```
238
243
@gemini-cli /review look for potential breaking changes and API compatibility
239
244
```
245
+
246
+ ## Extending to Support Forks
247
+
248
+ By default, this workflow is configured to work with pull requests from branches
249
+ within the same repository. The
250
+ [gemini-dispatch.yml](../gemini-dispatch/gemini-dispatch.yml) workflow includes
251
+ a condition that explicitly blocks pull requests from forks:
252
+
253
+ ```yaml
254
+ github.event.pull_request.head.repo.fork == false
255
+ ```
256
+
257
+ However, if you want to extend it to support pull requests from forked
258
+ repositories, there are several approaches depending on your authentication
259
+ setup and security requirements.
260
+
261
+ ### Understanding Fork Security Model
262
+
263
+ When pull requests come from forks, GitHub Actions restricts access to secrets
264
+ and repository tokens to prevent malicious code from accessing sensitive
265
+ information. However, the impact depends on what secrets are actually needed:
266
+
267
+ - ** Available from forks** : ` GITHUB_TOKEN ` (with limited permissions),
268
+ repository content, pull request data.
269
+ - ** Restricted from forks** : Base repository secrets and authentication.
270
+ - ** Workaround** : Forks can configure their own Google authentication as
271
+ described in the
272
+ [ Authentication documentation] ( ../../../docs/authentication.md ) .
273
+
274
+ ### Implementation Approaches
275
+
276
+ Depending on your security requirements and use case, you can choose from these
277
+ approaches:
278
+
279
+ #### 1. Simple Fork Support (Recommended for Open Source)
280
+
281
+ ** Best for** : Open source projects where contributors can provide their own
282
+ Google authentication.
283
+
284
+ ** How it works** : If forks have their own Google authentication configured, you
285
+ can enable fork support by simply removing the fork restriction condition in the
286
+ dispatch workflow. This works because:
287
+
288
+ - ** Gemini access** : The workflow can use the fork's Google authentication (see
289
+ [ Authentication documentation] ( ../../../docs/authentication.md ) ).
290
+ - ** GitHub access** : GitHub provides a default ` GITHUB_TOKEN ` with read access
291
+ to the repository and write access to pull requests.
292
+
293
+ ** Requirements** :
294
+ - Fork repositories must have Google authentication configured (see
295
+ [ Authentication documentation] ( ../../../docs/authentication.md ) ).
296
+ - Contributors are willing to use their own Gemini API quota.
297
+
298
+ ** Implementation** :
299
+ 1 . Remove the fork restriction in ` gemini-dispatch.yml ` :
300
+ ``` yaml
301
+ # Change this condition to remove the fork check
302
+ if : |-
303
+ (
304
+ github.event_name == 'pull_request'
305
+ # Remove this line: && github.event.pull_request.head.repo.fork == false
306
+ ) || (
307
+ # ... rest of conditions
308
+ )
309
+ ` ` `
310
+
311
+ 2. Document for contributors that they need to configure Google authentication
312
+ in their fork as described in the
313
+ [Authentication documentation](../../../docs/authentication.md).
314
+
315
+ **Benefits**: Simple, secure, no access to base repository secrets.
316
+ **Drawbacks**: Requires contributors to configure their own authentication.
317
+
318
+ #### 2. Using ` pull_request_target` Event
319
+
320
+ **Important Security Note**: Using `pull_request_target` can introduce security
321
+ vulnerabilities if not handled with extreme care. Because it runs in the context
322
+ of the base repository, it has access to secrets and other sensitive data.
323
+ Always ensure you are following security best practices, such as those outlined
324
+ in the linked resources, to prevent unauthorized access or code execution.
325
+
326
+ **Best for**: Private repositories where you want to provide API access centrally.
327
+
328
+ Modify the workflow to use `pull_request_target` instead of `pull_request`,
329
+ which runs with the base repository's permissions :
330
+
331
+ - **Benefits**: Full access to base repository secrets and permissions.
332
+ - **Security Considerations**: Requires careful code review and validation of
333
+ all fork contributions.
334
+ - **Resources**:
335
+ - [GitHub Docs : Using pull_request_target](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target).
336
+ - [Security Best Practices for pull_request_target](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
337
+ - [Safe Workflows for Forked Repositories](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
338
+ - **Best Practices**:
339
+ - Never execute untrusted code from forks without proper sandboxing.
340
+ - Validate all inputs from external pull requests.
341
+ - Review workflow changes carefully before implementing `pull_request_target`.
342
+ - Test security measures in a separate repository first.
343
+ - Monitor and audit fork-based workflow executions.
0 commit comments