Have PullRequestForBranch accept "owner:branch" value for forks
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.
This commit is contained in:
parent
c7a38b6331
commit
508f6787f0
5 changed files with 77 additions and 81 deletions
|
|
@ -243,13 +243,11 @@ func prView(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
prs, err := api.PullRequestsForBranch(apiClient, baseRepo, currentBranch)
|
||||
pr, err := api.PullRequestForBranch(apiClient, baseRepo, currentBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(prs) < 1 {
|
||||
return fmt.Errorf("the '%s' branch has no open pull requests", currentBranch)
|
||||
}
|
||||
openURL = prs[0].URL
|
||||
openURL = pr.URL
|
||||
}
|
||||
|
||||
fmt.Printf("Opening %s in your browser.\n", openURL)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func eq(t *testing.T, got interface{}, expected interface{}) {
|
|||
}
|
||||
|
||||
func TestPRStatus(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prStatus.json")
|
||||
|
|
@ -100,7 +100,7 @@ func TestPRList_filtering(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPRView(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "master")
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prView.json")
|
||||
|
|
@ -148,7 +148,7 @@ func TestPRView_NoActiveBranch(t *testing.T) {
|
|||
defer restoreCmd()
|
||||
|
||||
output, err := test.RunCommand(RootCmd, "pr view")
|
||||
if err == nil || err.Error() != "the 'master' branch has no open pull requests" {
|
||||
if err == nil || err.Error() != `no open pull requests found for branch "master"` {
|
||||
t.Errorf("error running command `pr view`: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue