Bug: Action fails to find PRs from forks when using pull_request_target
Description
When this action is used with the pull_request_target event for PRs from forks, it fails with a "Not Found" error (HTTP 422).
Root Cause
The issue is in src/adapter/get-prs-associated-with-commit.ts:
const owner = triggeredFromPR
? github.context.payload.pull_request?.head.repo.owner.login // ❌ Fork owner
: github.context.repo.owner
const repo = triggeredFromPR
? github.context.payload.pull_request?.head.repo.name // ❌ Fork repo
: github.context.repo.repo
When a PR is created from a fork:
- The PR exists in the base repository (where it will be merged)
- The commit exists in the fork repository (the contributor's fork)
head.repo points to the fork
base.repo points to the base repository
The action queries the fork repository for PRs associated with the commit, but PRs don't exist in the fork—they exist in the base repository.
Expected Behavior
The action should query the base repository where the PR actually exists.
Fix
Change to use base.repo instead of head.repo:
const owner = triggeredFromPR
? github.context.payload.pull_request?.base.repo.owner.login // ✅ Base owner
: github.context.repo.owner
const repo = triggeredFromPR
? github.context.payload.pull_request?.base.repo.name // ✅ Base repo
: github.context.repo.repo
Reproduction
- Create a fork of a repository
- Create a PR from the fork to the base repository
- Use this action with
pull_request_target event
- Observe the "Not Found" error
Environment
- Action version: v4.0.0 (commit: 4056877)
- Event:
pull_request_target
- Fork: Yes
I'd be happy to submit a PR with the fix if you'd like!
Bug: Action fails to find PRs from forks when using
pull_request_targetDescription
When this action is used with the
pull_request_targetevent for PRs from forks, it fails with a "Not Found" error (HTTP 422).Root Cause
The issue is in
src/adapter/get-prs-associated-with-commit.ts:When a PR is created from a fork:
head.repopoints to the forkbase.repopoints to the base repositoryThe action queries the fork repository for PRs associated with the commit, but PRs don't exist in the fork—they exist in the base repository.
Expected Behavior
The action should query the base repository where the PR actually exists.
Fix
Change to use
base.repoinstead ofhead.repo:Reproduction
pull_request_targeteventEnvironment
pull_request_targetI'd be happy to submit a PR with the fix if you'd like!