diff --git a/command/pr_checkout_test.go b/command/pr_checkout_test.go index 501af2447..16b7429be 100644 --- a/command/pr_checkout_test.go +++ b/command/pr_checkout_test.go @@ -76,8 +76,6 @@ func TestPRCheckout_urlArg(t *testing.T) { return ctx } http := initFakeHTTP() - http.StubRepoResponse("hubot", "REPO") - http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "number": 123, @@ -126,7 +124,6 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) { return ctx } http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "number": 123, @@ -161,7 +158,7 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) { eq(t, err, nil) eq(t, output.String(), "") - bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body) + bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body) reqBody := struct { Variables struct { Owner string diff --git a/command/pr_lookup.go b/command/pr_lookup.go index 7f9a86955..a1b0c9638 100644 --- a/command/pr_lookup.go +++ b/command/pr_lookup.go @@ -14,32 +14,37 @@ import ( ) func prFromArgs(ctx context.Context, apiClient *api.Client, cmd *cobra.Command, args []string) (*api.PullRequest, ghrepo.Interface, error) { + if len(args) == 1 { + // First check to see if the prString is a url, return repo from url if found. This + // is run first because we don't need to run determineBaseRepo for this path + prString := args[0] + pr, r, err := prFromURL(ctx, apiClient, prString) + if pr != nil || err != nil { + return pr, r, err + } + } + repo, err := determineBaseRepo(apiClient, cmd, ctx) if err != nil { return nil, nil, fmt.Errorf("could not determine base repo: %w", err) } + // If there are no args see if we can guess the PR from the current branch if len(args) == 0 { pr, err := prForCurrentBranch(ctx, apiClient, repo) return pr, repo, err - } + } else { + prString := args[0] + // Next see if the prString is a number and use that to look up the url + pr, err := prFromNumberString(ctx, apiClient, repo, prString) + if pr != nil || err != nil { + return pr, repo, err + } - // First check to see if the prString is a url, return repo from url if found - prString := args[0] - pr, r, err := prFromURL(ctx, apiClient, prString) - if pr != nil || err != nil { - return pr, r, err - } - - // Next see if the prString is a number and use that to look up the url - pr, err = prFromNumberString(ctx, apiClient, repo, prString) - if pr != nil || err != nil { + // Last see if it is a branch name + pr, err = api.PullRequestForBranch(apiClient, repo, "", prString) return pr, repo, err } - - // Last see if it is a branch name - pr, err = api.PullRequestForBranch(apiClient, repo, "", prString) - return pr, repo, err } func prFromNumberString(ctx context.Context, apiClient *api.Client, repo ghrepo.Interface, s string) (*api.PullRequest, error) { diff --git a/command/pr_review_test.go b/command/pr_review_test.go index e2c54e715..612f6c574 100644 --- a/command/pr_review_test.go +++ b/command/pr_review_test.go @@ -50,7 +50,6 @@ func TestPRReview_bad_body(t *testing.T) { func TestPRReview_url_arg(t *testing.T) { initBlankContext("", "OWNER/REPO", "master") http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "id": "foobar123", @@ -77,7 +76,7 @@ func TestPRReview_url_arg(t *testing.T) { test.ExpectLines(t, output.String(), "Approved pull request #123") - bodyBytes, _ := ioutil.ReadAll(http.Requests[2].Body) + bodyBytes, _ := ioutil.ReadAll(http.Requests[1].Body) reqBody := struct { Variables struct { Input struct { diff --git a/command/pr_test.go b/command/pr_test.go index ef483c7d2..a11c60820 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -722,8 +722,6 @@ func TestPRView_web_numberArgWithHash(t *testing.T) { func TestPRView_web_urlArg(t *testing.T) { initBlankContext("", "OWNER/REPO", "master") http := initFakeHTTP() - - http.StubRepoResponse("OWNER", "REPO") http.StubResponse(200, bytes.NewBufferString(` { "data": { "repository": { "pullRequest": { "url": "https://github.com/OWNER/REPO/pull/23"