diff --git a/command/repo.go b/command/repo.go index 8a4d1cc0e..122fe402c 100644 --- a/command/repo.go +++ b/command/repo.go @@ -386,20 +386,16 @@ var Confirm = func(prompt string, result *bool) error { func repoView(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) - - var openURL string var toView ghrepo.Interface if len(args) == 0 { - baseRepo, err := determineBaseRepo(cmd, ctx) + var err error + toView, err = determineBaseRepo(cmd, ctx) if err != nil { return err } - openURL = fmt.Sprintf("https://github.com/%s", ghrepo.FullName(baseRepo)) - toView = baseRepo } else { repoArg := args[0] if isURL(repoArg) { - openURL = repoArg parsedURL, err := url.Parse(repoArg) if err != nil { return fmt.Errorf("did not understand argument: %w", err) @@ -411,23 +407,19 @@ func repoView(cmd *cobra.Command, args []string) error { } } else { toView = ghrepo.FromFullName(repoArg) - openURL = fmt.Sprintf("https://github.com/%s", repoArg) } } apiClient, err := apiClientForContext(ctx) - + if err != nil { + return err + } + _, err = api.GitHubRepo(apiClient, toView) if err != nil { return err } - _, err_message := api.GitHubRepo(apiClient, toView) - if err_message != nil { - return err_message - } - + openURL := fmt.Sprintf("https://github.com/%s", ghrepo.FullName(toView)) fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL)) return utils.OpenInBrowser(openURL) - - } diff --git a/command/repo_test.go b/command/repo_test.go index 3fd3357da..a3ba656c3 100644 --- a/command/repo_test.go +++ b/command/repo_test.go @@ -610,7 +610,6 @@ func TestRepoView(t *testing.T) { eq(t, url, "https://github.com/OWNER/REPO") } - func TestRepoView_ownerRepo(t *testing.T) { ctx := context.NewBlank() ctx.SetBranch("master")