Skip to content

[Bug]: Action fails to find PRs from forks when using pull_request_target #353

@puneet-arora15

Description

@puneet-arora15

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

  1. Create a fork of a repository
  2. Create a PR from the fork to the base repository
  3. Use this action with pull_request_target event
  4. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions