diff --git a/command/pr.go b/command/pr.go index 5277e38b2..ccb5f13a7 100644 --- a/command/pr.go +++ b/command/pr.go @@ -260,7 +260,8 @@ func prFromArg(apiClient *api.Client, baseRepo context.GitHubRepository, arg str } if m := prURLRE.FindStringSubmatch(arg); m != nil { - return &api.PullRequest{URL: m[0]}, nil + prNumber, _ := strconv.Atoi(m[3]) + return api.PullRequestByNumber(apiClient, baseRepo, prNumber) } return api.PullRequestForBranch(apiClient, baseRepo, arg) @@ -332,15 +333,6 @@ func prCheckout(cmd *cobra.Command, args []string) error { if err != nil { return err } - if pr.Number == 0 { - // hydrate the pr object by fetching extra information from the API - m := prURLRE.FindStringSubmatch(pr.URL) - prNumber, _ := strconv.Atoi(m[3]) - pr, err = api.PullRequestByNumber(apiClient, baseRemote, prNumber) - if err != nil { - return err - } - } headRemote := baseRemote if pr.IsCrossRepository { diff --git a/command/pr_test.go b/command/pr_test.go index f271560a5..4d2864656 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -256,7 +256,13 @@ func TestPRView_numberArg(t *testing.T) { func TestPRView_urlArg(t *testing.T) { initBlankContext("OWNER/REPO", "master") - initFakeHTTP() + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repository": { "pullRequest": { + "url": "https://github.com/OWNER/REPO/pull/23" + } } } } + `)) var seenCmd *exec.Cmd restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {