Skip to content

Commit 96024f8

Browse files
committed
docs: add fork support documentation for PR review workflow
- Add comprehensive section on extending PR review workflow to support forks - Document simple fork support approach using contributor's own Google auth - Explain GitHub Actions security model for fork-based PRs - Provide implementation approaches from simple to advanced - Include security best practices and resources for pull_request_target - Reference centralized authentication documentation - Reorganize content with clear implementation approaches
1 parent e9848a9 commit 96024f8

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

examples/workflows/pr-review/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ This document explains how to use the Gemini CLI on GitHub to automatically revi
2828
- [Security-Focused Review](#security-focused-review)
2929
- [Performance Review](#performance-review)
3030
- [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)
3136

3237
## Overview
3338

@@ -237,3 +242,75 @@ The AI prompt can be customized to:
237242
```
238243
@gemini-cli /review look for potential breaking changes and API compatibility
239244
```
245+
246+
## Extending to Support Forks
247+
248+
By default, this workflow is configured to work with pull requests from branches within the same repository. The [gemini-dispatch.yml](../gemini-dispatch/gemini-dispatch.yml) workflow includes a condition that explicitly blocks pull requests from forks:
249+
250+
```yaml
251+
github.event.pull_request.head.repo.fork == false
252+
```
253+
254+
However, if you want to extend it to support pull requests from forked repositories, there are several approaches depending on your authentication setup and security requirements.
255+
256+
### Understanding Fork Security Model
257+
258+
When pull requests come from forks, GitHub Actions restricts access to secrets and repository tokens to prevent malicious code from accessing sensitive information. However, the impact depends on what secrets are actually needed:
259+
260+
- **Available from forks**: `GITHUB_TOKEN` (with limited permissions), repository content, pull request data.
261+
- **Restricted from forks**: Base repository secrets and authentication.
262+
- **Workaround**: Forks can configure their own Google authentication as described in the [Authentication documentation](../../../docs/authentication.md).
263+
264+
### Implementation Approaches
265+
266+
Depending on your security requirements and use case, you can choose from these approaches:
267+
268+
#### 1. Simple Fork Support (Recommended for Open Source)
269+
270+
**Best for**: Open source projects where contributors can provide their own Google authentication.
271+
272+
**How it works**: If forks have their own Google authentication configured, you can enable fork support by simply removing the fork restriction condition in the dispatch workflow. This works because:
273+
274+
- **Gemini access**: The workflow can use the fork's Google authentication (see [Authentication documentation](../../../docs/authentication.md)).
275+
- **GitHub access**: GitHub provides a default `GITHUB_TOKEN` with read access to the repository and write access to pull requests.
276+
277+
**Requirements**:
278+
- Fork repositories must have Google authentication configured (see [Authentication documentation](../../../docs/authentication.md)).
279+
- Contributors are willing to use their own Gemini API quota.
280+
281+
**Implementation**:
282+
1. Remove the fork restriction in `gemini-dispatch.yml`:
283+
```yaml
284+
# Change this condition to remove the fork check
285+
if: |-
286+
(
287+
github.event_name == 'pull_request'
288+
# Remove this line: && github.event.pull_request.head.repo.fork == false
289+
) || (
290+
# ... rest of conditions
291+
)
292+
```
293+
294+
2. Document for contributors that they need to configure Google authentication in their fork as described in the [Authentication documentation](../../../docs/authentication.md).
295+
296+
**Benefits**: Simple, secure, no access to base repository secrets.
297+
**Drawbacks**: Requires contributors to configure their own authentication.
298+
299+
#### 2. Using `pull_request_target` Event
300+
301+
**Best for**: Private repositories where you want to provide API access centrally.
302+
303+
Modify the workflow to use `pull_request_target` instead of `pull_request`, which runs with the base repository's permissions:
304+
305+
- **Benefits**: Full access to base repository secrets and permissions.
306+
- **Security Considerations**: Requires careful code review and validation of all fork contributions.
307+
- **Resources**:
308+
- [GitHub Docs: Using pull_request_target](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target).
309+
- [Security Best Practices for pull_request_target](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
310+
- [Safe Workflows for Forked Repositories](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
311+
- **Best Practices**:
312+
- Never execute untrusted code from forks without proper sandboxing.
313+
- Validate all inputs from external pull requests.
314+
- Review workflow changes carefully before implementing `pull_request_target`.
315+
- Test security measures in a separate repository first.
316+
- Monitor and audit fork-based workflow executions.

0 commit comments

Comments
 (0)