From 20fc0dfcb74ca7497458226ef834d3b1d09a0db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 24 Feb 2020 17:14:46 +0100 Subject: [PATCH] Avoid API requests in `repo view` when repo argument is given --- command/repo.go | 8 ++++---- command/repo_test.go | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/command/repo.go b/command/repo.go index e453d8b61..d77e2efff 100644 --- a/command/repo.go +++ b/command/repo.go @@ -36,13 +36,13 @@ branch is opened.`, func repoView(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) - baseRepo, err := determineBaseRepo(cmd, ctx) - if err != nil { - return err - } var openURL string if len(args) == 0 { + baseRepo, err := determineBaseRepo(cmd, ctx) + if err != nil { + return err + } openURL = fmt.Sprintf("https://github.com/%s", ghrepo.FullName(*baseRepo)) } else { if strings.HasPrefix(args[0], "http") { diff --git a/command/repo_test.go b/command/repo_test.go index 30da540b0..f156f1283 100644 --- a/command/repo_test.go +++ b/command/repo_test.go @@ -4,6 +4,7 @@ import ( "os/exec" "testing" + "github.com/cli/cli/context" "github.com/cli/cli/utils" ) @@ -35,9 +36,12 @@ func TestRepoView(t *testing.T) { } func TestRepoView_ownerRepo(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") + ctx := context.NewBlank() + ctx.SetBranch("master") + initContext = func() context.Context { + return ctx + } + initFakeHTTP() var seenCmd *exec.Cmd restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable { @@ -62,9 +66,12 @@ func TestRepoView_ownerRepo(t *testing.T) { } func TestRepoView_fullURL(t *testing.T) { - initBlankContext("OWNER/REPO", "master") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") + ctx := context.NewBlank() + ctx.SetBranch("master") + initContext = func() context.Context { + return ctx + } + initFakeHTTP() var seenCmd *exec.Cmd restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {