Skip to content

Include headRepositoryId when creating a new PR #10253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

jacob-keller
Copy link

@jacob-keller jacob-keller commented Jan 16, 2025

gh pr create does not currently handle creating pull requests across
repositories in the same organization. If a user attempts to create such a
PR, they will see a confusing error message:

pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between innersource:main and sandbox:branch, Head ref must be a branch (createPullRequest)

According to the API documentation, to create such a pull request, the API
request must contain the headRepositoryId identifying where the PR branch
exists.

In the usual case where gh pr create is being called without arguments, the
head repository is already known. It is looked up in order to ensure the
local changes are pushed to the remote fork.

In submitPR, extract the repository ID from the headRepo. If the headRepo
is already a full repository object, just grab the ID from it. Otherwise
perform an additional API lookup to get the repository object and then grab
the ID from that.

Extend the CreatePullRequest API wrapper to pass the headRepositoryId if it
was given.

This partially fixes #10093, at least in cases where the head repository is
known. A different solution will be required for the general case where
--head is used.

gh pr create does not currently handle creating pull requests across
repositories in the same organization. If a user attempts to create such a
PR, they will see a confusing error message:

  pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between innersource:main and sandbox:branch, Head ref must be a branch (createPullRequest)

According to the API documentation, to create such a pull request, the API
request must contain the headRepositoryId identifying where the PR branch
exists.

In the usual case where gh pr create is being called without arguments, the
head repository is already known. It is looked up in order to ensure the
local changes are pushed to the remote fork.

In submitPR, extract the repository ID from the headRepo. If the headRepo
is already a full repository object, just grab the ID from it. Otherwise
perform an additional API lookup to get the repository object and then grab
the ID from that.

Extend the CreatePullRequest API wrapper to pass the headRepositoryId if it
was given.

This partially fixes cli#10238, at least in cases where the head repository is
known. A different solution will be required for the general case where
--head is used.
@jacob-keller jacob-keller force-pushed the include-head-repository-id branch from 84606c4 to f5b50e0 Compare January 17, 2025 23:44
@jacob-keller
Copy link
Author

Ok, I got my system setup to build, and fixed the issues compiling. I haven't yet figured out how to resolve the tests failing, since we now issue another HTTP API request to get the repository object for a few of the tests.

@jacob-keller
Copy link
Author

I'm still unable to figure out how to get the tests to pass, but I did try this manually and it resolved my issues with creating pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance gh pr create to support cross repo pull requests within the same organization
1 participant