diff --git a/pkg/cmd/repo/archive/archive.go b/pkg/cmd/repo/archive/archive.go index c4d6be2bb..eb2af2175 100644 --- a/pkg/cmd/repo/archive/archive.go +++ b/pkg/cmd/repo/archive/archive.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,6 +17,7 @@ import ( type ArchiveOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams + Config func() (config.Config, error) RepoArg string } @@ -24,6 +25,7 @@ func NewCmdArchive(f *cmdutil.Factory, runF func(*ArchiveOptions) error) *cobra. opts := &ArchiveOptions{ IO: f.IOStreams, HttpClient: f.HttpClient, + Config: f.Config, } cmd := &cobra.Command{ @@ -57,7 +59,16 @@ func archiveRun(opts *ArchiveOptions) error { archiveURL := opts.RepoArg if !strings.Contains(archiveURL, "/") { - currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default()) + cfg, err := opts.Config() + if err != nil { + return err + } + hostname, err := cfg.DefaultHost() + if err != nil { + return err + } + + currentUser, err := api.CurrentLoginName(apiClient, hostname) if err != nil { return err } diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 1f74a8188..a0fe837e7 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -12,7 +12,6 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" - "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -327,7 +326,11 @@ func createRun(opts *CreateOptions) error { templateRepoName := opts.Template if !strings.Contains(templateRepoName, "/") { - currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default()) + host, err := cfg.DefaultHost() + if err != nil { + return err + } + currentUser, err := api.CurrentLoginName(apiClient, host) if err != nil { return err } diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index c649b5394..95591bd32 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -13,7 +13,7 @@ import ( "strings" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -90,6 +90,7 @@ type GardenOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) + Config func() (config.Config, error) RepoArg string } @@ -99,6 +100,7 @@ func NewCmdGarden(f *cmdutil.Factory, runF func(*GardenOptions) error) *cobra.Co IO: f.IOStreams, HttpClient: f.HttpClient, BaseRepo: f.BaseRepo, + Config: f.Config, } cmd := &cobra.Command{ @@ -149,7 +151,16 @@ func gardenRun(opts *GardenOptions) error { var err error viewURL := opts.RepoArg if !strings.Contains(viewURL, "/") { - currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default()) + cfg, err := opts.Config() + if err != nil { + return err + } + hostname, err := cfg.DefaultHost() + if err != nil { + return err + } + + currentUser, err := api.CurrentLoginName(apiClient, hostname) if err != nil { return err } diff --git a/pkg/cmd/repo/view/view.go b/pkg/cmd/repo/view/view.go index ef8a7dfa2..3d2879dc0 100644 --- a/pkg/cmd/repo/view/view.go +++ b/pkg/cmd/repo/view/view.go @@ -11,7 +11,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -30,6 +30,7 @@ type ViewOptions struct { BaseRepo func() (ghrepo.Interface, error) Browser browser Exporter cmdutil.Exporter + Config func() (config.Config, error) RepoArg string Web bool @@ -42,6 +43,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman HttpClient: f.HttpClient, BaseRepo: f.BaseRepo, Browser: f.Browser, + Config: f.Config, } cmd := &cobra.Command{ @@ -90,10 +92,18 @@ func viewRun(opts *ViewOptions) error { return err } } else { - var err error viewURL := opts.RepoArg if !strings.Contains(viewURL, "/") { - currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default()) + cfg, err := opts.Config() + if err != nil { + return err + } + hostname, err := cfg.DefaultHost() + if err != nil { + return err + } + + currentUser, err := api.CurrentLoginName(apiClient, hostname) if err != nil { return err } diff --git a/pkg/cmd/repo/view/view_test.go b/pkg/cmd/repo/view/view_test.go index e7d814cb4..cb4bc24fa 100644 --- a/pkg/cmd/repo/view/view_test.go +++ b/pkg/cmd/repo/view/view_test.go @@ -8,6 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" + "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -528,6 +529,9 @@ func Test_ViewRun_WithoutUsername(t *testing.T) { return &http.Client{Transport: reg}, nil }, IO: io, + Config: func() (config.Config, error) { + return config.NewBlankConfig(), nil + }, } if err := viewRun(opts); err != nil {