diff --git a/pkg/cmd/pr/status/status.go b/pkg/cmd/pr/status/status.go index 499202b7e..e97770ce4 100644 --- a/pkg/cmd/pr/status/status.go +++ b/pkg/cmd/pr/status/status.go @@ -197,18 +197,21 @@ func prSelectorForCurrentBranch(branchConfig git.BranchConfig, baseRepo ghrepo.I return prNumber, prHeadRef, nil } - var err error var branchOwner string if branchConfig.RemoteURL != nil { // the branch merges from a remote specified by URL - if r, err := ghrepo.FromURL(branchConfig.RemoteURL); err == nil { - branchOwner = r.RepoOwner() + r, err := ghrepo.FromURL(branchConfig.RemoteURL) + if err != nil { + return 0, prHeadRef, err } + branchOwner = r.RepoOwner() } else if branchConfig.RemoteName != "" { // the branch merges from a remote specified by name - if r, err := rem.FindByName(branchConfig.RemoteName); err == nil { - branchOwner = r.RepoOwner() + r, err := rem.FindByName(branchConfig.RemoteName) + if err != nil { + return 0, prHeadRef, err } + branchOwner = r.RepoOwner() } selector := prHeadRef @@ -222,7 +225,7 @@ func prSelectorForCurrentBranch(branchConfig git.BranchConfig, baseRepo ghrepo.I } } - return 0, selector, err + return 0, selector, nil } func totalApprovals(pr *api.PullRequest) int { diff --git a/pkg/cmd/pr/status/status_test.go b/pkg/cmd/pr/status/status_test.go index 9f3079957..94505aaba 100644 --- a/pkg/cmd/pr/status/status_test.go +++ b/pkg/cmd/pr/status/status_test.go @@ -2,6 +2,7 @@ package status import ( "bytes" + "fmt" "io" "net/http" "net/url" @@ -527,6 +528,41 @@ func Test_prSelectorForCurrentBranch(t *testing.T) { wantSelector: "forkName:main", wantError: nil, }, + { + name: "Remote URL error", + branchConfig: git.BranchConfig{ + RemoteURL: &url.URL{ + Scheme: "ssh", + User: url.User("git"), + Host: "github.com", + Path: "/\\invalid?Path/", + }, + }, + prHeadRef: "Frederick888/main", + wantPrNumber: 0, + wantSelector: "Frederick888/main", + wantError: fmt.Errorf("invalid path: /\\invalid?Path/"), + }, + { + name: "Remote Name error", + branchConfig: git.BranchConfig{ + RemoteName: "nonexistentRemote", + }, + prHeadRef: "Frederick888/main", + remotes: context.Remotes{ + &context.Remote{ + Remote: &git.Remote{Name: "origin"}, + Repo: ghrepo.NewWithHost("forkName", "playground", "github.com"), + }, + &context.Remote{ + Remote: &git.Remote{Name: "upstream"}, + Repo: ghrepo.NewWithHost("Frederick888", "playground", "github.com"), + }, + }, + wantPrNumber: 0, + wantSelector: "Frederick888/main", + wantError: fmt.Errorf("no matching remote found"), + }, } for _, tt := range tests {