Skip to content

docs: add pull_request_target guide for fork contribution support - #2501

Merged
naorpeled merged 2 commits into
The-PR-Agent:mainfrom
utsab345:docs/fork-contribution-support
Jul 5, 2026
Merged

naorpeled merged 2 commits into
The-PR-Agent:mainfrom
utsab345:docs/fork-contribution-support

Conversation

@utsab345

@utsab345 utsab345 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds documentation explaining how to use the pull_request_target event to enable PR-Agent on PRs from forked repositories (external contributions).

The GitHub Action runner already supports this event type (pr_agent/servers/github_action_runner.py:110), but no documentation existed showing users how to configure it.

Changes

  • docs/docs/installation/github.md: Added new subsection #### Using with pull_request_target (fork/contribution support) with a complete YAML example, explanation of why pull_request doesn't work for forks, and a security warning box.
  • docs/docs/usage-guide/automations_and_usage.md: Added a tip admonition in the GitHub Action section pointing to the new fork contribution guide.

Closes #2500

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (3) 📜 Skill insights (0)

Context used

Grey Divider


Action required

1. Incomplete pull_request_target security guidance 📎 Requirement gap ⛨ Security
Description
The fork-support guide recommends pull_request_target with actions/checkout using
allow-unsafe-pr-checkout: true without clearly documenting GitHub’s safer checkout defaults
change, or distinguishing safe versus unsafe checkout patterns and when/why they apply. This can
lead users to copy an unnecessary, high-risk checkout configuration even though PR-Agent’s action
runner can operate via the PR URL from the event payload without needing PR code checked out.
Code

docs/docs/installation/github.md[R57-95]

+#### Using with pull_request_target (fork/contribution support)
+
+By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.
+
+To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.
+
+```yaml
+name: PR Agent
+on:
+  pull_request_target:
+    types: [opened, reopened, synchronize, ready_for_review, review_requested]
+  issue_comment:
+jobs:
+  pr_agent_job:
+    if: ${{ github.event.sender.type != 'Bot' && (github.event_name == 'pull_request_target' || github.event.issue.pull_request) }}
+    runs-on: ubuntu-latest
+    permissions:
+      issues: write
+      pull-requests: write
+      contents: write
+    steps:
+      - name: Checkout PR code
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          allow-unsafe-pr-checkout: true
+      - name: PR Agent action step
+        uses: the-pr-agent/pr-agent@main
+        env:
+          OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          github_action_config.pr_actions: '["opened", "reopened", "synchronize", "ready_for_review", "review_requested"]'
+```
+
+!!! warning "Security considerations"
+    Using `pull_request_target` requires extra care. The `actions/checkout` step with `allow-unsafe-pr-checkout: true` checks out the PR's code, which could contain modified workflows. To mitigate risks, consider:
+    - Using `pull_request_target` only when you need fork support
+    - Reviewing the [GitHub security guide on pull_request_target](https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target)
+    - Avoiding running additional build steps from the checked-out PR code
Evidence
PR Compliance ID 7 requires that documentation covering pull_request_target include a security
section that references GitHub’s official guidance, mentions the safer checkout defaults change, and
explicitly explains safe vs. unsafe checkout patterns (including when/why allow-unsafe-pr-checkout
and pinning ref to the head SHA are used); however, the added section only provides a warning and
a GitHub link and does not lay out these patterns or the defaults change. Additionally, the action
runner code path derives pr_url from the GitHub event payload and invokes PR-Agent tools using
that URL, indicating PR-Agent execution does not depend on checked-out workspace files, so
recommending an unsafe checkout in the default example increases risk without being required for
PR-Agent itself.

Document secure usage of pull_request_target with actions/checkout for PR Agent
docs/docs/installation/github.md[57-95]
pr_agent/servers/github_action_runner.py[110-187]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The documentation’s `pull_request_target` example includes an `actions/checkout` step with `allow-unsafe-pr-checkout: true`, but it does not (a) reference GitHub’s safer checkout defaults change, (b) clearly explain safe vs. unsafe checkout patterns and when/why to use mitigations like pinning `ref` to the PR head SHA, or (c) clarify that PR-Agent itself can run using the PR URL (via GitHub API) and therefore does not require checking out PR code. We want the docs to reduce the chance users copy-paste an unnecessary, high-risk checkout configuration while still providing accurate, compliant guidance for cases where checkout is truly needed.
## Issue Context
This guide is likely to be adopted verbatim in public repositories that accept fork PRs, so ambiguous or default unsafe checkout guidance increases real-world security risk. Compliance requires explicit, `pull_request_target`-specific guidance that references GitHub’s official recommendations and the safer defaults change, and that clearly distinguishes safe vs. unsafe patterns (including when/why `allow-unsafe-pr-checkout` is used and why pinning `ref` to a head SHA can be important). Also, PR-Agent’s action runner operates off the PR URL derived from the event payload, so checkout is not required for PR-Agent execution and should not be implied as necessary.
## Fix Focus Areas
- docs/docs/installation/github.md[57-95]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Issue_comment checkout ref invalid 🐞 Bug ≡ Correctness
Description
The new workflow example always runs actions/checkout with `ref: ${{
github.event.pull_request.head.sha }}, but the same job is also triggered by issue_comment`, where
github.event.pull_request is not present. This can break comment-triggered PR-Agent commands (job
fails or checks out the wrong ref) in the documented fork-support setup.
Code

docs/docs/installation/github.md[R78-83]

+      - name: Checkout PR code
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          allow-unsafe-pr-checkout: true
+      - name: PR Agent action step
Evidence
issue_comment events are processed using event_payload.issue.pull_request.url (not
event_payload.pull_request.*), and the unit test payload for issue_comment contains no
pull_request object—so the docs example’s github.event.pull_request.head.sha dereference is
invalid for comment-triggered runs.

pr_agent/servers/github_action_runner.py[192-237]
tests/unittest/test_github_action_runner_core.py[152-163]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The docs workflow listens to both `pull_request_target` and `issue_comment`, but unconditionally uses `github.event.pull_request.head.sha` in the checkout step. For `issue_comment` events the payload does not include `pull_request`, so the example can fail when users comment on PRs.
### Issue Context
PR-Agent’s GitHub Action runner handles `issue_comment` by using `event_payload.issue.pull_request.url` and does not require a local checkout.
### Fix Focus Areas
- docs/docs/installation/github.md[78-89]
### Proposed fix
Choose one of:
1) Remove the checkout step entirely from this example (PR-Agent runs via PR URL / API), OR
2) Make the checkout step conditional:
 - `if: ${{ github.event_name == 'pull_request_target' }}`
 - and avoid referencing `github.event.pull_request.*` for `issue_comment` runs (either skip checkout on comments or use a ref expression valid for comment events, e.g. `refs/pull/${{ github.event.issue.number }}/head`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Checkout guidance contradicts tip 📎 Requirement gap ⚙ Maintainability ⭐ New
Description
The fork-support documentation claims the PR code is checked out manually using actions/checkout,
but the same section later says no local checkout is needed and the example workflow omits checkout.
This inconsistency makes it unclear what the recommended fork-safe configuration is and whether
checkout is required for PR-Agent to run.
Code

docs/docs/installation/github.md[61]

+To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.
Evidence
PR Compliance ID 6 requires clear documentation for configuring PR-Agent on fork-based PRs, but the
added fork-support section currently provides conflicting guidance: it states the PR code is checked
out manually with actions/checkout while an adjacent tip and the accompanying YAML example
indicate checkout is unnecessary. This is further supported by the runner behavior described in the
inputs, which relies on PR URLs/event payload and GitHub API rather than a workspace checkout,
making the “manual checkout” phrasing misleading and likely to cause users to add unnecessary
checkout steps.

Document supported setup for PR Agent on public repos with fork-based contributions
docs/docs/installation/github.md[59-62]
docs/docs/installation/github.md[61-88]
pr_agent/servers/github_action_runner.py[68-85]
pr_agent/servers/github_action_runner.py[110-187]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The fork-support guide contains contradictory guidance: it states that PR code is checked out manually with `actions/checkout`, but the example workflow omits `actions/checkout` and the tip says no local checkout is needed. Align the narrative text with the intended/actual behavior so users understand the recommended fork-safe configuration and whether checkout is required.

## Issue Context
PR Compliance ID 6 requires the fork-based contribution setup to be clearly documented with a recommended configuration. Additionally, PR-Agent’s GitHub Action runner operates using the GitHub event payload/PR URLs and GitHub API, so the current “manual checkout” statement is misleading relative to the example and tip; the docs should either remove that clause or clearly state checkout is optional and generally should be avoided unless explicitly needed.

## Fix Focus Areas
- docs/docs/installation/github.md[59-62]
- docs/docs/installation/github.md[61-62]
- docs/docs/installation/github.md[86-88]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Fork token behavior misstated 🐞 Bug ≡ Correctness ⭐ New
Description
The new fork-support section says forked pull_request runs “won’t be able to access” the
GITHUB_TOKEN secret, but elsewhere the same doc states GITHUB_TOKEN is automatically created;
the practical fork limitation is typically restricted token permissions and missing repo secrets
(e.g., OPENAI_KEY). This wording can mislead users about the root cause of failures (permission
errors vs missing token/secret).
Code

docs/docs/installation/github.md[R59-60]

+By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.
+
Evidence
The same page states GITHUB_TOKEN is automatically created, contradicting the new claim that it
can’t be accessed; the GitHub Action runner also hard-requires GITHUB_TOKEN to be set, indicating
it’s treated as an always-provided runtime credential rather than a repo secret in code.

docs/docs/installation/github.md[40-60]
pr_agent/servers/github_action_runner.py[33-52]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The fork-support section describes fork PR failures as an inability to access the `GITHUB_TOKEN` secret, which is misleading and contradicts earlier text in the same doc.

### Issue Context
- This guide is meant to help users understand why `pull_request` doesn’t work for forks.
- The key distinction is repository secrets (e.g. `OPENAI_KEY`) vs the default `GITHUB_TOKEN` and its permission scope on fork PRs.

### Fix Focus Areas
- docs/docs/installation/github.md[59-61]

### Expected fix
Rewrite the explanation to distinguish:
- repo secrets are not exposed on fork PRs under `pull_request` (e.g. `OPENAI_KEY`), and
- the GitHub-provided token exists but may be read-only / insufficient to post comments on fork PRs.
Avoid calling `GITHUB_TOKEN` a normal repo secret in this context.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Unpinned action ref 🐞 Bug ⛨ Security ⭐ New
Description
The pull_request_target example runs uses: the-pr-agent/pr-agent@main in a workflow that has
access to repository secrets, meaning each run executes whatever code is currently on main. This
is a supply-chain/reproducibility risk because upstream changes (or compromise) would execute with
secret access.
Code

docs/docs/installation/github.md[R78-83]

+      - name: PR Agent action step
+        uses: the-pr-agent/pr-agent@main
+        env:
+          OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          github_action_config.pr_actions: '["opened", "reopened", "synchronize", "ready_for_review", "review_requested"]'
Evidence
The documentation example uses a mutable @main ref. The repository’s action.yaml defines the
action behavior from this repo (Docker-based), so using a moving ref means the executed action
implementation can change over time without workflow changes.

docs/docs/installation/github.md[78-83]
action.yaml[1-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The workflow example references the action via a moving branch (`@main`) in a secrets-enabled `pull_request_target` workflow.

### Issue Context
This doc section is specifically about enabling fork support with `pull_request_target`, which runs with base-repo privileges and secrets.

### Fix Focus Areas
- docs/docs/installation/github.md[78-83]

### Expected fix
Update the example to use a pinned ref (preferably a full commit SHA, or at least a released version tag), and optionally add a short note advising users to periodically update the pin.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (1)
6. No internal workflow clarification 📎 Requirement gap ⚙ Maintainability
Description
The new documentation does not explain how PR-Agent itself is run in the pr-agent repository
(e.g., workflow triggers) versus the recommended public setup for forked contributions. This can
leave users uncertain about the "official"/intended configuration for public repos.
Code

docs/docs/installation/github.md[R57-62]

+#### Using with pull_request_target (fork/contribution support)
+
+By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.
+
+To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.
+
Evidence
PR Compliance ID 8 requires docs to explicitly explain how PR-Agent is run in the pr-agent
repository today and why that differs from recommended public configuration. The added fork-support
docs provide a recommended pull_request_target setup but do not mention the repository’s own
workflow_dispatch-only workflow, creating the ambiguity described by the rule.

Clarify how PR Agent itself is run (internal repo) vs recommended public setup
docs/docs/installation/github.md[57-96]
.github/workflows/pr-agent-review.yaml[7-11]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Docs do not clarify the difference between how PR-Agent runs in this repository vs the recommended workflow for public repos accepting fork PRs.
## Issue Context
The repository’s own workflow uses `workflow_dispatch` (with PR/comment triggers commented out), which differs from the guidance being added for users. Compliance requires explicitly addressing this difference and recommending the correct public configuration.
## Fix Focus Areas
- docs/docs/installation/github.md[57-96]
- docs/docs/usage-guide/automations_and_usage.md[170-177]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Previous review results

Review updated until commit ffdec38

Results up to commit 9f3ed00


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (2) 📜 Skill insights (0)

Context used

Action required
1. Incomplete pull_request_target security guidance 📎 Requirement gap ⛨ Security
Description
The fork-support guide recommends pull_request_target with actions/checkout using
allow-unsafe-pr-checkout: true without clearly documenting GitHub’s safer checkout defaults
change, or distinguishing safe versus unsafe checkout patterns and when/why they apply. This can
lead users to copy an unnecessary, high-risk checkout configuration even though PR-Agent’s action
runner can operate via the PR URL from the event payload without needing PR code checked out.
Code

docs/docs/installation/github.md[R57-95]

+#### Using with pull_request_target (fork/contribution support)
+
+By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.
+
+To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.
+
+```yaml
+name: PR Agent
+on:
+  pull_request_target:
+    types: [opened, reopened, synchronize, ready_for_review, review_requested]
+  issue_comment:
+jobs:
+  pr_agent_job:
+    if: ${{ github.event.sender.type != 'Bot' && (github.event_name == 'pull_request_target' || github.event.issue.pull_request) }}
+    runs-on: ubuntu-latest
+    permissions:
+      issues: write
+      pull-requests: write
+      contents: write
+    steps:
+      - name: Checkout PR code
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          allow-unsafe-pr-checkout: true
+      - name: PR Agent action step
+        uses: the-pr-agent/pr-agent@main
+        env:
+          OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          github_action_config.pr_actions: '["opened", "reopened", "synchronize", "ready_for_review", "review_requested"]'
+```
+
+!!! warning "Security considerations"
+    Using `pull_request_target` requires extra care. The `actions/checkout` step with `allow-unsafe-pr-checkout: true` checks out the PR's code, which could contain modified workflows. To mitigate risks, consider:
+    - Using `pull_request_target` only when you need fork support
+    - Reviewing the [GitHub security guide on pull_request_target](https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target)
+    - Avoiding running additional build steps from the checked-out PR code
Evidence
PR Compliance ID 7 requires that documentation covering pull_request_target include a security
section that references GitHub’s official guidance, mentions the safer checkout defaults change, and
explicitly explains safe vs. unsafe checkout patterns (including when/why allow-unsafe-pr-checkout
and pinning ref to the head SHA are used); however, the added section only provides a warning and
a GitHub link and does not lay out these patterns or the defaults change. Additionally, the action
runner code path derives pr_url from the GitHub event payload and invokes PR-Agent tools using
that URL, indicating PR-Agent execution does not depend on checked-out workspace files, so
recommending an unsafe checkout in the default example increases risk without being required for
PR-Agent itself.

Document secure usage of pull_request_target with actions/checkout for PR Agent
docs/docs/installation/github.md[57-95]
pr_agent/servers/github_action_runner.py[110-187]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The documentation’s `pull_request_target` example includes an `actions/checkout` step with `allow-unsafe-pr-checkout: true`, but it does not (a) reference GitHub’s safer checkout defaults change, (b) clearly explain safe vs. unsafe checkout patterns and when/why to use mitigations like pinning `ref` to the PR head SHA, or (c) clarify that PR-Agent itself can run using the PR URL (via GitHub API) and therefore does not require checking out PR code. We want the docs to reduce the chance users copy-paste an unnecessary, high-risk checkout configuration while still providing accurate, compliant guidance for cases where checkout is truly needed.

## Issue Context
This guide is likely to be adopted verbatim in public repositories that accept fork PRs, so ambiguous or default unsafe checkout guidance increases real-world security risk. Compliance requires explicit, `pull_request_target`-specific guidance that references GitHub’s official recommendations and the safer defaults change, and that clearly distinguishes safe vs. unsafe patterns (including when/why `allow-unsafe-pr-checkout` is used and why pinning `ref` to a head SHA can be important). Also, PR-Agent’s action runner operates off the PR URL derived from the event payload, so checkout is not required for PR-Agent execution and should not be implied as necessary.

## Fix Focus Areas
- docs/docs/installation/github.md[57-95]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Issue_comment checkout ref invalid 🐞 Bug ≡ Correctness
Description
The new workflow example always runs actions/checkout with `ref: ${{
github.event.pull_request.head.sha }}, but the same job is also triggered by issue_comment`, where
github.event.pull_request is not present. This can break comment-triggered PR-Agent commands (job
fails or checks out the wrong ref) in the documented fork-support setup.
Code

docs/docs/installation/github.md[R78-83]

+      - name: Checkout PR code
+        uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.pull_request.head.sha }}
+          allow-unsafe-pr-checkout: true
+      - name: PR Agent action step
Evidence
issue_comment events are processed using event_payload.issue.pull_request.url (not
event_payload.pull_request.*), and the unit test payload for issue_comment contains no
pull_request object—so the docs example’s github.event.pull_request.head.sha dereference is
invalid for comment-triggered runs.

pr_agent/servers/github_action_runner.py[192-237]
tests/unittest/test_github_action_runner_core.py[152-163]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The docs workflow listens to both `pull_request_target` and `issue_comment`, but unconditionally uses `github.event.pull_request.head.sha` in the checkout step. For `issue_comment` events the payload does not include `pull_request`, so the example can fail when users comment on PRs.

### Issue Context
PR-Agent’s GitHub Action runner handles `issue_comment` by using `event_payload.issue.pull_request.url` and does not require a local checkout.

### Fix Focus Areas
- docs/docs/installation/github.md[78-89]

### Proposed fix
Choose one of:
1) Remove the checkout step entirely from this example (PR-Agent runs via PR URL / API), OR
2) Make the checkout step conditional:
  - `if: ${{ github.event_name == 'pull_request_target' }}`
  - and avoid referencing `github.event.pull_request.*` for `issue_comment` runs (either skip checkout on comments or use a ref expression valid for comment events, e.g. `refs/pull/${{ github.event.issue.number }}/head`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
3. No internal workflow clarification 📎 Requirement gap ⚙ Maintainability
Description
The new documentation does not explain how PR-Agent itself is run in the pr-agent repository
(e.g., workflow triggers) versus the recommended public setup for forked contributions. This can
leave users uncertain about the "official"/intended configuration for public repos.
Code

docs/docs/installation/github.md[R57-62]

+#### Using with pull_request_target (fork/contribution support)
+
+By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.
+
+To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.
+
Evidence
PR Compliance ID 8 requires docs to explicitly explain how PR-Agent is run in the pr-agent
repository today and why that differs from recommended public configuration. The added fork-support
docs provide a recommended pull_request_target setup but do not mention the repository’s own
workflow_dispatch-only workflow, creating the ambiguity described by the rule.

Clarify how PR Agent itself is run (internal repo) vs recommended public setup
docs/docs/installation/github.md[57-96]
.github/workflows/pr-agent-review.yaml[7-11]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Docs do not clarify the difference between how PR-Agent runs in this repository vs the recommended workflow for public repos accepting fork PRs.

## Issue Context
The repository’s own workflow uses `workflow_dispatch` (with PR/comment triggers commented out), which differs from the guidance being added for users. Compliance requires explicitly addressing this difference and recommending the correct public configuration.

## Fix Focus Areas
- docs/docs/installation/github.md[57-96]
- docs/docs/usage-guide/automations_and_usage.md[170-177]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


ⓘ  2 issues published inline · 3 in summary

Qodo Logo

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 3, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Docs: document pull_request_target setup for forked PR support

📝 Documentation 🕐 Less than 10 minutes

Grey Divider

AI Description

• Document GitHub Actions configuration for PR-Agent on forked pull requests.
• Explain why pull_request lacks secrets on forks and when to use pull_request_target.
• Add cross-link tip in the usage guide and include security cautions for unsafe checkout.
Diagram

graph TD
  U["Repo maintainer"] --> W["GitHub Actions workflow"] --> E{{"Event: pull_request_target"}} --> C["Checkout PR SHA"] --> A["PR-Agent action"]
  D1["docs/installation/github.md"] --> W
  D2["docs/usage-guide/automations_and_usage.md"] --> D1
  subgraph Legend
    direction LR
    _doc["Documentation"] ~~~ _cfg["Workflow config"] ~~~ _evt{{"GitHub event"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Prefer GitHub App for external contributors
  • ➕ Avoids pull_request_target + unsafe checkout pitfalls for untrusted forks
  • ➕ Centralized auth model; less workflow complexity per repo
  • ➖ Requires installing/configuring an app instead of a simple workflow
  • ➖ May not fit repos that intentionally standardize on Actions-only automation
2. Use a two-workflow pattern (workflow_run) to keep secrets isolated
  • ➕ Reduces risk of exposing secrets to untrusted PR code execution
  • ➕ Allows stricter separation between untrusted build and trusted analysis
  • ➖ More complex to document and maintain
  • ➖ Harder for users to reason about triggers, artifacts, and permissions

Recommendation: The PR’s approach (documenting pull_request_target with explicit checkout instructions and a prominent security warning) is the most practical, lowest-friction way to enable fork PR support for GitHub Actions users. Consider mentioning the GitHub App option as an additional safer alternative for organizations that do not want to adopt allow-unsafe-pr-checkout, but the current documentation is appropriate and complete for the requested scenario.

Files changed (2) +43 / -0

Documentation (2) +43 / -0
github.mdAdd pull_request_target workflow example for fork PRs +40/-0

Add pull_request_target workflow example for fork PRs

• Adds a new subsection explaining why 'pull_request' cannot access secrets on forked PRs and how to switch to 'pull_request_target'. Includes a complete workflow YAML snippet with manual PR SHA checkout and a security warning admonition with mitigation guidance.

docs/docs/installation/github.md

automations_and_usage.mdLink GitHub Action docs to fork support guide +3/-0

Link GitHub Action docs to fork support guide

• Adds a tip admonition in the GitHub Action section pointing readers to the new 'pull_request_target' fork/contribution support documentation, including the security considerations link target.

docs/docs/usage-guide/automations_and_usage.md

Document how to use pull_request_target event to enable PR-Agent on PRs
from forked repositories. The code already supports this event type
(github_action_runner.py:110), but no documentation existed.

Closes The-PR-Agent#2500
@utsab345
utsab345 force-pushed the docs/fork-contribution-support branch from 567aaea to 9f3ed00 Compare July 3, 2026 11:10
Comment thread docs/docs/installation/github.md Outdated
Comment on lines +57 to +95
#### Using with pull_request_target (fork/contribution support)

By default, the `pull_request` event does not have access to repository secrets when the PR originates from a forked repository, which means PR-Agent won't be able to access your `OPENAI_KEY` and `GITHUB_TOKEN` secrets.

To support PRs from external contributors (forks), use the `pull_request_target` event instead. This event runs in the context of the base repository and has access to secrets, while the PR code is checked out manually with `actions/checkout`.

```yaml
name: PR Agent
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review, review_requested]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' && (github.event_name == 'pull_request_target' || github.event.issue.pull_request) }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
- name: PR Agent action step
uses: the-pr-agent/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_action_config.pr_actions: '["opened", "reopened", "synchronize", "ready_for_review", "review_requested"]'
```

!!! warning "Security considerations"
Using `pull_request_target` requires extra care. The `actions/checkout` step with `allow-unsafe-pr-checkout: true` checks out the PR's code, which could contain modified workflows. To mitigate risks, consider:
- Using `pull_request_target` only when you need fork support
- Reviewing the [GitHub security guide on pull_request_target](https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target)
- Avoiding running additional build steps from the checked-out PR code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Incomplete pull_request_target security guidance 📎 Requirement gap ⛨ Security

The fork-support guide recommends pull_request_target with actions/checkout using
allow-unsafe-pr-checkout: true without clearly documenting GitHub’s safer checkout defaults
change, or distinguishing safe versus unsafe checkout patterns and when/why they apply. This can
lead users to copy an unnecessary, high-risk checkout configuration even though PR-Agent’s action
runner can operate via the PR URL from the event payload without needing PR code checked out.
Agent Prompt
## Issue description
The documentation’s `pull_request_target` example includes an `actions/checkout` step with `allow-unsafe-pr-checkout: true`, but it does not (a) reference GitHub’s safer checkout defaults change, (b) clearly explain safe vs. unsafe checkout patterns and when/why to use mitigations like pinning `ref` to the PR head SHA, or (c) clarify that PR-Agent itself can run using the PR URL (via GitHub API) and therefore does not require checking out PR code. We want the docs to reduce the chance users copy-paste an unnecessary, high-risk checkout configuration while still providing accurate, compliant guidance for cases where checkout is truly needed.

## Issue Context
This guide is likely to be adopted verbatim in public repositories that accept fork PRs, so ambiguous or default unsafe checkout guidance increases real-world security risk. Compliance requires explicit, `pull_request_target`-specific guidance that references GitHub’s official recommendations and the safer defaults change, and that clearly distinguishes safe vs. unsafe patterns (including when/why `allow-unsafe-pr-checkout` is used and why pinning `ref` to a head SHA can be important). Also, PR-Agent’s action runner operates off the PR URL derived from the event payload, so checkout is not required for PR-Agent execution and should not be implied as necessary.

## Fix Focus Areas
- docs/docs/installation/github.md[57-95]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread docs/docs/installation/github.md Outdated
Comment on lines +78 to +83
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
- name: PR Agent action step

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Issue_comment checkout ref invalid 🐞 Bug ≡ Correctness

The new workflow example always runs actions/checkout with `ref: ${{
github.event.pull_request.head.sha }}, but the same job is also triggered by issue_comment`, where
github.event.pull_request is not present. This can break comment-triggered PR-Agent commands (job
fails or checks out the wrong ref) in the documented fork-support setup.
Agent Prompt
### Issue description
The docs workflow listens to both `pull_request_target` and `issue_comment`, but unconditionally uses `github.event.pull_request.head.sha` in the checkout step. For `issue_comment` events the payload does not include `pull_request`, so the example can fail when users comment on PRs.

### Issue Context
PR-Agent’s GitHub Action runner handles `issue_comment` by using `event_payload.issue.pull_request.url` and does not require a local checkout.

### Fix Focus Areas
- docs/docs/installation/github.md[78-89]

### Proposed fix
Choose one of:
1) Remove the checkout step entirely from this example (PR-Agent runs via PR URL / API), OR
2) Make the checkout step conditional:
   - `if: ${{ github.event_name == 'pull_request_target' }}`
   - and avoid referencing `github.event.pull_request.*` for `issue_comment` runs (either skip checkout on comments or use a ref expression valid for comment events, e.g. `refs/pull/${{ github.event.issue.number }}/head`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit ffdec38

@naorpeled

Copy link
Copy Markdown
Member

Thanks @utsab345 !

@naorpeled
naorpeled merged commit b1328df into The-PR-Agent:main Jul 5, 2026
5 checks passed
@utsab345

utsab345 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @utsab345 !

You're welcome, @naorpeled! Thanks for the review and merge. Looking forward to contributing again! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: missing documentation on how to run this for external contributions

2 participants