diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index aa5c013ff..0c9590fac 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -9,6 +9,7 @@ import ( "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/docs" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/root" "github.com/cli/cli/v2/pkg/cmdutil" @@ -48,7 +49,7 @@ func run(args []string) error { rootCmd, _ := root.NewCmdRoot(&cmdutil.Factory{ IOStreams: ios, Browser: &browser{}, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewFromString(""), nil }, ExtensionManager: &em{}, diff --git a/internal/codespaces/api/api_test.go b/internal/codespaces/api/api_test.go index 722657197..9d06dcdaf 100644 --- a/internal/codespaces/api/api_test.go +++ b/internal/codespaces/api/api_test.go @@ -12,6 +12,8 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" + ghmock "github.com/cli/cli/v2/internal/gh/mock" "github.com/cli/cli/v2/pkg/cmdutil" ) @@ -137,13 +139,13 @@ func createHttpClient() (*http.Client, error) { func TestNew_APIURL_dotcomConfig(t *testing.T) { t.Setenv("GITHUB_API_URL", "") t.Setenv("GITHUB_SERVER_URL", "https://github.com") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { return &config.AuthConfig{} }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -160,15 +162,15 @@ func TestNew_APIURL_dotcomConfig(t *testing.T) { func TestNew_APIURL_customConfig(t *testing.T) { t.Setenv("GITHUB_API_URL", "") t.Setenv("GITHUB_SERVER_URL", "https://github.mycompany.com") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetDefaultHost("github.mycompany.com", "GH_HOST") return authCfg }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -185,13 +187,13 @@ func TestNew_APIURL_customConfig(t *testing.T) { func TestNew_APIURL_env(t *testing.T) { t.Setenv("GITHUB_API_URL", "https://api.mycompany.com") t.Setenv("GITHUB_SERVER_URL", "https://mycompany.com") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { return &config.AuthConfig{} }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -208,7 +210,7 @@ func TestNew_APIURL_env(t *testing.T) { func TestNew_APIURL_dotcomFallback(t *testing.T) { t.Setenv("GITHUB_API_URL", "") f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return nil, errors.New("Failed to load") }, } @@ -222,13 +224,13 @@ func TestNew_APIURL_dotcomFallback(t *testing.T) { func TestNew_ServerURL_dotcomConfig(t *testing.T) { t.Setenv("GITHUB_SERVER_URL", "") t.Setenv("GITHUB_API_URL", "https://api.github.com") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { return &config.AuthConfig{} }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -245,15 +247,15 @@ func TestNew_ServerURL_dotcomConfig(t *testing.T) { func TestNew_ServerURL_customConfig(t *testing.T) { t.Setenv("GITHUB_SERVER_URL", "") t.Setenv("GITHUB_API_URL", "https://github.mycompany.com/api/v3") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetDefaultHost("github.mycompany.com", "GH_HOST") return authCfg }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -270,13 +272,13 @@ func TestNew_ServerURL_customConfig(t *testing.T) { func TestNew_ServerURL_env(t *testing.T) { t.Setenv("GITHUB_SERVER_URL", "https://mycompany.com") t.Setenv("GITHUB_API_URL", "https://api.mycompany.com") - cfg := &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + cfg := &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { return &config.AuthConfig{} }, } f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } @@ -293,7 +295,7 @@ func TestNew_ServerURL_env(t *testing.T) { func TestNew_ServerURL_dotcomFallback(t *testing.T) { t.Setenv("GITHUB_SERVER_URL", "") f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return nil, errors.New("Failed to load") }, } diff --git a/internal/config/auth_config_test.go b/internal/config/auth_config_test.go index 52373f375..ed000ff18 100644 --- a/internal/config/auth_config_test.go +++ b/internal/config/auth_config_test.go @@ -13,7 +13,7 @@ import ( // Note that NewIsolatedTestConfig sets up a Mock keyring as well func newTestAuthConfig(t *testing.T) *AuthConfig { cfg, _ := NewIsolatedTestConfig(t) - return cfg.Authentication() + return &AuthConfig{cfg: cfg.cfg} } func TestTokenFromKeyring(t *testing.T) { diff --git a/internal/config/config.go b/internal/config/config.go index f3ed8cf6f..ad451ee97 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( "path/filepath" "slices" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/keyring" ghAuth "github.com/cli/go-gh/v2/pkg/auth" ghConfig "github.com/cli/go-gh/v2/pkg/config" @@ -27,49 +28,7 @@ const ( versionKey = "version" ) -// This interface describes interacting with some persistent configuration for gh. -// -//go:generate moq -rm -out config_mock.go . Config -type Config interface { - GetOrDefault(string, string) (string, error) - Set(string, string, string) - Write() error - Migrate(Migration) error - - CacheDir() string - - Aliases() *AliasConfig - Authentication() *AuthConfig - Browser(string) string - Editor(string) string - GitProtocol(string) string - HTTPUnixSocket(string) string - Pager(string) string - Prompt(string) string - Version() string -} - -// Migration is the interface that config migrations must implement. -// -// Migrations will receive a copy of the config, and should modify that copy -// as necessary. After migration has completed, the modified config contents -// will be used. -// -// The calling code is expected to verify that the current version of the config -// matches the PreVersion of the migration before calling Do, and will set the -// config version to the PostVersion after the migration has completed successfully. -// -//go:generate moq -rm -out migration_mock.go . Migration -type Migration interface { - // PreVersion is the required config version for this to be applied - PreVersion() string - // PostVersion is the config version that must be applied after migration - PostVersion() string - // Do is expected to apply any necessary changes to the config in place - Do(*ghConfig.Config) error -} - -func NewConfig() (Config, error) { +func NewConfig() (gh.Config, error) { c, err := ghConfig.Read(fallbackConfig()) if err != nil { return nil, err @@ -123,11 +82,11 @@ func (c *cfg) Write() error { return ghConfig.Write(c.cfg) } -func (c *cfg) Aliases() *AliasConfig { +func (c *cfg) Aliases() gh.AliasConfig { return &AliasConfig{cfg: c.cfg} } -func (c *cfg) Authentication() *AuthConfig { +func (c *cfg) Authentication() gh.AuthConfig { return &AuthConfig{cfg: c.cfg} } @@ -166,7 +125,7 @@ func (c *cfg) Version() string { return val } -func (c *cfg) Migrate(m Migration) error { +func (c *cfg) Migrate(m gh.Migration) error { version := c.Version() // If migration has already occurred then do not attempt to migrate again. diff --git a/internal/config/migrate_test.go b/internal/config/migrate_test.go index 193848558..783f605a2 100644 --- a/internal/config/migrate_test.go +++ b/internal/config/migrate_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "testing" + ghmock "github.com/cli/cli/v2/internal/gh/mock" ghConfig "github.com/cli/go-gh/v2/pkg/config" "github.com/stretchr/testify/require" ) @@ -60,7 +61,7 @@ func TestMigrationAppliedBumpsVersion(t *testing.T) { c.Set([]string{versionKey}, "expected-pre-version") topLevelKey := []string{"toplevelkey"} - migration := &MigrationMock{ + migration := &ghmock.MigrationMock{ DoFunc: func(config *ghConfig.Config) error { config.Set(topLevelKey, "toplevelvalue") return nil @@ -96,7 +97,7 @@ func TestMigrationIsNoopWhenAlreadyApplied(t *testing.T) { c := ghConfig.ReadFromString(testFullConfig()) c.Set([]string{versionKey}, "expected-post-version") - migration := &MigrationMock{ + migration := &ghmock.MigrationMock{ DoFunc: func(config *ghConfig.Config) error { return errors.New("is not called") }, @@ -126,7 +127,7 @@ func TestMigrationErrorsWhenPreVersionMismatch(t *testing.T) { c.Set([]string{versionKey}, "not-expected-pre-version") topLevelKey := []string{"toplevelkey"} - migration := &MigrationMock{ + migration := &ghmock.MigrationMock{ DoFunc: func(config *ghConfig.Config) error { config.Set(topLevelKey, "toplevelvalue") return nil @@ -228,8 +229,8 @@ func makeFileUnwriteable(t *testing.T, file string) { require.NoError(t, os.Chmod(file, 0000)) } -func mockMigration(doFunc func(config *ghConfig.Config) error) *MigrationMock { - return &MigrationMock{ +func mockMigration(doFunc func(config *ghConfig.Config) error) *ghmock.MigrationMock { + return &ghmock.MigrationMock{ DoFunc: doFunc, PreVersionFunc: func() string { return "" diff --git a/internal/config/stub.go b/internal/config/stub.go index 547ad951b..d0500cfe4 100644 --- a/internal/config/stub.go +++ b/internal/config/stub.go @@ -6,18 +6,20 @@ import ( "path/filepath" "testing" + "github.com/cli/cli/v2/internal/gh" + ghmock "github.com/cli/cli/v2/internal/gh/mock" "github.com/cli/cli/v2/internal/keyring" ghConfig "github.com/cli/go-gh/v2/pkg/config" ) -func NewBlankConfig() *ConfigMock { +func NewBlankConfig() *ghmock.ConfigMock { return NewFromString(defaultConfigStr) } -func NewFromString(cfgStr string) *ConfigMock { +func NewFromString(cfgStr string) *ghmock.ConfigMock { c := ghConfig.ReadFromString(cfgStr) cfg := cfg{c} - mock := &ConfigMock{} + mock := &ghmock.ConfigMock{} mock.GetOrDefaultFunc = func(host, key string) (string, error) { return cfg.GetOrDefault(host, key) } @@ -27,13 +29,13 @@ func NewFromString(cfgStr string) *ConfigMock { mock.WriteFunc = func() error { return cfg.Write() } - mock.MigrateFunc = func(m Migration) error { + mock.MigrateFunc = func(m gh.Migration) error { return cfg.Migrate(m) } - mock.AliasesFunc = func() *AliasConfig { + mock.AliasesFunc = func() gh.AliasConfig { return &AliasConfig{cfg: c} } - mock.AuthenticationFunc = func() *AuthConfig { + mock.AuthenticationFunc = func() gh.AuthConfig { return &AuthConfig{ cfg: c, defaultHostOverride: func() (string, string) { @@ -88,7 +90,7 @@ func NewFromString(cfgStr string) *ConfigMock { // in the real implementation, sets the GH_CONFIG_DIR env var so that // any call to Write goes to a different location on disk, and then returns // the blank config and a function that reads any data written to disk. -func NewIsolatedTestConfig(t *testing.T) (Config, func(io.Writer, io.Writer)) { +func NewIsolatedTestConfig(t *testing.T) (*cfg, func(io.Writer, io.Writer)) { keyring.MockInit() c := ghConfig.ReadFromString("") diff --git a/internal/gh/gh.go b/internal/gh/gh.go new file mode 100644 index 000000000..6e3094ea1 --- /dev/null +++ b/internal/gh/gh.go @@ -0,0 +1,158 @@ +// Package gh provides types that represent the domain of the CLI application. +// +// For example, the CLI expects to be able to get and set user configuration in order to perform its functionality, +// so the Config interface is defined here, though the concrete implementation lives elsewhere. Though the current +// implementation of config writes to certain files on disk, that is an implementation detail compared to the contract +// laid out in the interface here. +// +// Currently this package is in an early state but we could imagine other domain concepts living here for interacting +// with git or GitHub. +package gh + +import ( + ghConfig "github.com/cli/go-gh/v2/pkg/config" +) + +// A Config implements persistent storage and modification of application configuration. +// +//go:generate moq -rm -pkg ghmock -out mock/config.go . Config +type Config interface { + // GetOrDefault provides primitive access for fetching configuration values, optionally scoped by host. + GetOrDefault(hostname string, key string) (string, error) + // Set provides primitive access for setting configuration values, optionally scoped by host. + Set(hostname string, key string, value string) + + // Browser returns the configured browser, optionally scoped by host. + Browser(hostname string) string + // Editor returns the configured editor, optionally scoped by host. + Editor(hostname string) string + // GitProtocol returns the configured git protocol, optionally scoped by host. + GitProtocol(hostname string) string + // HTTPUnixSocket returns the configured HTTP unix socket, optionally scoped by host. + HTTPUnixSocket(hostname string) string + // Pager returns the configured Pager, optionally scoped by host. + Pager(hostname string) string + // Prompt returns the configured prompt, optionally scoped by host. + Prompt(hostname string) string + + // Aliases provides persistent storage and modification of command aliases. + Aliases() AliasConfig + + // Authentication provides persistent storage and modification of authentication configuration. + Authentication() AuthConfig + + // CacheDir returns the directory where the cacheable artifacts can be persisted. + CacheDir() string + + // Migrate applies a migration to the configuration. + Migrate(Migration) error + + // Version returns the current schema version of the configuration. + Version() string + + // Write persists modifications to the configuration. + Write() error +} + +// Migration is the interface that config migrations must implement. +// +// Migrations will receive a copy of the config, and should modify that copy +// as necessary. After migration has completed, the modified config contents +// will be used. +// +// The calling code is expected to verify that the current version of the config +// matches the PreVersion of the migration before calling Do, and will set the +// config version to the PostVersion after the migration has completed successfully. +// +//go:generate moq -rm -pkg ghmock -out mock/migration.go . Migration +type Migration interface { + // PreVersion is the required config version for this to be applied + PreVersion() string + // PostVersion is the config version that must be applied after migration + PostVersion() string + // Do is expected to apply any necessary changes to the config in place + Do(*ghConfig.Config) error +} + +// AuthConfig is used for interacting with some persistent configuration for gh, +// with knowledge on how to access encrypted storage when neccesarry. +// Behavior is scoped to authentication specific tasks. +type AuthConfig interface { + // ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, + // general configuration, and finally encrypted storage. + ActiveToken(hostname string) (token string, source string) + + // HasEnvToken returns true when a token has been specified in an environment variable, else returns false. + HasEnvToken() bool + + // TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage. + TokenFromKeyring(hostname string) (token string, err error) + + // TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching + // in encrypted storage. + // + // An empty username will return an error because the potential to return the currently active token under + // surprising cases is just too high to risk compared to the utility of having the function being smart. + TokenFromKeyringForUser(hostname, username string) (token string, err error) + + // ActiveUser will retrieve the username for the active user at the given hostname. + // + // This will not be accurate if the oauth token is set from an environment variable. + ActiveUser(hostname string) (username string, err error) + + // Hosts retrieves a list of known hosts. + Hosts() []string + + // DefaultHost retrieves the default host. + DefaultHost() (host string, source string) + + // Login will set user, git protocol, and auth token for the given hostname. + // + // If the encrypt option is specified it will first try to store the auth token + // in encrypted storage and will fall back to the general insecure configuration. + Login(hostname, username, token, gitProtocol string, secureStorage bool) (insecureStorageUsed bool, err error) + + // SwitchUser switches the active user for a given hostname. + SwitchUser(hostname, user string) error + + // Logout will remove user, git protocol, and auth token for the given hostname. + // It will remove the auth token from the encrypted storage if it exists there. + Logout(hostname, username string) error + + // UsersForHost retrieves a list of users configured for a specific host. + UsersForHost(hostname string) []string + + // TokenForUser retrieves the authentication token and its source for a specified user and hostname. + TokenForUser(hostname, user string) (token string, source string, err error) + + // The following methods are only for testing and that is a design smell we should consider fixing. + + // SetActiveToken will override any token resolution and return the given token and source for all calls to + // ActiveToken. + // Use for testing purposes only. + SetActiveToken(token, source string) + + // SetHosts will override any hosts resolution and return the given hosts for all calls to Hosts. + // Use for testing purposes only. + SetHosts(hosts []string) + + // SetDefaultHost will override any host resolution and return the given host and source for all calls to + // DefaultHost. + // Use for testing purposes only. + SetDefaultHost(host, source string) +} + +// AliasConfig defines an interface for managing command aliases. +type AliasConfig interface { + // Get retrieves the expansion for a specified alias. + Get(alias string) (expansion string, err error) + + // Add adds a new alias with the specified expansion. + Add(alias, expansion string) + + // Delete removes an alias. + Delete(alias string) error + + // All returns a map of all aliases to their corresponding expansions. + All() map[string]string +} diff --git a/internal/config/config_mock.go b/internal/gh/mock/config.go similarity index 94% rename from internal/config/config_mock.go rename to internal/gh/mock/config.go index fc25ad850..736c8c262 100644 --- a/internal/config/config_mock.go +++ b/internal/gh/mock/config.go @@ -1,26 +1,27 @@ // Code generated by moq; DO NOT EDIT. // github.com/matryer/moq -package config +package ghmock import ( + "github.com/cli/cli/v2/internal/gh" "sync" ) -// Ensure, that ConfigMock does implement Config. +// Ensure, that ConfigMock does implement gh.Config. // If this is not the case, regenerate this file with moq. -var _ Config = &ConfigMock{} +var _ gh.Config = &ConfigMock{} -// ConfigMock is a mock implementation of Config. +// ConfigMock is a mock implementation of gh.Config. // // func TestSomethingThatUsesConfig(t *testing.T) { // -// // make and configure a mocked Config +// // make and configure a mocked gh.Config // mockedConfig := &ConfigMock{ -// AliasesFunc: func() *AliasConfig { +// AliasesFunc: func() gh.AliasConfig { // panic("mock out the Aliases method") // }, -// AuthenticationFunc: func() *AuthConfig { +// AuthenticationFunc: func() gh.AuthConfig { // panic("mock out the Authentication method") // }, // BrowserFunc: func(s string) string { @@ -41,7 +42,7 @@ var _ Config = &ConfigMock{} // HTTPUnixSocketFunc: func(s string) string { // panic("mock out the HTTPUnixSocket method") // }, -// MigrateFunc: func(migration Migration) error { +// MigrateFunc: func(migration gh.Migration) error { // panic("mock out the Migrate method") // }, // PagerFunc: func(s string) string { @@ -61,16 +62,16 @@ var _ Config = &ConfigMock{} // }, // } // -// // use mockedConfig in code that requires Config +// // use mockedConfig in code that requires gh.Config // // and then make assertions. // // } type ConfigMock struct { // AliasesFunc mocks the Aliases method. - AliasesFunc func() *AliasConfig + AliasesFunc func() gh.AliasConfig // AuthenticationFunc mocks the Authentication method. - AuthenticationFunc func() *AuthConfig + AuthenticationFunc func() gh.AuthConfig // BrowserFunc mocks the Browser method. BrowserFunc func(s string) string @@ -91,7 +92,7 @@ type ConfigMock struct { HTTPUnixSocketFunc func(s string) string // MigrateFunc mocks the Migrate method. - MigrateFunc func(migration Migration) error + MigrateFunc func(migration gh.Migration) error // PagerFunc mocks the Pager method. PagerFunc func(s string) string @@ -149,7 +150,7 @@ type ConfigMock struct { // Migrate holds details about calls to the Migrate method. Migrate []struct { // Migration is the migration argument value. - Migration Migration + Migration gh.Migration } // Pager holds details about calls to the Pager method. Pager []struct { @@ -194,7 +195,7 @@ type ConfigMock struct { } // Aliases calls AliasesFunc. -func (mock *ConfigMock) Aliases() *AliasConfig { +func (mock *ConfigMock) Aliases() gh.AliasConfig { if mock.AliasesFunc == nil { panic("ConfigMock.AliasesFunc: method is nil but Config.Aliases was just called") } @@ -221,7 +222,7 @@ func (mock *ConfigMock) AliasesCalls() []struct { } // Authentication calls AuthenticationFunc. -func (mock *ConfigMock) Authentication() *AuthConfig { +func (mock *ConfigMock) Authentication() gh.AuthConfig { if mock.AuthenticationFunc == nil { panic("ConfigMock.AuthenticationFunc: method is nil but Config.Authentication was just called") } @@ -439,12 +440,12 @@ func (mock *ConfigMock) HTTPUnixSocketCalls() []struct { } // Migrate calls MigrateFunc. -func (mock *ConfigMock) Migrate(migration Migration) error { +func (mock *ConfigMock) Migrate(migration gh.Migration) error { if mock.MigrateFunc == nil { panic("ConfigMock.MigrateFunc: method is nil but Config.Migrate was just called") } callInfo := struct { - Migration Migration + Migration gh.Migration }{ Migration: migration, } @@ -459,10 +460,10 @@ func (mock *ConfigMock) Migrate(migration Migration) error { // // len(mockedConfig.MigrateCalls()) func (mock *ConfigMock) MigrateCalls() []struct { - Migration Migration + Migration gh.Migration } { var calls []struct { - Migration Migration + Migration gh.Migration } mock.lockMigrate.RLock() calls = mock.calls.Migrate diff --git a/internal/config/migration_mock.go b/internal/gh/mock/migration.go similarity index 91% rename from internal/config/migration_mock.go rename to internal/gh/mock/migration.go index bf8133fb4..e534ef5c4 100644 --- a/internal/config/migration_mock.go +++ b/internal/gh/mock/migration.go @@ -1,22 +1,23 @@ // Code generated by moq; DO NOT EDIT. // github.com/matryer/moq -package config +package ghmock import ( + "github.com/cli/cli/v2/internal/gh" ghConfig "github.com/cli/go-gh/v2/pkg/config" "sync" ) -// Ensure, that MigrationMock does implement Migration. +// Ensure, that MigrationMock does implement gh.Migration. // If this is not the case, regenerate this file with moq. -var _ Migration = &MigrationMock{} +var _ gh.Migration = &MigrationMock{} -// MigrationMock is a mock implementation of Migration. +// MigrationMock is a mock implementation of gh.Migration. // // func TestSomethingThatUsesMigration(t *testing.T) { // -// // make and configure a mocked Migration +// // make and configure a mocked gh.Migration // mockedMigration := &MigrationMock{ // DoFunc: func(config *ghConfig.Config) error { // panic("mock out the Do method") @@ -29,7 +30,7 @@ var _ Migration = &MigrationMock{} // }, // } // -// // use mockedMigration in code that requires Migration +// // use mockedMigration in code that requires gh.Migration // // and then make assertions. // // } diff --git a/pkg/cmd/alias/delete/delete.go b/pkg/cmd/alias/delete/delete.go index 16e943044..da69504a8 100644 --- a/pkg/cmd/alias/delete/delete.go +++ b/pkg/cmd/alias/delete/delete.go @@ -4,14 +4,14 @@ import ( "fmt" "sort" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" ) type DeleteOptions struct { - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Name string diff --git a/pkg/cmd/alias/delete/delete_test.go b/pkg/cmd/alias/delete/delete_test.go index 9990abdfc..845119a80 100644 --- a/pkg/cmd/alias/delete/delete_test.go +++ b/pkg/cmd/alias/delete/delete_test.go @@ -7,6 +7,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -161,7 +162,7 @@ func TestDeleteRun(t *testing.T) { tt.opts.IO = ios cfg := config.NewFromString(tt.config) - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/alias/imports/import.go b/pkg/cmd/alias/imports/import.go index c70a150f3..78959ece3 100644 --- a/pkg/cmd/alias/imports/import.go +++ b/pkg/cmd/alias/imports/import.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/alias/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -15,7 +15,7 @@ import ( ) type ImportOptions struct { - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Filename string diff --git a/pkg/cmd/alias/imports/import_test.go b/pkg/cmd/alias/imports/import_test.go index 024f52f02..c2ae16e7a 100644 --- a/pkg/cmd/alias/imports/import_test.go +++ b/pkg/cmd/alias/imports/import_test.go @@ -11,6 +11,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/alias/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -309,7 +310,7 @@ func TestImportRun(t *testing.T) { readConfigs := config.StubWriteConfig(t) cfg := config.NewFromString(tt.initConfig) - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/alias/list/list.go b/pkg/cmd/alias/list/list.go index 2f17ed195..c648b2e6d 100644 --- a/pkg/cmd/alias/list/list.go +++ b/pkg/cmd/alias/list/list.go @@ -2,7 +2,7 @@ package list import ( "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -10,7 +10,7 @@ import ( ) type ListOptions struct { - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams } diff --git a/pkg/cmd/alias/list/list_test.go b/pkg/cmd/alias/list/list_test.go index 2f8af41cd..0af36a38d 100644 --- a/pkg/cmd/alias/list/list_test.go +++ b/pkg/cmd/alias/list/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/stretchr/testify/assert" @@ -66,7 +67,7 @@ func TestAliasList(t *testing.T) { factory := &cmdutil.Factory{ IOStreams: ios, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return cfg, nil }, } diff --git a/pkg/cmd/alias/set/set.go b/pkg/cmd/alias/set/set.go index e2661b7f7..c09f7c0cc 100644 --- a/pkg/cmd/alias/set/set.go +++ b/pkg/cmd/alias/set/set.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/alias/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -14,7 +14,7 @@ import ( ) type SetOptions struct { - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Name string diff --git a/pkg/cmd/alias/set/set_test.go b/pkg/cmd/alias/set/set_test.go index 4acb8b8b0..40198d878 100644 --- a/pkg/cmd/alias/set/set_test.go +++ b/pkg/cmd/alias/set/set_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/alias/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -284,7 +285,7 @@ func TestSetRun(t *testing.T) { cfg.WriteFunc = func() error { return nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/api/api.go b/pkg/cmd/api/api.go index 8184065ca..b44cef2d4 100644 --- a/pkg/cmd/api/api.go +++ b/pkg/cmd/api/api.go @@ -17,7 +17,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/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/factory" @@ -37,7 +37,7 @@ type ApiOptions struct { AppVersion string BaseRepo func() (ghrepo.Interface, error) Branch func() (string, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) IO *iostreams.IOStreams @@ -149,7 +149,7 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command $ gh api repos/{owner}/{repo}/issues --template \ '{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " | color "yellow"}}){{"\n"}}{{end}}' - # update allowed values of the "environment" custom property in a deeply nested array + # update allowed values of the "environment" custom property in a deeply nested array gh api --PATCH /orgs/{org}/properties/schema \ -F 'properties[][property_name]=environment' \ -F 'properties[][default_value]=production' \ diff --git a/pkg/cmd/api/api_test.go b/pkg/cmd/api/api_test.go index 55138b3c7..a565312cd 100644 --- a/pkg/cmd/api/api_test.go +++ b/pkg/cmd/api/api_test.go @@ -16,6 +16,8 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" + ghmock "github.com/cli/cli/v2/internal/gh/mock" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -662,7 +664,7 @@ func Test_apiRun(t *testing.T) { ios.SetStdoutTTY(tt.isatty) tt.options.IO = ios - tt.options.Config = func() (config.Config, error) { return config.NewBlankConfig(), nil } + tt.options.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.options.HttpClient = func() (*http.Client, error) { var tr roundTripper = func(req *http.Request) (*http.Response, error) { resp := tt.httpResponse @@ -737,7 +739,7 @@ func Test_apiRun_paginationREST(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -809,7 +811,7 @@ func Test_apiRun_arrayPaginationREST(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -881,7 +883,7 @@ func Test_apiRun_arrayPaginationREST_with_headers(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -950,7 +952,7 @@ func Test_apiRun_paginationGraphQL(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -1049,7 +1051,7 @@ func Test_apiRun_paginationGraphQL_slurp(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -1161,7 +1163,7 @@ func Test_apiRun_paginated_template(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, @@ -1208,7 +1210,7 @@ func Test_apiRun_DELETE(t *testing.T) { var gotRequest *http.Request err := apiRun(&ApiOptions{ IO: ios, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, HttpClient: func() (*http.Client, error) { @@ -1293,7 +1295,7 @@ func Test_apiRun_inputFile(t *testing.T) { } return &http.Client{Transport: tr}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } @@ -1324,9 +1326,9 @@ func Test_apiRun_cache(t *testing.T) { ios, _, stdout, stderr := iostreams.Test() options := ApiOptions{ IO: ios, - Config: func() (config.Config, error) { - return &config.ConfigMock{ - AuthenticationFunc: func() *config.AuthConfig { + Config: func() (gh.Config, error) { + return &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { return &config.AuthConfig{} }, // Cached responses are stored in a tempdir that gets automatically cleaned up @@ -1738,7 +1740,7 @@ func Test_apiRun_acceptHeader(t *testing.T) { ios, _, _, _ := iostreams.Test() tt.options.IO = ios - tt.options.Config = func() (config.Config, error) { + tt.options.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 64e84c0e2..9104dd175 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -9,7 +9,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -20,7 +20,7 @@ import ( type LoginOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) GitClient *git.Client Prompter shared.Prompt diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 73aec604f..d53dd3f0b 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -10,6 +10,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -281,7 +282,7 @@ func Test_loginRun_nontty(t *testing.T) { opts *LoginOptions env map[string]string httpStubs func(*httpmock.Registry) - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) wantHosts string wantErr string wantStderr string @@ -417,7 +418,7 @@ func Test_loginRun_nontty(t *testing.T) { Hostname: "github.com", Token: "newUserToken", }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { _, err := c.Authentication().Login("github.com", "monalisa", "abc123", "https", false) require.NoError(t, err) }, @@ -451,7 +452,7 @@ func Test_loginRun_nontty(t *testing.T) { if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -500,7 +501,7 @@ func Test_loginRun_Survey(t *testing.T) { httpStubs func(*httpmock.Registry) prompterStubs func(*prompter.PrompterMock) runStubs func(*run.CommandStubber) - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) wantHosts string wantErrOut *regexp.Regexp wantSecureToken string @@ -700,7 +701,7 @@ func Test_loginRun_Survey(t *testing.T) { return -1, prompter.NoSuchPromptErr(prompt) } }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { _, err := c.Authentication().Login("github.com", "monalisa", "abc123", "https", false) require.NoError(t, err) }, @@ -744,7 +745,7 @@ func Test_loginRun_Survey(t *testing.T) { if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/auth/logout/logout.go b/pkg/cmd/auth/logout/logout.go index 9d7642ee9..ef978ebac 100644 --- a/pkg/cmd/auth/logout/logout.go +++ b/pkg/cmd/auth/logout/logout.go @@ -6,7 +6,7 @@ import ( "slices" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -15,7 +15,7 @@ import ( type LogoutOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Prompter shared.Prompt Hostname string Username string diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index ca37770c3..02386c55b 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -124,7 +125,7 @@ type hostUsers struct { users []user } -type tokenAssertion func(t *testing.T, cfg config.Config) +type tokenAssertion func(t *testing.T, cfg gh.Config) func Test_logoutRun_tty(t *testing.T) { tests := []struct { @@ -322,7 +323,7 @@ func Test_logoutRun_tty(t *testing.T) { } } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -516,7 +517,7 @@ func Test_logoutRun_nontty(t *testing.T) { ) } } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -552,7 +553,7 @@ func Test_logoutRun_nontty(t *testing.T) { } func hasNoToken(hostname string) tokenAssertion { - return func(t *testing.T, cfg config.Config) { + return func(t *testing.T, cfg gh.Config) { t.Helper() token, _ := cfg.Authentication().ActiveToken(hostname) @@ -561,7 +562,7 @@ func hasNoToken(hostname string) tokenAssertion { } func hasActiveToken(hostname string, expectedToken string) tokenAssertion { - return func(t *testing.T, cfg config.Config) { + return func(t *testing.T, cfg gh.Config) { t.Helper() token, _ := cfg.Authentication().ActiveToken(hostname) diff --git a/pkg/cmd/auth/refresh/refresh.go b/pkg/cmd/auth/refresh/refresh.go index b77c45bac..4e675c532 100644 --- a/pkg/cmd/auth/refresh/refresh.go +++ b/pkg/cmd/auth/refresh/refresh.go @@ -8,7 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/authflow" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -21,7 +21,7 @@ type username string type RefreshOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient *http.Client GitClient *git.Client Prompter shared.Prompt diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 51fa66bd6..dfc52d949 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -441,7 +442,7 @@ func Test_refreshRun(t *testing.T) { _, err := cfg.Authentication().Login(hostname, "test-user", "abc123", "https", false) require.NoError(t, err) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/auth/setupgit/setupgit.go b/pkg/cmd/auth/setupgit/setupgit.go index cd7314dfd..6bf85a7f4 100644 --- a/pkg/cmd/auth/setupgit/setupgit.go +++ b/pkg/cmd/auth/setupgit/setupgit.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -18,7 +18,7 @@ type gitConfigurator interface { type SetupGitOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Hostname string Force bool gitConfigure gitConfigurator diff --git a/pkg/cmd/auth/setupgit/setupgit_test.go b/pkg/cmd/auth/setupgit/setupgit_test.go index c1982f553..9e6550e54 100644 --- a/pkg/cmd/auth/setupgit/setupgit_test.go +++ b/pkg/cmd/auth/setupgit/setupgit_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -81,7 +82,7 @@ func Test_setupGitRun(t *testing.T) { name string opts *SetupGitOptions setupErr error - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) expectedHostsSetup []string expectedErr error expectedErrOut string @@ -89,7 +90,7 @@ func Test_setupGitRun(t *testing.T) { { name: "opts.Config returns an error", opts: &SetupGitOptions{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return nil, fmt.Errorf("oops") }, }, @@ -100,7 +101,7 @@ func Test_setupGitRun(t *testing.T) { opts: &SetupGitOptions{ Hostname: "ghe.io", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) }, expectedErr: errors.New("You are not logged into the GitHub host \"ghe.io\". Run gh auth login -h ghe.io to authenticate or provide `--force`"), @@ -118,7 +119,7 @@ func Test_setupGitRun(t *testing.T) { opts: &SetupGitOptions{ Hostname: "ghe.io", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false) }, expectedHostsSetup: []string{"ghe.io"}, @@ -129,7 +130,7 @@ func Test_setupGitRun(t *testing.T) { Hostname: "ghe.io", }, setupErr: fmt.Errorf("broken"), - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false) }, expectedErr: errors.New("failed to set up git credential helper: broken"), @@ -144,7 +145,7 @@ func Test_setupGitRun(t *testing.T) { { name: "when there are known hosts, and no hostname is provided, set them all up", opts: &SetupGitOptions{}, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false) login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) }, @@ -154,7 +155,7 @@ func Test_setupGitRun(t *testing.T) { name: "when no hostname is provided but setting one up errors, that error is bubbled", opts: &SetupGitOptions{}, setupErr: fmt.Errorf("broken"), - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false) }, expectedErr: errors.New("failed to set up git credential helper: broken"), @@ -177,7 +178,7 @@ func Test_setupGitRun(t *testing.T) { } if tt.opts.Config == nil { - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } } @@ -201,7 +202,7 @@ func Test_setupGitRun(t *testing.T) { } } -func login(t *testing.T, c config.Config, hostname, username, token, gitProtocol string, secureStorage bool) { +func login(t *testing.T, c gh.Config, hostname, username, token, gitProtocol string, secureStorage bool) { t.Helper() _, err := c.Authentication().Login(hostname, username, token, gitProtocol, secureStorage) require.NoError(t, err) diff --git a/pkg/cmd/auth/shared/writeable.go b/pkg/cmd/auth/shared/writeable.go index e5ae91469..381c7e02a 100644 --- a/pkg/cmd/auth/shared/writeable.go +++ b/pkg/cmd/auth/shared/writeable.go @@ -3,10 +3,10 @@ package shared import ( "strings" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" ) -func AuthTokenWriteable(authCfg *config.AuthConfig, hostname string) (string, bool) { +func AuthTokenWriteable(authCfg gh.AuthConfig, hostname string) (string, bool) { token, src := authCfg.ActiveToken(hostname) return src, (token == "" || !strings.HasSuffix(src, "_TOKEN")) } diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index b6ae21cb6..deb5ca6a1 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -12,6 +12,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/gh" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -124,7 +125,7 @@ func (e Entries) Strings(cs *iostreams.ColorScheme) []string { type StatusOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Hostname string ShowToken bool diff --git a/pkg/cmd/auth/status/status_test.go b/pkg/cmd/auth/status/status_test.go index a96b36c5b..ce4897978 100644 --- a/pkg/cmd/auth/status/status_test.go +++ b/pkg/cmd/auth/status/status_test.go @@ -10,6 +10,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -80,7 +81,7 @@ func Test_statusRun(t *testing.T) { opts StatusOptions env map[string]string httpStubs func(*httpmock.Registry) - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) wantErr error wantOut string wantErrOut string @@ -90,7 +91,7 @@ func Test_statusRun(t *testing.T) { opts: StatusOptions{ Hostname: "github.com", }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "abc123", "https") }, httpStubs: func(reg *httpmock.Registry) { @@ -110,7 +111,7 @@ func Test_statusRun(t *testing.T) { opts: StatusOptions{ Hostname: "ghe.io", }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "gho_abc123", "https") login(t, c, "ghe.io", "monalisa-ghe", "gho_abc123", "https") }, @@ -130,7 +131,7 @@ func Test_statusRun(t *testing.T) { { name: "missing scope", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "ghe.io", "monalisa-ghe", "gho_abc123", "https") }, httpStubs: func(reg *httpmock.Registry) { @@ -151,7 +152,7 @@ func Test_statusRun(t *testing.T) { { name: "bad token", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "ghe.io", "monalisa-ghe", "gho_abc123", "https") }, httpStubs: func(reg *httpmock.Registry) { @@ -170,7 +171,7 @@ func Test_statusRun(t *testing.T) { { name: "all good", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "gho_abc123", "https") login(t, c, "ghe.io", "monalisa-ghe", "gho_abc123", "ssh") }, @@ -204,7 +205,7 @@ func Test_statusRun(t *testing.T) { name: "token from env", opts: StatusOptions{}, env: map[string]string{"GH_TOKEN": "gho_abc123"}, - cfgStubs: func(t *testing.T, c config.Config) {}, + cfgStubs: func(t *testing.T, c gh.Config) {}, httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("GET", ""), @@ -225,7 +226,7 @@ func Test_statusRun(t *testing.T) { { name: "server-to-server token", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "ghs_abc123", "https") }, httpStubs: func(reg *httpmock.Registry) { @@ -245,7 +246,7 @@ func Test_statusRun(t *testing.T) { { name: "PAT V2 token", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "github_pat_abc123", "https") }, httpStubs: func(reg *httpmock.Registry) { @@ -267,7 +268,7 @@ func Test_statusRun(t *testing.T) { opts: StatusOptions{ ShowToken: true, }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "gho_abc123", "https") login(t, c, "ghe.io", "monalisa-ghe", "gho_xyz456", "https") }, @@ -298,7 +299,7 @@ func Test_statusRun(t *testing.T) { opts: StatusOptions{ Hostname: "github.example.com", }, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "abc123", "https") }, httpStubs: func(reg *httpmock.Registry) {}, @@ -308,7 +309,7 @@ func Test_statusRun(t *testing.T) { { name: "multiple accounts on a host", opts: StatusOptions{}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "gho_abc123", "https") login(t, c, "github.com", "monalisa-2", "gho_abc123", "https") }, @@ -335,7 +336,7 @@ func Test_statusRun(t *testing.T) { name: "multiple hosts with multiple accounts with environment tokens and with errors", opts: StatusOptions{}, env: map[string]string{"GH_ENTERPRISE_TOKEN": "gho_abc123"}, - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { login(t, c, "github.com", "monalisa", "gho_def456", "https") login(t, c, "github.com", "monalisa-2", "gho_ghi789", "https") login(t, c, "ghe.io", "monalisa-ghe", "gho_xyz123", "ssh") @@ -398,7 +399,7 @@ func Test_statusRun(t *testing.T) { if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -430,7 +431,7 @@ func Test_statusRun(t *testing.T) { } } -func login(t *testing.T, c config.Config, hostname, username, protocol, token string) { +func login(t *testing.T, c gh.Config, hostname, username, protocol, token string) { t.Helper() _, err := c.Authentication().Login(hostname, username, protocol, token, false) require.NoError(t, err) diff --git a/pkg/cmd/auth/switch/switch.go b/pkg/cmd/auth/switch/switch.go index a01017609..8822c407b 100644 --- a/pkg/cmd/auth/switch/switch.go +++ b/pkg/cmd/auth/switch/switch.go @@ -6,7 +6,7 @@ import ( "slices" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -15,7 +15,7 @@ import ( type SwitchOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Prompter shared.Prompt Hostname string Username string diff --git a/pkg/cmd/auth/switch/switch_test.go b/pkg/cmd/auth/switch/switch_test.go index efb69a56b..6ca77f44c 100644 --- a/pkg/cmd/auth/switch/switch_test.go +++ b/pkg/cmd/auth/switch/switch_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/keyring" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -403,7 +404,7 @@ func TestSwitchRun(t *testing.T) { } } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/auth/token/token.go b/pkg/cmd/auth/token/token.go index 10a301965..9f4dcc1ac 100644 --- a/pkg/cmd/auth/token/token.go +++ b/pkg/cmd/auth/token/token.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -12,7 +12,7 @@ import ( type TokenOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Hostname string Username string diff --git a/pkg/cmd/auth/token/token_test.go b/pkg/cmd/auth/token/token_test.go index 995653fd1..1d731f2ed 100644 --- a/pkg/cmd/auth/token/token_test.go +++ b/pkg/cmd/auth/token/token_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -56,7 +57,7 @@ func TestNewCmdToken(t *testing.T) { ios, _, _, _ := iostreams.Test() f := &cmdutil.Factory{ IOStreams: ios, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { cfg := config.NewBlankConfig() return cfg, nil }, @@ -96,7 +97,7 @@ func TestTokenRun(t *testing.T) { name string opts TokenOptions env map[string]string - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) wantStdout string wantErr bool wantErrMsg string @@ -104,7 +105,7 @@ func TestTokenRun(t *testing.T) { { name: "token", opts: TokenOptions{}, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) }, wantStdout: "gho_ABCDEFG\n", @@ -114,7 +115,7 @@ func TestTokenRun(t *testing.T) { opts: TokenOptions{ Hostname: "github.mycompany.com", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) login(t, cfg, "github.mycompany.com", "test-user", "gho_1234567", "https", false) }, @@ -138,7 +139,7 @@ func TestTokenRun(t *testing.T) { { name: "uses default host when one is not provided", opts: TokenOptions{}, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) login(t, cfg, "github.mycompany.com", "test-user", "gho_1234567", "https", false) }, @@ -151,7 +152,7 @@ func TestTokenRun(t *testing.T) { Hostname: "github.com", Username: "test-user", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false) login(t, cfg, "github.com", "test-user-2", "gho_1234567", "https", false) }, @@ -173,7 +174,7 @@ func TestTokenRun(t *testing.T) { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -193,7 +194,7 @@ func TestTokenRunSecureStorage(t *testing.T) { tests := []struct { name string opts TokenOptions - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) wantStdout string wantErr bool wantErrMsg string @@ -201,7 +202,7 @@ func TestTokenRunSecureStorage(t *testing.T) { { name: "token", opts: TokenOptions{}, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true) }, wantStdout: "gho_ABCDEFG\n", @@ -211,7 +212,7 @@ func TestTokenRunSecureStorage(t *testing.T) { opts: TokenOptions{ Hostname: "mycompany.com", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "mycompany.com", "test-user", "gho_1234567", "https", true) }, wantStdout: "gho_1234567\n", @@ -237,7 +238,7 @@ func TestTokenRunSecureStorage(t *testing.T) { Hostname: "github.com", Username: "test-user", }, - cfgStubs: func(t *testing.T, cfg config.Config) { + cfgStubs: func(t *testing.T, cfg gh.Config) { login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true) login(t, cfg, "github.com", "test-user-2", "gho_1234567", "https", true) }, @@ -256,7 +257,7 @@ func TestTokenRunSecureStorage(t *testing.T) { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } @@ -272,7 +273,7 @@ func TestTokenRunSecureStorage(t *testing.T) { } } -func login(t *testing.T, c config.Config, hostname, username, token, gitProtocol string, secureStorage bool) { +func login(t *testing.T, c gh.Config, hostname, username, token, gitProtocol string, secureStorage bool) { t.Helper() _, err := c.Authentication().Login(hostname, username, token, gitProtocol, secureStorage) require.NoError(t, err) diff --git a/pkg/cmd/config/get/get.go b/pkg/cmd/config/get/get.go index b65cf6bd3..e714c6a64 100644 --- a/pkg/cmd/config/get/get.go +++ b/pkg/cmd/config/get/get.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -13,7 +13,7 @@ import ( type GetOptions struct { IO *iostreams.IOStreams - Config config.Config + Config gh.Config Hostname string Key string diff --git a/pkg/cmd/config/get/get_test.go b/pkg/cmd/config/get/get_test.go index baebb584a..40eca49e5 100644 --- a/pkg/cmd/config/get/get_test.go +++ b/pkg/cmd/config/get/get_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -41,7 +42,7 @@ func TestNewCmdConfigGet(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } @@ -86,7 +87,7 @@ func Test_getRun(t *testing.T) { name: "get key", input: &GetOptions{ Key: "editor", - Config: func() config.Config { + Config: func() gh.Config { cfg := config.NewBlankConfig() cfg.Set("", "editor", "ed") return cfg @@ -99,7 +100,7 @@ func Test_getRun(t *testing.T) { input: &GetOptions{ Hostname: "github.com", Key: "editor", - Config: func() config.Config { + Config: func() gh.Config { cfg := config.NewBlankConfig() cfg.Set("", "editor", "ed") cfg.Set("github.com", "editor", "vim") diff --git a/pkg/cmd/config/list/list.go b/pkg/cmd/config/list/list.go index 2faed3f15..da2707134 100644 --- a/pkg/cmd/config/list/list.go +++ b/pkg/cmd/config/list/list.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -11,7 +12,7 @@ import ( type ListOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) Hostname string } diff --git a/pkg/cmd/config/list/list_test.go b/pkg/cmd/config/list/list_test.go index 945979414..32088b324 100644 --- a/pkg/cmd/config/list/list_test.go +++ b/pkg/cmd/config/list/list_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -35,7 +36,7 @@ func TestNewCmdConfigList(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } @@ -71,13 +72,13 @@ func Test_listRun(t *testing.T) { tests := []struct { name string input *ListOptions - config config.Config + config gh.Config stdout string wantErr bool }{ { name: "list", - config: func() config.Config { + config: func() gh.Config { cfg := config.NewBlankConfig() cfg.Set("HOST", "git_protocol", "ssh") cfg.Set("HOST", "editor", "/usr/bin/vim") @@ -101,7 +102,7 @@ browser=brave for _, tt := range tests { ios, _, stdout, _ := iostreams.Test() tt.input.IO = ios - tt.input.Config = func() (config.Config, error) { + tt.input.Config = func() (gh.Config, error) { return tt.config, nil } diff --git a/pkg/cmd/config/set/set.go b/pkg/cmd/config/set/set.go index e99bfb17c..dedbd0044 100644 --- a/pkg/cmd/config/set/set.go +++ b/pkg/cmd/config/set/set.go @@ -7,6 +7,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -14,7 +15,7 @@ import ( type SetOptions struct { IO *iostreams.IOStreams - Config config.Config + Config gh.Config Key string Value string diff --git a/pkg/cmd/config/set/set_test.go b/pkg/cmd/config/set/set_test.go index 2e26fd044..532d78f62 100644 --- a/pkg/cmd/config/set/set_test.go +++ b/pkg/cmd/config/set/set_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/google/shlex" @@ -49,7 +50,7 @@ func TestNewCmdConfigSet(t *testing.T) { _ = config.StubWriteConfig(t) f := &cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } diff --git a/pkg/cmd/extension/browse/browse.go b/pkg/cmd/extension/browse/browse.go index 47b3ea8b2..21d254956 100644 --- a/pkg/cmd/extension/browse/browse.go +++ b/pkg/cmd/extension/browse/browse.go @@ -13,7 +13,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/charmbracelet/glamour" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/iostreams" @@ -33,7 +33,7 @@ type ExtBrowseOpts struct { Em extensions.ExtensionManager Client *http.Client Logger *log.Logger - Cfg config.Config + Cfg gh.Config Rg *readmeGetter Debug bool SingleColumn bool diff --git a/pkg/cmd/extension/browse/browse_test.go b/pkg/cmd/extension/browse/browse_test.go index 3c4ae87ca..956ea0fc4 100644 --- a/pkg/cmd/extension/browse/browse_test.go +++ b/pkg/cmd/extension/browse/browse_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/repo/view" "github.com/cli/cli/v2/pkg/extensions" @@ -76,7 +77,7 @@ func Test_getExtensionRepos(t *testing.T) { } cfg := config.NewBlankConfig() - cfg.AuthenticationFunc = func() *config.AuthConfig { + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetDefaultHost("github.com", "") return authCfg diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index 094fa330a..a7e9d5171 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -13,6 +13,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -888,7 +889,7 @@ func TestNewCmdExtension(t *testing.T) { } f := cmdutil.Factory{ - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, IOStreams: ios, diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index a8d0db844..37d80573a 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -17,6 +17,7 @@ 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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/findsh" @@ -36,7 +37,7 @@ type Manager struct { platform func() (string, string) client *http.Client gitClient gitClient - config config.Config + config gh.Config io *iostreams.IOStreams dryRunMode bool } @@ -59,7 +60,7 @@ func NewManager(ios *iostreams.IOStreams, gc *git.Client) *Manager { } } -func (m *Manager) SetConfig(cfg config.Config) { +func (m *Manager) SetConfig(cfg gh.Config) { m.config = cfg } diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index dc5b37138..cb38c10fe 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -13,6 +13,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/extension" @@ -134,10 +135,10 @@ func newPrompter(f *cmdutil.Factory) prompter.Prompter { return prompter.New(editor, io.In, io.Out, io.ErrOut) } -func configFunc() func() (config.Config, error) { - var cachedConfig config.Config +func configFunc() func() (gh.Config, error) { + var cachedConfig gh.Config var configError error - return func() (config.Config, error) { + return func() (gh.Config, error) { if cachedConfig != nil || configError != nil { return cachedConfig, configError } diff --git a/pkg/cmd/factory/default_test.go b/pkg/cmd/factory/default_test.go index efd2f7793..94955bb30 100644 --- a/pkg/cmd/factory/default_test.go +++ b/pkg/cmd/factory/default_test.go @@ -9,6 +9,8 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" + ghmock "github.com/cli/cli/v2/internal/gh/mock" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -69,9 +71,9 @@ func Test_BaseRepo(t *testing.T) { readRemotes: func() (git.RemoteSet, error) { return tt.remotes, nil }, - getConfig: func() (config.Config, error) { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + getConfig: func() (gh.Config, error) { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} hosts := []string{"nonsense.com"} if tt.override != "" { @@ -207,9 +209,9 @@ func Test_SmartBaseRepo(t *testing.T) { readRemotes: func() (git.RemoteSet, error) { return tt.remotes, nil }, - getConfig: func() (config.Config, error) { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + getConfig: func() (gh.Config, error) { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} hosts := []string{"nonsense.com"} if tt.override != "" { @@ -256,7 +258,7 @@ func Test_OverrideBaseRepo(t *testing.T) { tests := []struct { name string remotes git.RemoteSet - config config.Config + config gh.Config envOverride string argOverride string wantsErr bool @@ -300,7 +302,7 @@ func Test_OverrideBaseRepo(t *testing.T) { readRemotes: func() (git.RemoteSet, error) { return tt.remotes, nil }, - getConfig: func() (config.Config, error) { + getConfig: func() (gh.Config, error) { return tt.config, nil }, } @@ -323,7 +325,7 @@ func Test_ioStreams_pager(t *testing.T) { tests := []struct { name string env map[string]string - config config.Config + config gh.Config wantPager string }{ { @@ -374,7 +376,7 @@ func Test_ioStreams_pager(t *testing.T) { } } f := New("1") - f.Config = func() (config.Config, error) { + f.Config = func() (gh.Config, error) { if tt.config == nil { return config.NewBlankConfig(), nil } else { @@ -390,7 +392,7 @@ func Test_ioStreams_pager(t *testing.T) { func Test_ioStreams_prompt(t *testing.T) { tests := []struct { name string - config config.Config + config gh.Config promptDisabled bool env map[string]string }{ @@ -417,7 +419,7 @@ func Test_ioStreams_prompt(t *testing.T) { } } f := New("1") - f.Config = func() (config.Config, error) { + f.Config = func() (gh.Config, error) { if tt.config == nil { return config.NewBlankConfig(), nil } else { @@ -458,7 +460,7 @@ func TestSSOURL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := New("1") - f.Config = func() (config.Config, error) { + f.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } ios, _, _, stderr := iostreams.Test() @@ -487,7 +489,7 @@ func TestSSOURL(t *testing.T) { func TestNewGitClient(t *testing.T) { tests := []struct { name string - config config.Config + config gh.Config executable string wantAuthHosts []string wantGhPath string @@ -503,7 +505,7 @@ func TestNewGitClient(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := New("1") - f.Config = func() (config.Config, error) { + f.Config = func() (gh.Config, error) { if tt.config == nil { return config.NewBlankConfig(), nil } else { @@ -522,16 +524,16 @@ func TestNewGitClient(t *testing.T) { } } -func defaultConfig() *config.ConfigMock { +func defaultConfig() *ghmock.ConfigMock { cfg := config.NewFromString("") cfg.Set("nonsense.com", "oauth_token", "BLAH") return cfg } -func pagerConfig() config.Config { +func pagerConfig() gh.Config { return config.NewFromString("pager: CONFIG_PAGER") } -func disablePromptConfig() config.Config { +func disablePromptConfig() gh.Config { return config.NewFromString("prompt: disabled") } diff --git a/pkg/cmd/factory/remote_resolver.go b/pkg/cmd/factory/remote_resolver.go index 6ef7c5e02..7e27834e2 100644 --- a/pkg/cmd/factory/remote_resolver.go +++ b/pkg/cmd/factory/remote_resolver.go @@ -7,7 +7,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/pkg/set" "github.com/cli/go-gh/v2/pkg/ssh" @@ -19,7 +19,7 @@ const ( type remoteResolver struct { readRemotes func() (git.RemoteSet, error) - getConfig func() (config.Config, error) + getConfig func() (gh.Config, error) urlTranslator context.Translator } diff --git a/pkg/cmd/factory/remote_resolver_test.go b/pkg/cmd/factory/remote_resolver_test.go index 0b4447ca0..8d537826e 100644 --- a/pkg/cmd/factory/remote_resolver_test.go +++ b/pkg/cmd/factory/remote_resolver_test.go @@ -6,6 +6,8 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" + ghmock "github.com/cli/cli/v2/internal/gh/mock" "github.com/stretchr/testify/assert" ) @@ -19,7 +21,7 @@ func Test_remoteResolver(t *testing.T) { tests := []struct { name string remotes func() (git.RemoteSet, error) - config config.Config + config gh.Config output []string wantsErr bool }{ @@ -30,9 +32,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://github.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{}) authCfg.SetDefaultHost("github.com", "default") @@ -47,9 +49,9 @@ func Test_remoteResolver(t *testing.T) { remotes: func() (git.RemoteSet, error) { return git.RemoteSet{}, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("example.com", "hosts") @@ -66,9 +68,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://test.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetActiveToken("", "") @@ -86,9 +88,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://github.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("example.com", "hosts") @@ -105,9 +107,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://example.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("example.com", "default") @@ -127,9 +129,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("fork", "https://example.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("example.com", "default") @@ -146,9 +148,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://test.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com", "github.com"}) authCfg.SetActiveToken("", "") @@ -167,9 +169,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://example.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com", "github.com"}) authCfg.SetDefaultHost("github.com", "default") @@ -190,9 +192,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("test", "https://test.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com", "github.com"}) authCfg.SetDefaultHost("github.com", "default") @@ -209,9 +211,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://example.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("test.com", "GH_HOST") @@ -229,9 +231,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://test.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com"}) authCfg.SetDefaultHost("test.com", "GH_HOST") @@ -250,9 +252,9 @@ func Test_remoteResolver(t *testing.T) { git.NewRemote("origin", "https://test.com/owner/repo.git"), }, nil }, - config: func() config.Config { - cfg := &config.ConfigMock{} - cfg.AuthenticationFunc = func() *config.AuthConfig { + config: func() gh.Config { + cfg := &ghmock.ConfigMock{} + cfg.AuthenticationFunc = func() gh.AuthConfig { authCfg := &config.AuthConfig{} authCfg.SetHosts([]string{"example.com", "test.com"}) authCfg.SetDefaultHost("test.com", "GH_HOST") @@ -268,7 +270,7 @@ func Test_remoteResolver(t *testing.T) { t.Run(tt.name, func(t *testing.T) { rr := &remoteResolver{ readRemotes: tt.remotes, - getConfig: func() (config.Config, error) { return tt.config, nil }, + getConfig: func() (gh.Config, error) { return tt.config, nil }, urlTranslator: identityTranslator{}, } resolver := rr.Resolver() diff --git a/pkg/cmd/gist/clone/clone.go b/pkg/cmd/gist/clone/clone.go index f33ee13c6..0f50bce31 100644 --- a/pkg/cmd/gist/clone/clone.go +++ b/pkg/cmd/gist/clone/clone.go @@ -7,7 +7,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -18,7 +18,7 @@ import ( type CloneOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams GitArgs []string diff --git a/pkg/cmd/gist/clone/clone_test.go b/pkg/cmd/gist/clone/clone_test.go index 58ce55b52..46ab53a0f 100644 --- a/pkg/cmd/gist/clone/clone_test.go +++ b/pkg/cmd/gist/clone/clone_test.go @@ -6,6 +6,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -22,7 +23,7 @@ func runCloneCommand(httpClient *http.Client, cli string) (*test.CmdOut, error) HttpClient: func() (*http.Client, error) { return httpClient, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, GitClient: &git.Client{ diff --git a/pkg/cmd/gist/create/create.go b/pkg/cmd/gist/create/create.go index ad293419f..4403df9be 100644 --- a/pkg/cmd/gist/create/create.go +++ b/pkg/cmd/gist/create/create.go @@ -16,7 +16,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/gist/shared" @@ -34,7 +34,7 @@ type CreateOptions struct { FilenameOverride string WebMode bool - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Browser browser.Browser } diff --git a/pkg/cmd/gist/create/create_test.go b/pkg/cmd/gist/create/create_test.go index 2302b96dd..40c89c0d8 100644 --- a/pkg/cmd/gist/create/create_test.go +++ b/pkg/cmd/gist/create/create_test.go @@ -13,6 +13,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -331,7 +332,7 @@ func Test_createRun(t *testing.T) { } tt.opts.HttpClient = mockClient - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gist/delete/delete.go b/pkg/cmd/gist/delete/delete.go index 22d27b65d..0b5224c8a 100644 --- a/pkg/cmd/gist/delete/delete.go +++ b/pkg/cmd/gist/delete/delete.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -16,7 +16,7 @@ import ( type DeleteOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Selector string diff --git a/pkg/cmd/gist/delete/delete_test.go b/pkg/cmd/gist/delete/delete_test.go index a6cde9ae0..00d9ab961 100644 --- a/pkg/cmd/gist/delete/delete_test.go +++ b/pkg/cmd/gist/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -99,7 +100,7 @@ func Test_deleteRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } ios, _, _, _ := iostreams.Test() diff --git a/pkg/cmd/gist/edit/edit.go b/pkg/cmd/gist/edit/edit.go index f2f04bd92..d777e9581 100644 --- a/pkg/cmd/gist/edit/edit.go +++ b/pkg/cmd/gist/edit/edit.go @@ -13,7 +13,7 @@ import ( "strings" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -27,7 +27,7 @@ var editNextOptions = []string{"Edit another file", "Submit", "Cancel"} type EditOptions struct { IO *iostreams.IOStreams HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) Prompter prompter.Prompter Edit func(string, string, string, *iostreams.IOStreams) (string, error) diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index b57fa41cc..11a32bc92 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -554,7 +555,7 @@ func Test_editRun(t *testing.T) { tt.opts.IO = ios tt.opts.Selector = "1234" - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gist/list/list.go b/pkg/cmd/gist/list/list.go index ee9fb2539..5d0e47150 100644 --- a/pkg/cmd/gist/list/list.go +++ b/pkg/cmd/gist/list/list.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/gist/shared" @@ -17,7 +17,7 @@ import ( type ListOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Limit int diff --git a/pkg/cmd/gist/list/list_test.go b/pkg/cmd/gist/list/list_test.go index 682ebe8dc..a15bae6aa 100644 --- a/pkg/cmd/gist/list/list_test.go +++ b/pkg/cmd/gist/list/list_test.go @@ -9,6 +9,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -367,7 +368,7 @@ func Test_listRun(t *testing.T) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gist/rename/rename.go b/pkg/cmd/gist/rename/rename.go index c23aca579..630e67019 100644 --- a/pkg/cmd/gist/rename/rename.go +++ b/pkg/cmd/gist/rename/rename.go @@ -10,7 +10,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/gh" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -19,7 +19,7 @@ import ( type RenameOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Selector string diff --git a/pkg/cmd/gist/rename/rename_test.go b/pkg/cmd/gist/rename/rename_test.go index 5413d87c9..e835cc8a7 100644 --- a/pkg/cmd/gist/rename/rename_test.go +++ b/pkg/cmd/gist/rename/rename_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -166,7 +167,7 @@ func TestRenameRun(t *testing.T) { tt.opts.NewFileName = "new.txt" tt.opts.IO = ios - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gist/view/view.go b/pkg/cmd/gist/view/view.go index e4f5c84e1..2a19f5958 100644 --- a/pkg/cmd/gist/view/view.go +++ b/pkg/cmd/gist/view/view.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/text" @@ -23,7 +23,7 @@ type browser interface { type ViewOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Browser browser Prompter prompter.Prompter diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index c571422c5..52e616f7c 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/gist/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -370,7 +371,7 @@ func Test_viewRun(t *testing.T) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gpg-key/add/add.go b/pkg/cmd/gpg-key/add/add.go index 54482d029..35ee12736 100644 --- a/pkg/cmd/gpg-key/add/add.go +++ b/pkg/cmd/gpg-key/add/add.go @@ -8,7 +8,7 @@ import ( "os" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -16,7 +16,7 @@ import ( type AddOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HTTPClient func() (*http.Client, error) KeyFile string diff --git a/pkg/cmd/gpg-key/add/add_test.go b/pkg/cmd/gpg-key/add/add_test.go index 3cce519cf..c6d7c18fb 100644 --- a/pkg/cmd/gpg-key/add/add_test.go +++ b/pkg/cmd/gpg-key/add/add_test.go @@ -6,6 +6,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" "github.com/stretchr/testify/assert" @@ -125,7 +126,7 @@ func Test_runAdd(t *testing.T) { if tt.httpStubs != nil { tt.httpStubs(reg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/gpg-key/delete/delete.go b/pkg/cmd/gpg-key/delete/delete.go index f86957bdb..d0fb5c0d6 100644 --- a/pkg/cmd/gpg-key/delete/delete.go +++ b/pkg/cmd/gpg-key/delete/delete.go @@ -5,7 +5,7 @@ import ( "net/http" "strconv" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -14,7 +14,7 @@ import ( type DeleteOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) KeyID string diff --git a/pkg/cmd/gpg-key/delete/delete_test.go b/pkg/cmd/gpg-key/delete/delete_test.go index c9c29aa3c..115e72db2 100644 --- a/pkg/cmd/gpg-key/delete/delete_test.go +++ b/pkg/cmd/gpg-key/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -201,7 +202,7 @@ func Test_deleteRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } ios, _, stdout, _ := iostreams.Test() diff --git a/pkg/cmd/gpg-key/list/list.go b/pkg/cmd/gpg-key/list/list.go index 4c594c584..9acf1d7b6 100644 --- a/pkg/cmd/gpg-key/list/list.go +++ b/pkg/cmd/gpg-key/list/list.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -15,7 +15,7 @@ import ( type ListOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HTTPClient func() (*http.Client, error) } diff --git a/pkg/cmd/gpg-key/list/list_test.go b/pkg/cmd/gpg-key/list/list_test.go index de702498c..daf8c991d 100644 --- a/pkg/cmd/gpg-key/list/list_test.go +++ b/pkg/cmd/gpg-key/list/list_test.go @@ -8,6 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" "github.com/stretchr/testify/assert" @@ -130,7 +131,7 @@ func Test_listRun(t *testing.T) { ios.SetStderrTTY(tt.isTTY) opts := tt.opts opts.IO = ios - opts.Config = func() (config.Config, error) { return config.NewBlankConfig(), nil } + opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } err := listRun(&opts) if tt.wantErr { assert.Error(t, err) diff --git a/pkg/cmd/issue/create/create.go b/pkg/cmd/issue/create/create.go index 9aa0fffa8..c359df2a0 100644 --- a/pkg/cmd/issue/create/create.go +++ b/pkg/cmd/issue/create/create.go @@ -8,7 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -19,7 +19,7 @@ import ( type CreateOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Browser browser.Browser diff --git a/pkg/cmd/issue/create/create_test.go b/pkg/cmd/issue/create/create_test.go index dcc4c7618..c70507327 100644 --- a/pkg/cmd/issue/create/create_test.go +++ b/pkg/cmd/issue/create/create_test.go @@ -14,6 +14,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" @@ -364,7 +365,7 @@ func runCommandWithRootDirOverridden(rt http.RoundTripper, isTTY bool, cli strin HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/delete/delete.go b/pkg/cmd/issue/delete/delete.go index 71c39da74..a70c6abb2 100644 --- a/pkg/cmd/issue/delete/delete.go +++ b/pkg/cmd/issue/delete/delete.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -16,7 +16,7 @@ import ( type DeleteOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Prompter iprompter diff --git a/pkg/cmd/issue/delete/delete_test.go b/pkg/cmd/issue/delete/delete_test.go index 287326268..bd83c826f 100644 --- a/pkg/cmd/issue/delete/delete_test.go +++ b/pkg/cmd/issue/delete/delete_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -31,7 +32,7 @@ func runCommand(rt http.RoundTripper, pm *prompter.MockPrompter, isTTY bool, cli HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/list/list.go b/pkg/cmd/issue/list/list.go index 20e77e141..47da51ae4 100644 --- a/pkg/cmd/issue/list/list.go +++ b/pkg/cmd/issue/list/list.go @@ -10,8 +10,8 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" fd "github.com/cli/cli/v2/internal/featuredetection" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" issueShared "github.com/cli/cli/v2/pkg/cmd/issue/shared" @@ -24,7 +24,7 @@ import ( type ListOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Browser browser.Browser diff --git a/pkg/cmd/issue/list/list_test.go b/pkg/cmd/issue/list/list_test.go index 5bed620c1..e45fc76e4 100644 --- a/pkg/cmd/issue/list/list_test.go +++ b/pkg/cmd/issue/list/list_test.go @@ -11,6 +11,7 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -34,7 +35,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/lock/lock.go b/pkg/cmd/issue/lock/lock.go index d33040798..4e0dac058 100644 --- a/pkg/cmd/issue/lock/lock.go +++ b/pkg/cmd/issue/lock/lock.go @@ -17,7 +17,7 @@ import ( "strings" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" issueShared "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -92,7 +92,7 @@ func fields() []string { type LockOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Prompter iprompter diff --git a/pkg/cmd/issue/pin/pin.go b/pkg/cmd/issue/pin/pin.go index 17032eff7..dfb11a881 100644 --- a/pkg/cmd/issue/pin/pin.go +++ b/pkg/cmd/issue/pin/pin.go @@ -6,7 +6,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,7 +17,7 @@ import ( type PinOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) SelectorArg string diff --git a/pkg/cmd/issue/pin/pin_test.go b/pkg/cmd/issue/pin/pin_test.go index b5c49622f..d4979a30d 100644 --- a/pkg/cmd/issue/pin/pin_test.go +++ b/pkg/cmd/issue/pin/pin_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -139,7 +140,7 @@ func TestPinRun(t *testing.T) { ios.SetStdoutTTY(tt.tty) tt.opts.IO = ios - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/issue/reopen/reopen.go b/pkg/cmd/issue/reopen/reopen.go index 1a011a5f5..92f18a7d9 100644 --- a/pkg/cmd/issue/reopen/reopen.go +++ b/pkg/cmd/issue/reopen/reopen.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/issue/shared" prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -17,7 +17,7 @@ import ( type ReopenOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) diff --git a/pkg/cmd/issue/reopen/reopen_test.go b/pkg/cmd/issue/reopen/reopen_test.go index ceb3265f8..4b8b33ee1 100644 --- a/pkg/cmd/issue/reopen/reopen_test.go +++ b/pkg/cmd/issue/reopen/reopen_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -28,7 +29,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/status/status.go b/pkg/cmd/issue/status/status.go index c9db94c98..a57cd7d9e 100644 --- a/pkg/cmd/issue/status/status.go +++ b/pkg/cmd/issue/status/status.go @@ -6,7 +6,7 @@ import ( "time" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" issueShared "github.com/cli/cli/v2/pkg/cmd/issue/shared" prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -17,7 +17,7 @@ import ( type StatusOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) diff --git a/pkg/cmd/issue/status/status_test.go b/pkg/cmd/issue/status/status_test.go index 297b45c06..6fddf3b0c 100644 --- a/pkg/cmd/issue/status/status_test.go +++ b/pkg/cmd/issue/status/status_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -27,7 +28,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/transfer/transfer.go b/pkg/cmd/issue/transfer/transfer.go index 8844e861f..140d02b91 100644 --- a/pkg/cmd/issue/transfer/transfer.go +++ b/pkg/cmd/issue/transfer/transfer.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -16,7 +16,7 @@ import ( type TransferOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) diff --git a/pkg/cmd/issue/transfer/transfer_test.go b/pkg/cmd/issue/transfer/transfer_test.go index 1f2f665e0..eed9c5d85 100644 --- a/pkg/cmd/issue/transfer/transfer_test.go +++ b/pkg/cmd/issue/transfer/transfer_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -24,7 +25,7 @@ func runCommand(rt http.RoundTripper, cli string) (*test.CmdOut, error) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/issue/unpin/unpin.go b/pkg/cmd/issue/unpin/unpin.go index 428f8cde9..3ac28d47c 100644 --- a/pkg/cmd/issue/unpin/unpin.go +++ b/pkg/cmd/issue/unpin/unpin.go @@ -6,7 +6,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/issue/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,7 +17,7 @@ import ( type UnpinOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) SelectorArg string diff --git a/pkg/cmd/issue/unpin/unpin_test.go b/pkg/cmd/issue/unpin/unpin_test.go index ad7bf7aef..70a018d94 100644 --- a/pkg/cmd/issue/unpin/unpin_test.go +++ b/pkg/cmd/issue/unpin/unpin_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -139,7 +140,7 @@ func TestUnpinRun(t *testing.T) { ios.SetStdoutTTY(tt.tty) tt.opts.IO = ios - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/issue/view/view_test.go b/pkg/cmd/issue/view/view_test.go index f42895920..2f91ba13e 100644 --- a/pkg/cmd/issue/view/view_test.go +++ b/pkg/cmd/issue/view/view_test.go @@ -10,6 +10,7 @@ import ( "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -31,7 +32,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/org/list/list.go b/pkg/cmd/org/list/list.go index 888d76c74..0c2b96f78 100644 --- a/pkg/cmd/org/list/list.go +++ b/pkg/cmd/org/list/list.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/MakeNowJust/heredoc" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -14,7 +14,7 @@ import ( type ListOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Limit int diff --git a/pkg/cmd/org/list/list_test.go b/pkg/cmd/org/list/list_test.go index 8efc0a49e..3f81419e8 100644 --- a/pkg/cmd/org/list/list_test.go +++ b/pkg/cmd/org/list/list_test.go @@ -7,6 +7,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -95,7 +96,7 @@ func TestListRun(t *testing.T) { r.Register( httpmock.GraphQL(`query OrganizationList\b`), httpmock.StringResponse(` - { "data": { "user": { + { "data": { "user": { "organizations": { "nodes": [], "totalCount": 0 } } } }`, ), @@ -224,7 +225,7 @@ cli ios.SetStderrTTY(tt.isTTY) tt.opts.IO = ios - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index 269c8aaab..f47f579f2 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -9,7 +9,7 @@ import ( "github.com/cli/cli/v2/api" cliContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/pr/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -20,7 +20,7 @@ import ( type CheckoutOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Remotes func() (cliContext.Remotes, error) Branch func() (string, error) diff --git a/pkg/cmd/pr/checkout/checkout_test.go b/pkg/cmd/pr/checkout/checkout_test.go index cc9aed0f0..1eda5dda2 100644 --- a/pkg/cmd/pr/checkout/checkout_test.go +++ b/pkg/cmd/pr/checkout/checkout_test.go @@ -12,6 +12,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -82,7 +83,7 @@ func Test_checkoutRun(t *testing.T) { finder := shared.NewMockFinder("123", pr, baseRepo) return finder }(), - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Branch: func() (string, error) { @@ -111,7 +112,7 @@ func Test_checkoutRun(t *testing.T) { finder := shared.NewMockFinder("123", pr, baseRepo) return finder }(), - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Branch: func() (string, error) { @@ -138,7 +139,7 @@ func Test_checkoutRun(t *testing.T) { finder := shared.NewMockFinder("123", pr, baseRepo) return finder }(), - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Branch: func() (string, error) { @@ -222,7 +223,7 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cl HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Remotes: func() (context.Remotes, error) { diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 38bc81a72..54b6358ac 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -18,7 +18,7 @@ import ( ghContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -32,7 +32,7 @@ type CreateOptions struct { // This struct stores user input and factory functions HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Remotes func() (ghContext.Remotes, error) Branch func() (string, error) diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index b7d0e46ae..3b64688c3 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -16,6 +16,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" @@ -1411,7 +1412,7 @@ func Test_createRun(t *testing.T) { opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - opts.Config = func() (config.Config, error) { + opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } opts.Remotes = func() (context.Remotes, error) { diff --git a/pkg/cmd/pr/edit/edit.go b/pkg/cmd/pr/edit/edit.go index d0dbcfbc2..3f80aa80a 100644 --- a/pkg/cmd/pr/edit/edit.go +++ b/pkg/cmd/pr/edit/edit.go @@ -6,7 +6,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/gh" "github.com/cli/cli/v2/internal/ghrepo" shared "github.com/cli/cli/v2/pkg/cmd/pr/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -309,7 +309,7 @@ type EditorRetriever interface { } type editorRetriever struct { - config func() (config.Config, error) + config func() (gh.Config, error) } func (e editorRetriever) Retrieve() (string, error) { diff --git a/pkg/cmd/pr/merge/merge.go b/pkg/cmd/pr/merge/merge.go index a2f16e4da..1e7deabcb 100644 --- a/pkg/cmd/pr/merge/merge.go +++ b/pkg/cmd/pr/merge/merge.go @@ -10,7 +10,7 @@ import ( "github.com/cli/cli/v2/api" ghContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/pr/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -680,7 +680,7 @@ func confirmSubmission(client *http.Client, opts *MergeOptions, action shared.Ac type userEditor struct { io *iostreams.IOStreams - config func() (config.Config, error) + config func() (gh.Config, error) } func (e *userEditor) Edit(filename, startingText string) (string, error) { diff --git a/pkg/cmd/pr/review/review.go b/pkg/cmd/pr/review/review.go index b1cc500c2..4fa973a87 100644 --- a/pkg/cmd/pr/review/review.go +++ b/pkg/cmd/pr/review/review.go @@ -7,7 +7,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -19,7 +19,7 @@ import ( type ReviewOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Prompter prompter.Prompter diff --git a/pkg/cmd/pr/review/review_test.go b/pkg/cmd/pr/review/review_test.go index b27eb4f8a..f9e00c3b8 100644 --- a/pkg/cmd/pr/review/review_test.go +++ b/pkg/cmd/pr/review/review_test.go @@ -12,6 +12,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -176,7 +177,7 @@ func runCommand(rt http.RoundTripper, prompter prompter.Prompter, isTTY bool, cl HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Prompter: prompter, diff --git a/pkg/cmd/pr/shared/commentable.go b/pkg/cmd/pr/shared/commentable.go index 808960b24..7a38286d2 100644 --- a/pkg/cmd/pr/shared/commentable.go +++ b/pkg/cmd/pr/shared/commentable.go @@ -8,7 +8,7 @@ import ( "net/http" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmdutil" @@ -206,7 +206,7 @@ func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) { } } -func CommentableInteractiveEditSurvey(cf func() (config.Config, error), io *iostreams.IOStreams) func(string) (string, error) { +func CommentableInteractiveEditSurvey(cf func() (gh.Config, error), io *iostreams.IOStreams) func(string) (string, error) { return func(initialValue string) (string, error) { editorCommand, err := cmdutil.DetermineEditor(cf) if err != nil { @@ -219,7 +219,7 @@ func CommentableInteractiveEditSurvey(cf func() (config.Config, error), io *iost } } -func CommentableEditSurvey(cf func() (config.Config, error), io *iostreams.IOStreams) func(string) (string, error) { +func CommentableEditSurvey(cf func() (gh.Config, error), io *iostreams.IOStreams) func(string) (string, error) { return func(initialValue string) (string, error) { editorCommand, err := cmdutil.DetermineEditor(cf) if err != nil { diff --git a/pkg/cmd/pr/status/status.go b/pkg/cmd/pr/status/status.go index bb7bb735d..2cd28f2ed 100644 --- a/pkg/cmd/pr/status/status.go +++ b/pkg/cmd/pr/status/status.go @@ -13,8 +13,8 @@ import ( "github.com/cli/cli/v2/api" ghContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" fd "github.com/cli/cli/v2/internal/featuredetection" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/pr/shared" @@ -26,7 +26,7 @@ import ( type StatusOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Remotes func() (ghContext.Remotes, error) diff --git a/pkg/cmd/pr/status/status_test.go b/pkg/cmd/pr/status/status_test.go index 3df048503..e8e487559 100644 --- a/pkg/cmd/pr/status/status_test.go +++ b/pkg/cmd/pr/status/status_test.go @@ -13,6 +13,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" fd "github.com/cli/cli/v2/internal/featuredetection" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -37,7 +38,7 @@ func runCommandWithDetector(rt http.RoundTripper, branch string, isTTY bool, cli HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/project/link/link.go b/pkg/cmd/project/link/link.go index 56c7b5eba..1e334af8c 100644 --- a/pkg/cmd/project/link/link.go +++ b/pkg/cmd/project/link/link.go @@ -2,18 +2,19 @@ package link import ( "fmt" + "net/http" + "strconv" + "strings" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/project/shared/client" "github.com/cli/cli/v2/pkg/cmd/project/shared/queries" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" - "net/http" - "strconv" - "strings" ) type linkOpts struct { @@ -30,7 +31,7 @@ type linkOpts struct { type linkConfig struct { httpClient func() (*http.Client, error) - config func() (config.Config, error) + config func() (gh.Config, error) client *queries.Client opts linkOpts io *iostreams.IOStreams diff --git a/pkg/cmd/project/link/link_test.go b/pkg/cmd/project/link/link_test.go index cd9aa074e..23fcfb106 100644 --- a/pkg/cmd/project/link/link_test.go +++ b/pkg/cmd/project/link/link_test.go @@ -1,7 +1,11 @@ package link import ( + "net/http" + "testing" + "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/project/shared/queries" "github.com/cli/cli/v2/pkg/cmdutil" @@ -9,8 +13,6 @@ import ( "github.com/google/shlex" "github.com/stretchr/testify/require" "gopkg.in/h2non/gock.v1" - "net/http" - "testing" ) func TestNewCmdLink(t *testing.T) { @@ -277,7 +279,7 @@ func TestRunLink_Repo(t *testing.T) { httpClient: func() (*http.Client, error) { return http.DefaultClient, nil }, - config: func() (config.Config, error) { + config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, io: ios, @@ -389,7 +391,7 @@ func TestRunLink_Team(t *testing.T) { httpClient: func() (*http.Client, error) { return http.DefaultClient, nil }, - config: func() (config.Config, error) { + config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, io: ios, diff --git a/pkg/cmd/project/unlink/unlink.go b/pkg/cmd/project/unlink/unlink.go index 87a5e585b..7a75db6d1 100644 --- a/pkg/cmd/project/unlink/unlink.go +++ b/pkg/cmd/project/unlink/unlink.go @@ -2,18 +2,19 @@ package unlink import ( "fmt" + "net/http" + "strconv" + "strings" + "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/project/shared/client" "github.com/cli/cli/v2/pkg/cmd/project/shared/queries" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" - "net/http" - "strconv" - "strings" ) type unlinkOpts struct { @@ -30,7 +31,7 @@ type unlinkOpts struct { type unlinkConfig struct { httpClient func() (*http.Client, error) - config func() (config.Config, error) + config func() (gh.Config, error) client *queries.Client opts unlinkOpts io *iostreams.IOStreams diff --git a/pkg/cmd/project/unlink/unlink_test.go b/pkg/cmd/project/unlink/unlink_test.go index 7735fbe0c..0846d786a 100644 --- a/pkg/cmd/project/unlink/unlink_test.go +++ b/pkg/cmd/project/unlink/unlink_test.go @@ -1,7 +1,11 @@ package unlink import ( + "net/http" + "testing" + "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/project/shared/queries" "github.com/cli/cli/v2/pkg/cmdutil" @@ -9,8 +13,6 @@ import ( "github.com/google/shlex" "github.com/stretchr/testify/require" "gopkg.in/h2non/gock.v1" - "net/http" - "testing" ) func TestNewCmdUnlink(t *testing.T) { @@ -277,7 +279,7 @@ func TestRunUnlink_Repo(t *testing.T) { httpClient: func() (*http.Client, error) { return http.DefaultClient, nil }, - config: func() (config.Config, error) { + config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, io: ios, @@ -389,7 +391,7 @@ func TestRunUnlink_Team(t *testing.T) { httpClient: func() (*http.Client, error) { return http.DefaultClient, nil }, - config: func() (config.Config, error) { + config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, io: ios, diff --git a/pkg/cmd/release/create/create.go b/pkg/cmd/release/create/create.go index f575a339a..d702226dd 100644 --- a/pkg/cmd/release/create/create.go +++ b/pkg/cmd/release/create/create.go @@ -11,7 +11,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/release/shared" @@ -29,7 +29,7 @@ type iprompter interface { type CreateOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) GitClient *git.Client BaseRepo func() (ghrepo.Interface, error) diff --git a/pkg/cmd/release/create/create_test.go b/pkg/cmd/release/create/create_test.go index 6dccf9f20..ed7d99c1e 100644 --- a/pkg/cmd/release/create/create_test.go +++ b/pkg/cmd/release/create/create_test.go @@ -12,6 +12,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" @@ -1694,7 +1695,7 @@ func Test_createRun_interactive(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/repo/archive/archive.go b/pkg/cmd/repo/archive/archive.go index dbf2d209e..86e1a6df7 100644 --- a/pkg/cmd/repo/archive/archive.go +++ b/pkg/cmd/repo/archive/archive.go @@ -7,7 +7,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -18,7 +18,7 @@ import ( type ArchiveOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Confirmed bool IO *iostreams.IOStreams diff --git a/pkg/cmd/repo/clone/clone.go b/pkg/cmd/repo/clone/clone.go index bb586410a..28001e6fe 100644 --- a/pkg/cmd/repo/clone/clone.go +++ b/pkg/cmd/repo/clone/clone.go @@ -10,7 +10,7 @@ import ( "github.com/MakeNowJust/heredoc" "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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -21,7 +21,7 @@ import ( type CloneOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams GitArgs []string diff --git a/pkg/cmd/repo/clone/clone_test.go b/pkg/cmd/repo/clone/clone_test.go index ebdc6351a..471ed05dd 100644 --- a/pkg/cmd/repo/clone/clone_test.go +++ b/pkg/cmd/repo/clone/clone_test.go @@ -7,6 +7,7 @@ import ( "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -102,7 +103,7 @@ func runCloneCommand(httpClient *http.Client, cli string) (*test.CmdOut, error) HttpClient: func() (*http.Client, error) { return httpClient, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, GitClient: &git.Client{ diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index a55d60746..af30f4029 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -17,7 +17,7 @@ import ( "github.com/cenkalti/backoff/v4" "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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/repo/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -38,7 +38,7 @@ type iprompter interface { type CreateOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Prompter iprompter BackOff backoff.BackOff diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index 4c84138e0..e6576ebd0 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -9,6 +9,7 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -831,7 +832,7 @@ func Test_createRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/repo/fork/fork.go b/pkg/cmd/repo/fork/fork.go index fe59ab31f..a5e9066b2 100644 --- a/pkg/cmd/repo/fork/fork.go +++ b/pkg/cmd/repo/fork/fork.go @@ -14,7 +14,7 @@ import ( "github.com/cli/cli/v2/api" ghContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/repo/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -32,7 +32,7 @@ type iprompter interface { type ForkOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) Remotes func() (ghContext.Remotes, error) diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index 7f37c0ae9..b1b62e11a 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -13,6 +13,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" @@ -211,7 +212,7 @@ func TestRepoFork(t *testing.T) { httpStubs func(*httpmock.Registry) execStubs func(*run.CommandStubber) promptStubs func(*prompter.MockPrompter) - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) remotes []*context.Remote wantOut string wantErrOut string @@ -254,7 +255,7 @@ func TestRepoFork(t *testing.T) { Repo: ghrepo.New("OWNER", "REPO"), }, }, - cfgStubs: func(_ *testing.T, c config.Config) { + cfgStubs: func(_ *testing.T, c gh.Config) { c.Set("", "git_protocol", "") }, httpStubs: forkPost, @@ -735,7 +736,7 @@ func TestRepoFork(t *testing.T) { if tt.cfgStubs != nil { tt.cfgStubs(t, cfg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return cfg, nil } diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index 1ae88deae..d9342f9cb 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/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -90,7 +90,7 @@ type GardenOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) RepoArg string } diff --git a/pkg/cmd/repo/list/list.go b/pkg/cmd/repo/list/list.go index e48142723..2cee2c480 100644 --- a/pkg/cmd/repo/list/list.go +++ b/pkg/cmd/repo/list/list.go @@ -10,8 +10,8 @@ import ( "github.com/spf13/cobra" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" fd "github.com/cli/cli/v2/internal/featuredetection" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmdutil" @@ -20,7 +20,7 @@ import ( type ListOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) IO *iostreams.IOStreams Exporter cmdutil.Exporter Detector fd.Detector diff --git a/pkg/cmd/repo/list/list_test.go b/pkg/cmd/repo/list/list_test.go index 1a209e04d..bd51cadfc 100644 --- a/pkg/cmd/repo/list/list_test.go +++ b/pkg/cmd/repo/list/list_test.go @@ -15,6 +15,7 @@ import ( "github.com/cli/cli/v2/internal/config" fd "github.com/cli/cli/v2/internal/featuredetection" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -282,7 +283,7 @@ func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, err HttpClient: func() (*http.Client, error) { return &http.Client{Transport: rt}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } @@ -325,7 +326,7 @@ func TestRepoList_nontty(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: httpReg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Now: func() time.Time { @@ -366,7 +367,7 @@ func TestRepoList_tty(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: httpReg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Now: func() time.Time { @@ -436,7 +437,7 @@ func TestRepoList_noVisibilityField(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Now: func() time.Time { @@ -474,7 +475,7 @@ func TestRepoList_invalidOwner(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, Now: func() time.Time { diff --git a/pkg/cmd/repo/rename/rename.go b/pkg/cmd/repo/rename/rename.go index df56af951..7a011b4e3 100644 --- a/pkg/cmd/repo/rename/rename.go +++ b/pkg/cmd/repo/rename/rename.go @@ -9,7 +9,7 @@ import ( "github.com/cli/cli/v2/api" ghContext "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -26,7 +26,7 @@ type RenameOptions struct { GitClient *git.Client IO *iostreams.IOStreams Prompter iprompter - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Remotes func() (ghContext.Remotes, error) DoConfirm bool diff --git a/pkg/cmd/repo/rename/rename_test.go b/pkg/cmd/repo/rename/rename_test.go index 68499b2fa..da40e51b0 100644 --- a/pkg/cmd/repo/rename/rename_test.go +++ b/pkg/cmd/repo/rename/rename_test.go @@ -8,6 +8,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" @@ -230,7 +231,7 @@ func TestRenameRun(t *testing.T) { return repo, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/repo/unarchive/unarchive.go b/pkg/cmd/repo/unarchive/unarchive.go index 08108f211..74d84a779 100644 --- a/pkg/cmd/repo/unarchive/unarchive.go +++ b/pkg/cmd/repo/unarchive/unarchive.go @@ -7,7 +7,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,7 +17,7 @@ import ( type UnarchiveOptions struct { HttpClient func() (*http.Client, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Confirmed bool IO *iostreams.IOStreams diff --git a/pkg/cmd/repo/view/view.go b/pkg/cmd/repo/view/view.go index 3351d9cd9..136384152 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/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmdutil" @@ -26,7 +26,7 @@ type ViewOptions struct { BaseRepo func() (ghrepo.Interface, error) Browser browser.Browser Exporter cmdutil.Exporter - Config func() (config.Config, error) + Config func() (gh.Config, error) RepoArg string Web bool diff --git a/pkg/cmd/repo/view/view_test.go b/pkg/cmd/repo/view/view_test.go index 16b525783..a8361e9ef 100644 --- a/pkg/cmd/repo/view/view_test.go +++ b/pkg/cmd/repo/view/view_test.go @@ -10,6 +10,7 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" @@ -530,7 +531,7 @@ func Test_ViewRun_WithoutUsername(t *testing.T) { return &http.Client{Transport: reg}, nil }, IO: io, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } diff --git a/pkg/cmd/ruleset/check/check.go b/pkg/cmd/ruleset/check/check.go index 7d82990c4..b56476d84 100644 --- a/pkg/cmd/ruleset/check/check.go +++ b/pkg/cmd/ruleset/check/check.go @@ -10,7 +10,7 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/ruleset/shared" @@ -22,7 +22,7 @@ import ( type CheckOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Git *git.Client Browser browser.Browser diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 38ae1be44..6e4331864 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -15,6 +15,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/run/shared" @@ -140,7 +141,7 @@ func TestNewCmdView(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } diff --git a/pkg/cmd/search/shared/shared_test.go b/pkg/cmd/search/shared/shared_test.go index 9d977cc83..689459d39 100644 --- a/pkg/cmd/search/shared/shared_test.go +++ b/pkg/cmd/search/shared/shared_test.go @@ -7,6 +7,7 @@ import ( "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/factory" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/search" @@ -15,7 +16,7 @@ import ( func TestSearcher(t *testing.T) { f := factory.New("1") - f.Config = func() (config.Config, error) { + f.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } _, err := Searcher(f) diff --git a/pkg/cmd/secret/delete/delete.go b/pkg/cmd/secret/delete/delete.go index a86784ff2..9a299ce4f 100644 --- a/pkg/cmd/secret/delete/delete.go +++ b/pkg/cmd/secret/delete/delete.go @@ -6,7 +6,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/secret/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,7 +17,7 @@ import ( type DeleteOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) SecretName string diff --git a/pkg/cmd/secret/delete/delete_test.go b/pkg/cmd/secret/delete/delete_test.go index 8474e90c0..9d2c078c7 100644 --- a/pkg/cmd/secret/delete/delete_test.go +++ b/pkg/cmd/secret/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -162,7 +163,7 @@ func Test_removeRun_repo(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { @@ -190,7 +191,7 @@ func Test_removeRun_env(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { @@ -247,7 +248,7 @@ func Test_removeRun_org(t *testing.T) { ios, _, _, _ := iostreams.Test() - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.BaseRepo = func() (ghrepo.Interface, error) { @@ -281,7 +282,7 @@ func Test_removeRun_user(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, SecretName: "cool_secret", diff --git a/pkg/cmd/secret/list/list.go b/pkg/cmd/secret/list/list.go index 0d2e6f3f1..9e1fd305d 100644 --- a/pkg/cmd/secret/list/list.go +++ b/pkg/cmd/secret/list/list.go @@ -9,7 +9,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/cmd/secret/shared" @@ -21,7 +21,7 @@ import ( type ListOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Now func() time.Time Exporter cmdutil.Exporter @@ -138,7 +138,7 @@ func listRun(opts *ListOptions) error { case shared.Environment: secrets, err = getEnvSecrets(client, baseRepo, envName) case shared.Organization, shared.User: - var cfg config.Config + var cfg gh.Config var host string cfg, err = opts.Config() diff --git a/pkg/cmd/secret/list/list_test.go b/pkg/cmd/secret/list/list_test.go index f52e153f0..2e7b19065 100644 --- a/pkg/cmd/secret/list/list_test.go +++ b/pkg/cmd/secret/list/list_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/secret/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -418,7 +419,7 @@ func Test_listRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.Now = func() time.Time { @@ -611,7 +612,7 @@ func Test_listRun_populatesNumSelectedReposIfRequired(t *testing.T) { opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - opts.Config = func() (config.Config, error) { + opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } opts.Now = func() time.Time { diff --git a/pkg/cmd/secret/set/set.go b/pkg/cmd/secret/set/set.go index 1e66e38a9..755bdda1f 100644 --- a/pkg/cmd/secret/set/set.go +++ b/pkg/cmd/secret/set/set.go @@ -11,7 +11,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/secret/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -25,7 +25,7 @@ import ( type SetOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Prompter iprompter diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index 3b46e63f1..5c8d6f693 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -11,6 +11,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/secret/shared" @@ -265,7 +266,7 @@ func Test_setRun_repo(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -306,7 +307,7 @@ func Test_setRun_env(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -407,7 +408,7 @@ func Test_setRun_org(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.IO = ios @@ -489,7 +490,7 @@ func Test_setRun_user(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.IO = ios @@ -527,7 +528,7 @@ func Test_setRun_shouldNotStore(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { diff --git a/pkg/cmd/ssh-key/add/add.go b/pkg/cmd/ssh-key/add/add.go index 553c35985..c620d438b 100644 --- a/pkg/cmd/ssh-key/add/add.go +++ b/pkg/cmd/ssh-key/add/add.go @@ -6,7 +6,7 @@ import ( "net/http" "os" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmd/ssh-key/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -15,7 +15,7 @@ import ( type AddOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HTTPClient func() (*http.Client, error) KeyFile string diff --git a/pkg/cmd/ssh-key/add/add_test.go b/pkg/cmd/ssh-key/add/add_test.go index 43222a6c4..6d30b6d0d 100644 --- a/pkg/cmd/ssh-key/add/add_test.go +++ b/pkg/cmd/ssh-key/add/add_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" "github.com/stretchr/testify/assert" @@ -131,7 +132,7 @@ func Test_runAdd(t *testing.T) { if tt.httpStubs != nil { tt.httpStubs(reg) } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/ssh-key/delete/delete.go b/pkg/cmd/ssh-key/delete/delete.go index b6ed9f014..670b47b3e 100644 --- a/pkg/cmd/ssh-key/delete/delete.go +++ b/pkg/cmd/ssh-key/delete/delete.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -13,7 +13,7 @@ import ( type DeleteOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) KeyID string diff --git a/pkg/cmd/ssh-key/delete/delete_test.go b/pkg/cmd/ssh-key/delete/delete_test.go index 85e79de3a..be2917c82 100644 --- a/pkg/cmd/ssh-key/delete/delete_test.go +++ b/pkg/cmd/ssh-key/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -187,7 +188,7 @@ func Test_deleteRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } ios, _, stdout, _ := iostreams.Test() diff --git a/pkg/cmd/ssh-key/list/list.go b/pkg/cmd/ssh-key/list/list.go index f00075944..eebc82f90 100644 --- a/pkg/cmd/ssh-key/list/list.go +++ b/pkg/cmd/ssh-key/list/list.go @@ -9,7 +9,7 @@ import ( "time" "github.com/cli/cli/v2/api" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/cmd/ssh-key/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -19,7 +19,7 @@ import ( type ListOptions struct { IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) HTTPClient func() (*http.Client, error) } diff --git a/pkg/cmd/ssh-key/list/list_test.go b/pkg/cmd/ssh-key/list/list_test.go index ab28c34c3..77ee26600 100644 --- a/pkg/cmd/ssh-key/list/list_test.go +++ b/pkg/cmd/ssh-key/list/list_test.go @@ -8,6 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" ) @@ -233,7 +234,7 @@ func TestListRun(t *testing.T) { opts := tt.opts opts.IO = ios - opts.Config = func() (config.Config, error) { return config.NewBlankConfig(), nil } + opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } err := listRun(&opts) if (err != nil) != tt.wantErr { diff --git a/pkg/cmd/status/status_test.go b/pkg/cmd/status/status_test.go index d9fdd54bc..9be333de7 100644 --- a/pkg/cmd/status/status_test.go +++ b/pkg/cmd/status/status_test.go @@ -10,6 +10,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -59,7 +60,7 @@ func TestNewCmdStatus(t *testing.T) { f := &cmdutil.Factory{ IOStreams: ios, - Config: func() (config.Config, error) { + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, } diff --git a/pkg/cmd/variable/delete/delete.go b/pkg/cmd/variable/delete/delete.go index 1c6ab72ee..3617f3188 100644 --- a/pkg/cmd/variable/delete/delete.go +++ b/pkg/cmd/variable/delete/delete.go @@ -6,7 +6,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/variable/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -17,7 +17,7 @@ import ( type DeleteOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) VariableName string diff --git a/pkg/cmd/variable/delete/delete_test.go b/pkg/cmd/variable/delete/delete_test.go index a71e032c3..e659f96a6 100644 --- a/pkg/cmd/variable/delete/delete_test.go +++ b/pkg/cmd/variable/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -130,7 +131,7 @@ func TestRemoveRun(t *testing.T) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } diff --git a/pkg/cmd/variable/list/list.go b/pkg/cmd/variable/list/list.go index 6d82d51a2..1c29cfe2f 100644 --- a/pkg/cmd/variable/list/list.go +++ b/pkg/cmd/variable/list/list.go @@ -8,7 +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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/tableprinter" "github.com/cli/cli/v2/pkg/cmd/variable/shared" @@ -20,7 +20,7 @@ import ( type ListOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Now func() time.Time @@ -112,7 +112,7 @@ func listRun(opts *ListOptions) error { case shared.Environment: variables, err = getEnvVariables(client, baseRepo, envName) case shared.Organization: - var cfg config.Config + var cfg gh.Config var host string cfg, err = opts.Config() if err != nil { diff --git a/pkg/cmd/variable/list/list_test.go b/pkg/cmd/variable/list/list_test.go index ed0eadf38..0629bb2c7 100644 --- a/pkg/cmd/variable/list/list_test.go +++ b/pkg/cmd/variable/list/list_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/variable/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -238,7 +239,7 @@ func Test_listRun(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.Now = func() time.Time { diff --git a/pkg/cmd/variable/set/set.go b/pkg/cmd/variable/set/set.go index 95685e81b..890c1e3fa 100644 --- a/pkg/cmd/variable/set/set.go +++ b/pkg/cmd/variable/set/set.go @@ -10,7 +10,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/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/variable/shared" "github.com/cli/cli/v2/pkg/cmdutil" @@ -27,7 +27,7 @@ type iprompter interface { type SetOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams - Config func() (config.Config, error) + Config func() (gh.Config, error) BaseRepo func() (ghrepo.Interface, error) Prompter iprompter diff --git a/pkg/cmd/variable/set/set_test.go b/pkg/cmd/variable/set/set_test.go index 1395d0fce..4e77d5900 100644 --- a/pkg/cmd/variable/set/set_test.go +++ b/pkg/cmd/variable/set/set_test.go @@ -10,6 +10,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/variable/shared" @@ -210,7 +211,7 @@ func Test_setRun_repo(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -283,7 +284,7 @@ func Test_setRun_env(t *testing.T) { HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil }, - Config: func() (config.Config, error) { return config.NewBlankConfig(), nil }, + Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil }, BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.FromFullName("owner/repo") }, @@ -394,7 +395,7 @@ func Test_setRun_org(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } - tt.opts.Config = func() (config.Config, error) { + tt.opts.Config = func() (gh.Config, error) { return config.NewBlankConfig(), nil } tt.opts.IO = ios diff --git a/pkg/cmdutil/auth_check.go b/pkg/cmdutil/auth_check.go index fb269704f..d8a43176a 100644 --- a/pkg/cmdutil/auth_check.go +++ b/pkg/cmdutil/auth_check.go @@ -3,7 +3,7 @@ package cmdutil import ( "reflect" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -26,7 +26,7 @@ func DisableAuthCheckFlag(flag *pflag.Flag) { flag.Annotations[skipAuthCheckAnnotation] = []string{"true"} } -func CheckAuth(cfg config.Config) bool { +func CheckAuth(cfg gh.Config) bool { if cfg.Authentication().HasEnvToken() { return true } diff --git a/pkg/cmdutil/auth_check_test.go b/pkg/cmdutil/auth_check_test.go index 02d1fd775..05eb0254a 100644 --- a/pkg/cmdutil/auth_check_test.go +++ b/pkg/cmdutil/auth_check_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/spf13/cobra" "github.com/stretchr/testify/require" ) @@ -12,7 +13,7 @@ func Test_CheckAuth(t *testing.T) { tests := []struct { name string env map[string]string - cfgStubs func(*testing.T, config.Config) + cfgStubs func(*testing.T, gh.Config) expected bool }{ { @@ -26,7 +27,7 @@ func Test_CheckAuth(t *testing.T) { }, { name: "known host", - cfgStubs: func(t *testing.T, c config.Config) { + cfgStubs: func(t *testing.T, c gh.Config) { _, err := c.Authentication().Login("github.com", "test-user", "test-token", "https", false) require.NoError(t, err) }, diff --git a/pkg/cmdutil/factory.go b/pkg/cmdutil/factory.go index b48dceed3..07ffbee64 100644 --- a/pkg/cmdutil/factory.go +++ b/pkg/cmdutil/factory.go @@ -9,7 +9,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/browser" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/extensions" @@ -28,7 +28,7 @@ type Factory struct { BaseRepo func() (ghrepo.Interface, error) Branch func() (string, error) - Config func() (config.Config, error) + Config func() (gh.Config, error) HttpClient func() (*http.Client, error) Remotes func() (context.Remotes, error) } diff --git a/pkg/cmdutil/legacy.go b/pkg/cmdutil/legacy.go index 1f247d4e6..0cc9674e1 100644 --- a/pkg/cmdutil/legacy.go +++ b/pkg/cmdutil/legacy.go @@ -4,12 +4,12 @@ import ( "fmt" "os" - "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/gh" ) // TODO: consider passing via Factory // TODO: support per-hostname settings -func DetermineEditor(cf func() (config.Config, error)) (string, error) { +func DetermineEditor(cf func() (gh.Config, error)) (string, error) { editorCommand := os.Getenv("GH_EDITOR") if editorCommand == "" { cfg, err := cf()