-
Notifications
You must be signed in to change notification settings - Fork 7.6k
gh pr create: add --head-repo flag
#12286
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Thank you for your pull request! 🎉 This PR appears to fix the following issues that are not labeled with
help wanted
As outlined in our Contributing Guidelines, we expect that PRs are only created for issues that have been labeled While we appreciate your initiative, please note that:
What happens next:
Thank you for your understanding and contribution to the project! 🙏 This comment was automatically generated by cliAutomation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR, @bayandin! ✨
I was doing some local testing and can confirm this works to open up intra-org PRs across forks 💯
My main concern is enhancing this behavior to determine some of this context from the local repository to reduce the number of flags a user has to provide.
As a side note, I think this work will expose some other places within gh pr and other commands where the existing cross-repo PR logic doesn't show the exact information we would want showing up such as gh pr view showing the org/repo:branch, which can be a follow up.
tinyfists/fork ‹12286-test›$ gh repo set-default
This command sets the default remote repository to use when querying the
GitHub API for the locally cloned repository.
gh uses the default repository for things like:
- viewing and creating pull requests
- viewing and creating issues
- viewing and creating releases
- working with GitHub Actions
### NOTE: gh does not use the default repository for managing repository and environment secrets.
? Which repository should be the default? [Use arrows to move, type to filter]
> tinyfists/upstream
tinyfists/fork
tinyfists/fork ‹12286-test›$ gh pr view 1
Working...
Add file for cross-repo PR testing tinyfists/upstream#1
Open • andyfeller wants to merge 1 commit into main from 12286-test • about 4 hours ago
+3 -0 • No checks
No description provided
View this pull request on GitHub: https://github.com/tinyfists/upstream/pull/1| if opts.HeadRepo != "" { | ||
| if opts.HeadBranch == "" { | ||
| return cmdutil.FlagErrorf("`--head-repo` requires `--head` to be specified") | ||
| } | ||
| // When --head-repo is provided, --head must be a plain branch name (no colon) | ||
| // because headRepositoryId and qualified headRefName (user:branch) are mutually exclusive | ||
| if strings.Contains(opts.HeadBranch, ":") { | ||
| return cmdutil.FlagErrorf("`--head-repo` cannot be used with `--head` in `user:branch` format. Use a plain branch name with `--head` when specifying `--head-repo`") | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: should this require --head when being called locally within a repository?
I can see this being required if calling this outside of a local repo, however I would expect the head branch and repo to be determined from the local context if possible.
| fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default [current branch])") | ||
| fl.StringVar(&opts.HeadRepo, "head-repo", "", "The `repository` that contains the head branch (owner/repo format)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest: I think gh users familiar using forks will expect --head owner:branch to work.
To be clear, I don't personally like the complex formatting behind the existing flag as it is leaking a detail of the GitHub API. However, I think having this new flag as a one-off for cross-org forks is inconsistent experience.
d00e979 to
86ef121
Compare
This PR adds support for explicitly specifying the head repository when creating pull requests. This enables creating PRs from same-org forks and cases where the head repository cannot be automatically determined.
--head-repo <owner/repo>to specify the repository containing the head branch--headto be specified and must be a plain branch name (notuser:branchformat)Example:
Note: A comment on the original issue (#6462 (comment)) raised concerns about GitHub Enterprise Server support. While
headRepositoryIdwas added to GHES 3.8, that version was discontinued on 2024-03-26 already. Therefore, adding it without feature detection.Fixes #6462
Fixed #10093