From 692bdaf5784ecc326deb78089a077b8e2c4ddf07 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Tue, 29 Apr 2025 14:32:51 +0300 Subject: [PATCH] Apply code review changes --- pkg/cmd/pr/shared/finder.go | 10 ++++++++-- pkg/cmd/pr/shared/finder_test.go | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/pr/shared/finder.go b/pkg/cmd/pr/shared/finder.go index 9e92c0692..a87d6790f 100644 --- a/pkg/cmd/pr/shared/finder.go +++ b/pkg/cmd/pr/shared/finder.go @@ -212,7 +212,8 @@ func (f *finder) Find(opts FindOptions) (*api.PullRequest, ghrepo.Interface, err } var pr *api.PullRequest - if f.prNumber > 0 || f.branchName == "" { + if f.prNumber > 0 { + // If we have a PR number, let's look it up if numberFieldOnly { // avoid hitting the API if we already have all the information return &api.PullRequest{Number: f.prNumber}, f.baseRefRepo, nil @@ -221,11 +222,16 @@ func (f *finder) Find(opts FindOptions) (*api.PullRequest, ghrepo.Interface, err if err != nil { return pr, f.baseRefRepo, err } - } else { + } else if prRefs.BaseRepo() != nil && f.branchName != "" { + // No PR number, but we have a base repo and branch name. pr, err = findForRefs(httpClient, prRefs, opts.States, fields.ToSlice()) if err != nil { return pr, f.baseRefRepo, err } + } else { + // If we don't have a PR number or a base repo and branch name, + // we can't do anything + return nil, f.baseRefRepo, &NotFoundError{fmt.Errorf("no pull requests found")} } g, _ := errgroup.WithContext(context.Background()) diff --git a/pkg/cmd/pr/shared/finder_test.go b/pkg/cmd/pr/shared/finder_test.go index 66fb900eb..abc754d1a 100644 --- a/pkg/cmd/pr/shared/finder_test.go +++ b/pkg/cmd/pr/shared/finder_test.go @@ -180,9 +180,7 @@ func TestFind(t *testing.T) { remotePushDefaultFn: stubRemotePushDefault("", nil), }, }, - httpStub: nil, - wantPR: 0, - wantRepo: "https://github.com/ORIGINOWNER/REPO", + wantErr: true, }, { name: "number with hash argument",