Improve detecting PR for the current branch#96
Merged
Conversation
When on a `patch-1` branch locally, `gh pr view` would happily open the first open PR it finds with "patch-1" as its head, even those coming from forks.
Now reads git branch configuration and handles these cases:
branch ["foo"]
remote origin
merge refs/heads/bar
branch ["foo"]
remote other-remote
merge refs/heads/foo
branch ["foo"]
remote https://github.com/OWNER/REPO.git
merge refs/heads/bar
branch ["foo"]
remote origin
merge refs/pull/123/head
probablycorey
approved these changes
Nov 22, 2019
Contributor
probablycorey
left a comment
There was a problem hiding this comment.
👍 for the tests. The code looks great, but I think a little more documentation would help us maintain it in the future.
| } | ||
| } | ||
|
|
||
| pr, err := api.PullRequestForBranch(apiClient, baseRepo, branchWithOwner) |
Contributor
There was a problem hiding this comment.
This looks good but it's a pretty dense. Maybe pull it out into a few functions, or variables like prNumberInRef := prHeadRE.FindStringSubmatch(branchConfig.MergeRef). I'm pretty stingy with comments, but this might be the type of code where some make sense.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When on the e.g. "development" branch, the CLI could erroneously associate it with a PR that also has "development" as its head, but comes from a fork. https://github.slack.com/archives/CLLG3RMAR/p1574107160421000
This implements a stricter current branch match that eliminates false positives.
Now reads git branch configuration and handles these cases:
Upstream branch is differently named:
Upstream branch tracks a non-default remote:
Upstream configuration is with remote URL instead of name:
Upstream configuration pulls from special PR head refspec:
Ultimately, all this ensures that
pr viewcan be used without arguments on any branch created withpr checkoutand that the correct PR will be opened.Commands to extend this behavior to (TODO):
pr viewpr status