Skip to content

Enhance gh pr create to support cross repo pull requests within the same organization #10093

@andyfeller

Description

@andyfeller

Describe the feature or problem you’d like to solve

gh pr create -H user:branch is limited to creating cross repo pull requests between an upstream repository and a user-owned fork due to createPullRequest mutation limitation in the headRefName field. Instead, these types of cross repo pull requests should specify the GraphQL ID of the upstream repository using headRepositoryId field.

Ideally, the -H, --head branch flag could be used with user or organization logins.

For more information, #9364 (comment)

Proposed solution

This would support intra-organization forking needs as well as simplify acceptance tests around this scenario:

# Create the PR spanning upstream and fork repositories, gh pr create does not support headRepositoryId needed for private forks
exec gh api graphql -F repositoryId="${REPO_ID}" -F headRepositoryId="${FORK_ID}" -F query='mutation CreatePullRequest($headRepositoryId: ID!, $repositoryId: ID!) { createPullRequest(input:{ baseRefName: "main", body: "Feature Body", draft: false, headRefName: "feature-branch", headRepositoryId: $headRepositoryId, repositoryId: $repositoryId, title:"Feature Title" }){ pullRequest{ id url } } }'

Additional context

Relates #9208
Relates #575

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions