From 24336f1344f57af4f6c41c4d50481a11ec742239 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Mon, 16 Sep 2024 13:42:51 -0400 Subject: [PATCH 01/22] Enhance gh repo create docs, fix random cmd link Relates #8946 - updates the documentation within `gh repo create` to include links to lookup .gitignore templates and licenses - fixes link markup within `gh auth setup-git` so link is formatted correctly on https://cli.github.com --- pkg/cmd/auth/setupgit/setupgit.go | 2 +- pkg/cmd/repo/create/create.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/auth/setupgit/setupgit.go b/pkg/cmd/auth/setupgit/setupgit.go index c1200b475..0ff7b6903 100644 --- a/pkg/cmd/auth/setupgit/setupgit.go +++ b/pkg/cmd/auth/setupgit/setupgit.go @@ -36,7 +36,7 @@ func NewCmdSetupGit(f *cmdutil.Factory, runF func(*SetupGitOptions) error) *cobr Long: heredoc.Docf(` This command configures %[1]sgit%[1]s to use GitHub CLI as a credential helper. For more information on git credential helpers please reference: - https://git-scm.com/docs/gitcredentials. + . By default, GitHub CLI will be set as the credential helper for all authenticated hosts. If there is no authenticated hosts the command fails with an error. diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 8b5dd515a..28ca0d1e8 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -93,7 +93,12 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co To create a remote repository from an existing local repository, specify the source directory with %[1]s--source%[1]s. By default, the remote repository name will be the name of the source directory. + Pass %[1]s--push%[1]s to push any local commits to the new repository. + + For language or platform .gitignore templates to use with %[1]s--gitignore%[1]s, . + + For license keywords to use with %[1]s--license%[1]s, . `, "`"), Example: heredoc.Doc(` # create a repository interactively From 8e8fc696f13ce3396eabb92471bc4ae71a86274e Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Thu, 12 Sep 2024 09:20:02 -0700 Subject: [PATCH 02/22] disable auth check for att trusted-root cmd Signed-off-by: Brian DeHamer --- pkg/cmd/attestation/trustedroot/trustedroot.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/cmd/attestation/trustedroot/trustedroot.go b/pkg/cmd/attestation/trustedroot/trustedroot.go index c9c3fdb04..a79c32ddb 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot.go @@ -94,6 +94,7 @@ func NewTrustedRootCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Com }, } + cmdutil.DisableAuthCheck(&trustedRootCmd) trustedRootCmd.Flags().StringVarP(&opts.TufUrl, "tuf-url", "", "", "URL to the TUF repository mirror") trustedRootCmd.Flags().StringVarP(&opts.TufRootPath, "tuf-root", "", "", "Path to the TUF root.json file on disk") trustedRootCmd.MarkFlagsRequiredTogether("tuf-url", "tuf-root") From cbe85253214d1ff3ce3c4fe707d55e99fe2adfaf Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Fri, 13 Sep 2024 15:26:14 -0700 Subject: [PATCH 03/22] enforce auth for tenancy Signed-off-by: Brian DeHamer --- .../attestation/trustedroot/trustedroot.go | 9 ++ .../trustedroot/trustedroot_test.go | 97 +++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/pkg/cmd/attestation/trustedroot/trustedroot.go b/pkg/cmd/attestation/trustedroot/trustedroot.go index a79c32ddb..7dba916eb 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot.go @@ -69,6 +69,15 @@ func NewTrustedRootCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Com } if ghinstance.IsTenancy(opts.Hostname) { + c, err := f.Config() + if err != nil { + return err + } + + if token, _ := c.Authentication().ActiveToken(opts.Hostname); token == "" { + return fmt.Errorf("not authenticated with %s", opts.Hostname) + } + hc, err := f.HttpClient() if err != nil { return err diff --git a/pkg/cmd/attestation/trustedroot/trustedroot_test.go b/pkg/cmd/attestation/trustedroot/trustedroot_test.go index 70b5ae2a1..b7d5f6c2f 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot_test.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot_test.go @@ -3,6 +3,7 @@ package trustedroot import ( "bytes" "fmt" + "net/http" "strings" "testing" @@ -10,8 +11,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "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/cmd/attestation/api" "github.com/cli/cli/v2/pkg/cmd/attestation/test" "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" ) @@ -19,6 +25,9 @@ func TestNewTrustedRootCmd(t *testing.T) { testIO, _, _, _ := iostreams.Test() f := &cmdutil.Factory{ IOStreams: testIO, + Config: func() (gh.Config, error) { + return &ghmock.ConfigMock{}, nil + }, } testcases := []struct { @@ -72,6 +81,83 @@ func TestNewTrustedRootCmd(t *testing.T) { } } +func TestNewTrustedRootWithTenancy(t *testing.T) { + testIO, _, _, _ := iostreams.Test() + var testReg httpmock.Registry + var metaResp = api.MetaResponse{ + Domains: api.Domain{ + ArtifactAttestations: api.ArtifactAttestations{ + TrustDomain: "foo", + }, + }, + } + testReg.Register(httpmock.REST(http.MethodGet, "meta"), + httpmock.StatusJSONResponse(200, &metaResp)) + + httpClientFunc := func() (*http.Client, error) { + reg := &testReg + client := &http.Client{} + httpmock.ReplaceTripper(client, reg) + return client, nil + } + + cli := "--hostname foo-bar.ghe.com" + + t.Run("Host with NO auth configured", func(t *testing.T) { + f := &cmdutil.Factory{ + IOStreams: testIO, + Config: func() (gh.Config, error) { + return &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { + return &MockAuthConfig{Token: ""} + }, + }, nil + }, + } + + cmd := NewTrustedRootCmd(f, func(_ *Options) error { + return nil + }) + + argv := strings.Split(cli, " ") + cmd.SetArgs(argv) + cmd.SetIn(&bytes.Buffer{}) + cmd.SetOut(&bytes.Buffer{}) + cmd.SetErr(&bytes.Buffer{}) + _, err := cmd.ExecuteC() + + assert.Error(t, err) + assert.ErrorContains(t, err, "not authenticated") + }) + + t.Run("Host wth auth configured", func(t *testing.T) { + f := &cmdutil.Factory{ + IOStreams: testIO, + Config: func() (gh.Config, error) { + return &ghmock.ConfigMock{ + AuthenticationFunc: func() gh.AuthConfig { + return &MockAuthConfig{Token: "TOKEN"} + }, + }, nil + }, + HttpClient: httpClientFunc, + } + + cmd := NewTrustedRootCmd(f, func(_ *Options) error { + return nil + }) + + argv := strings.Split(cli, " ") + cmd.SetArgs(argv) + cmd.SetIn(&bytes.Buffer{}) + cmd.SetOut(&bytes.Buffer{}) + cmd.SetErr(&bytes.Buffer{}) + + _, err := cmd.ExecuteC() + assert.NoError(t, err) + }) +} + var newTUFErrClient tufClientInstantiator = func(o *tuf.Options) (*tuf.Client, error) { return nil, fmt.Errorf("failed to create TUF client") } @@ -99,3 +185,14 @@ func TestGetTrustedRoot(t *testing.T) { }) } + +type MockAuthConfig struct { + config.AuthConfig + Token string +} + +var _ gh.AuthConfig = (*MockAuthConfig)(nil) + +func (c *MockAuthConfig) ActiveToken(host string) (string, string) { + return c.Token, "" +} From 3bcedfe7f071904af24b0d9096980e53844ca42a Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Tue, 17 Sep 2024 14:18:00 -0700 Subject: [PATCH 04/22] Update pkg/cmd/attestation/trustedroot/trustedroot_test.go Co-authored-by: Fredrik Skogman --- pkg/cmd/attestation/trustedroot/trustedroot_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/attestation/trustedroot/trustedroot_test.go b/pkg/cmd/attestation/trustedroot/trustedroot_test.go index b7d5f6c2f..c3c1818dd 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot_test.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot_test.go @@ -130,7 +130,7 @@ func TestNewTrustedRootWithTenancy(t *testing.T) { assert.ErrorContains(t, err, "not authenticated") }) - t.Run("Host wth auth configured", func(t *testing.T) { + t.Run("Host with auth configured", func(t *testing.T) { f := &cmdutil.Factory{ IOStreams: testIO, Config: func() (gh.Config, error) { From dded0391254781d1222b1050885a5c658b4461b0 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Thu, 12 Sep 2024 10:48:12 +0100 Subject: [PATCH 05/22] Improve the suggested command for creating an issue when an extension doesn't have a binary for your platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When installing an extension, the CLI must to select the correct binary to download for the machine (see the [`installBin` function](https://github.com/cli/cli/blob/78c1d00eccac1b2ae82ac0bfeea3e2292c98056a/pkg/cmd/extension/manager.go#L240)). By default, the CLI will download a binary matching the current machine's architecture. If a suitable binary isn't available, the CLI [outputs an error](https://github.com/cli/cli/blob/78c1d00eccac1b2ae82ac0bfeea3e2292c98056a/pkg/cmd/extension/manager.go#L278), directing the user to create an issue on the extension's repository: ```go if asset == nil { return fmt.Errorf( "%[1]s unsupported for %[2]s. Open an issue: `gh issue create -R %[3]s/%[1]s -t'Support %[2]s'`", repo.RepoName(), platform, repo.RepoOwner()) } ``` The issue this creates isn't very clear or helpful. It isn't obvious where it is coming from, or what you need to do. This improves the suggested command, adding a better title to the issue and an explanatory body. To test this, try installing my `timrogers/gh-extension-without-binary` extension, which only has an esoteric `linux-ppc64` binary 😸: ```bash gh extension install timrogers/gh-extension-without-binary ``` You'll get a nice output like this: ``` gh-extension-without-binary unsupported for darwin-arm64. Open an issue: `gh issue create -R timrogers/gh-extension-without-binary --title "Add support for the darwin-arm64 architecture" --body "This extension does not support the darwin-arm64 architecture. I tried to install it on a darwin-arm64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see ."` ``` ...which produces an issue like https://github.com/timrogers/gh-extension-without-binary/issues/4. I have tested the resulting command on macOS and Windows, so I am confident that it has *at least reasonable* cross-platform support. Fixes https://github.com/cli/cli/issues/9600. --- pkg/cmd/extension/manager.go | 15 +++++++++++++-- pkg/cmd/extension/manager_test.go | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 45186d689..37140ee0f 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -280,9 +280,11 @@ func (m *Manager) installBin(repo ghrepo.Interface, target string) error { } if asset == nil { + issueCreateCommand := generateMissingBinaryIssueCreateCommand(repo.RepoOwner(), repo.RepoName(), platform) + return fmt.Errorf( - "%[1]s unsupported for %[2]s. Open an issue: `gh issue create -R %[3]s/%[1]s -t'Support %[2]s'`", - repo.RepoName(), platform, repo.RepoOwner()) + "%[1]s unsupported for %[2]s. Open an issue: `%[3]s`", + repo.RepoName(), platform, issueCreateCommand) } name := repo.RepoName() @@ -334,6 +336,15 @@ func (m *Manager) installBin(repo ghrepo.Interface, target string) error { return nil } +func generateMissingBinaryIssueCreateCommand(repoOwner string, repoName string, currentPlatform string) string { + issueBody := generateMissingBinaryIssueBody(currentPlatform) + return fmt.Sprintf("gh issue create -R %[1]s/%[2]s --title \"Add support for the %[3]s architecture\" --body \"%[4]s\"", repoOwner, repoName, currentPlatform, issueBody) +} + +func generateMissingBinaryIssueBody(currentPlatform string) string { + return fmt.Sprintf("This extension does not support the %[1]s architecture. I tried to install it on a %[1]s machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .", currentPlatform) +} + func writeManifest(dir, name string, data []byte) (writeErr error) { path := filepath.Join(dir, name) var f *os.File diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index 5de4e15cb..78fd40978 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -906,7 +906,7 @@ func TestManager_Install_binary_unsupported(t *testing.T) { m := newTestManager(tempDir, &client, nil, ios) err := m.Install(repo, "") - assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64. Open an issue: `gh issue create -R owner/gh-bin-ext -t'Support windows-amd64'`") + assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64. Open an issue: `gh issue create -R owner/gh-bin-ext --title \"Add support for the windows-amd64 architecture\" --body \"This extension does not support the windows-amd64 architecture. I tried to install it on a windows-amd64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .\"`") assert.Equal(t, "", stdout.String()) assert.Equal(t, "", stderr.String()) From 81d57a0643ff5856a96c0c5735184a571985f3df Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Thu, 12 Sep 2024 23:18:37 +0100 Subject: [PATCH 06/22] Improve error presentation --- pkg/cmd/extension/manager.go | 6 ++++-- pkg/cmd/extension/manager_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 37140ee0f..6bed532d3 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -280,11 +280,13 @@ func (m *Manager) installBin(repo ghrepo.Interface, target string) error { } if asset == nil { + cs := m.io.ColorScheme() + errorMessageInRed := fmt.Sprintf(cs.Red("%[1]s unsupported for %[2]s."), repo.RepoName(), platform) issueCreateCommand := generateMissingBinaryIssueCreateCommand(repo.RepoOwner(), repo.RepoName(), platform) return fmt.Errorf( - "%[1]s unsupported for %[2]s. Open an issue: `%[3]s`", - repo.RepoName(), platform, issueCreateCommand) + "%[1]s\n\nOpen an issue on the extension's repo by running the following command:\n\n `%[2]s`", + errorMessageInRed, issueCreateCommand) } name := repo.RepoName() diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index 78fd40978..ae3a9a469 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -906,7 +906,7 @@ func TestManager_Install_binary_unsupported(t *testing.T) { m := newTestManager(tempDir, &client, nil, ios) err := m.Install(repo, "") - assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64. Open an issue: `gh issue create -R owner/gh-bin-ext --title \"Add support for the windows-amd64 architecture\" --body \"This extension does not support the windows-amd64 architecture. I tried to install it on a windows-amd64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .\"`") + assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64.\n\nOpen an issue on the extension's repo by running the following command:\n\n\t`gh issue create -R owner/gh-bin-ext --title \"Add support for the windows-amd64 architecture\" --body \"This extension does not support the windows-amd64 architecture. I tried to install it on a windows-amd64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .\"") assert.Equal(t, "", stdout.String()) assert.Equal(t, "", stderr.String()) From e7403b89d0c0be36dacae29f61cb040525ba7246 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Wed, 18 Sep 2024 08:42:19 -0600 Subject: [PATCH 07/22] Add HasActiveToken to AuthConfig. Co-authored-by: William Martin --- internal/config/auth_config_test.go | 26 +++++++++++++++++++++++++- internal/config/config.go | 7 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/internal/config/auth_config_test.go b/internal/config/auth_config_test.go index ed000ff18..61245c650 100644 --- a/internal/config/auth_config_test.go +++ b/internal/config/auth_config_test.go @@ -52,8 +52,32 @@ func TestTokenFromKeyringForUserErrorsIfUsernameIsBlank(t *testing.T) { require.ErrorContains(t, err, "username cannot be blank") } +func TestHasActiveToken(t *testing.T) { + // Given the user has logged in for a host + authCfg := newTestAuthConfig(t) + _, err := authCfg.Login("github.com", "test-user", "test-token", "", false) + require.NoError(t, err) + + // When we check if that host has an active token + hasActiveToken := authCfg.HasActiveToken("github.com") + + // Then there is an active token + require.True(t, hasActiveToken, "expected there to be an active token") +} + +func TestHasNoActiveToken(t *testing.T) { + // Given there are no users logged in for a host + authCfg := newTestAuthConfig(t) + + // When we check if any host has an active token + hasActiveToken := authCfg.HasActiveToken("github.com") + + // Then there is no active token + require.False(t, hasActiveToken, "expected there to be no active token") +} + func TestTokenStoredInConfig(t *testing.T) { - // When the user has logged in insecurely + // Given the user has logged in insecurely authCfg := newTestAuthConfig(t) _, err := authCfg.Login("github.com", "test-user", "test-token", "", false) require.NoError(t, err) diff --git a/internal/config/config.go b/internal/config/config.go index 29b66b73b..f7c949a46 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -217,6 +217,13 @@ func (c *AuthConfig) ActiveToken(hostname string) (string, string) { return token, source } +// HasActiveToken returns true when a token for the hostname is +// present. +func (c *AuthConfig) HasActiveToken(hostname string) bool { + token, _ := c.ActiveToken(hostname) + return token != "" +} + // HasEnvToken returns true when a token has been specified in an // environment variable, else returns false. func (c *AuthConfig) HasEnvToken() bool { From 88d48f23654838ea7428ed47ed28f64f65405f6a Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:32:58 -0600 Subject: [PATCH 08/22] Add HasActiveToken method to AuthConfig interface --- internal/gh/gh.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/gh/gh.go b/internal/gh/gh.go index c39734075..e4431fdab 100644 --- a/internal/gh/gh.go +++ b/internal/gh/gh.go @@ -93,6 +93,9 @@ type Migration interface { // with knowledge on how to access encrypted storage when neccesarry. // Behavior is scoped to authentication specific tasks. type AuthConfig interface { + // HasActiveToken returns true when a token for the hostname is present. + HasActiveToken(hostname string) bool + // 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) From d8e77d256fe83791cf675e0ff539e1390ffd98d5 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:35:11 -0600 Subject: [PATCH 09/22] Use new HasActiveToken method in trustedroot.go --- pkg/cmd/attestation/trustedroot/trustedroot.go | 2 +- .../attestation/trustedroot/trustedroot_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/attestation/trustedroot/trustedroot.go b/pkg/cmd/attestation/trustedroot/trustedroot.go index 7dba916eb..6f741dcd4 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot.go @@ -74,7 +74,7 @@ func NewTrustedRootCmd(f *cmdutil.Factory, runF func(*Options) error) *cobra.Com return err } - if token, _ := c.Authentication().ActiveToken(opts.Hostname); token == "" { + if !c.Authentication().HasActiveToken(opts.Hostname) { return fmt.Errorf("not authenticated with %s", opts.Hostname) } diff --git a/pkg/cmd/attestation/trustedroot/trustedroot_test.go b/pkg/cmd/attestation/trustedroot/trustedroot_test.go index c3c1818dd..c4a259436 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot_test.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot_test.go @@ -109,7 +109,7 @@ func TestNewTrustedRootWithTenancy(t *testing.T) { Config: func() (gh.Config, error) { return &ghmock.ConfigMock{ AuthenticationFunc: func() gh.AuthConfig { - return &MockAuthConfig{Token: ""} + return &stubAuthConfig{hasActiveToken: false} }, }, nil }, @@ -136,7 +136,7 @@ func TestNewTrustedRootWithTenancy(t *testing.T) { Config: func() (gh.Config, error) { return &ghmock.ConfigMock{ AuthenticationFunc: func() gh.AuthConfig { - return &MockAuthConfig{Token: "TOKEN"} + return &stubAuthConfig{hasActiveToken: true} }, }, nil }, @@ -186,13 +186,13 @@ func TestGetTrustedRoot(t *testing.T) { } -type MockAuthConfig struct { +type stubAuthConfig struct { config.AuthConfig - Token string + hasActiveToken bool } -var _ gh.AuthConfig = (*MockAuthConfig)(nil) +var _ gh.AuthConfig = (*stubAuthConfig)(nil) -func (c *MockAuthConfig) ActiveToken(host string) (string, string) { - return c.Token, "" +func (c *stubAuthConfig) HasActiveToken(host string) bool { + return c.hasActiveToken } From d24dfbeacfdc87ea108835ee79e9f766fd75f639 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:35:35 -0600 Subject: [PATCH 10/22] Update comment formatting --- internal/config/config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index f7c949a46..1b56d30b2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -217,8 +217,7 @@ func (c *AuthConfig) ActiveToken(hostname string) (string, string) { return token, source } -// HasActiveToken returns true when a token for the hostname is -// present. +// HasActiveToken returns true when a token for the hostname is present. func (c *AuthConfig) HasActiveToken(hostname string) bool { token, _ := c.ActiveToken(hostname) return token != "" From 195188cee8751247d94c0196ac5ab20371210591 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 18 Sep 2024 18:55:20 +0100 Subject: [PATCH 11/22] Update pkg/cmd/extension/manager.go Co-authored-by: Tyler McGoffin --- pkg/cmd/extension/manager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 6bed532d3..410d4c224 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -285,8 +285,8 @@ func (m *Manager) installBin(repo ghrepo.Interface, target string) error { issueCreateCommand := generateMissingBinaryIssueCreateCommand(repo.RepoOwner(), repo.RepoName(), platform) return fmt.Errorf( - "%[1]s\n\nOpen an issue on the extension's repo by running the following command:\n\n `%[2]s`", - errorMessageInRed, issueCreateCommand) + "%[1]s\n\nTo request support for %[2]s, open an issue on the extension's repo by running the following command:\n\n `%[3]s`", + errorMessageInRed, platform, issueCreateCommand) } name := repo.RepoName() From 665e41566fe0856fd8d4c2991f81535b50b7da61 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 18 Sep 2024 19:07:32 +0100 Subject: [PATCH 12/22] Fix test --- pkg/cmd/extension/manager_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index ae3a9a469..0ad8e991e 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -906,7 +906,7 @@ func TestManager_Install_binary_unsupported(t *testing.T) { m := newTestManager(tempDir, &client, nil, ios) err := m.Install(repo, "") - assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64.\n\nOpen an issue on the extension's repo by running the following command:\n\n\t`gh issue create -R owner/gh-bin-ext --title \"Add support for the windows-amd64 architecture\" --body \"This extension does not support the windows-amd64 architecture. I tried to install it on a windows-amd64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .\"") + assert.EqualError(t, err, "gh-bin-ext unsupported for windows-amd64.\n\nTo request support for windows-amd64, open an issue on the extension's repo by running the following command:\n\n\t`gh issue create -R owner/gh-bin-ext --title \"Add support for the windows-amd64 architecture\" --body \"This extension does not support the windows-amd64 architecture. I tried to install it on a windows-amd64 machine, and it failed due to the lack of an available binary. Would you be able to update the extension's build and release process to include the relevant binary? For more details, see .\"`") assert.Equal(t, "", stdout.String()) assert.Equal(t, "", stderr.String()) From 8123de9722c698c2ebbb21bdd32516ca7bcad1bf Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Wed, 18 Sep 2024 14:05:04 -0700 Subject: [PATCH 13/22] fix tenant-awareness for trusted-root command Signed-off-by: Brian DeHamer --- pkg/cmd/attestation/trustedroot/trustedroot.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/attestation/trustedroot/trustedroot.go b/pkg/cmd/attestation/trustedroot/trustedroot.go index c9c3fdb04..c52bdac15 100644 --- a/pkg/cmd/attestation/trustedroot/trustedroot.go +++ b/pkg/cmd/attestation/trustedroot/trustedroot.go @@ -116,6 +116,12 @@ func getTrustedRoot(makeTUF tufClientInstantiator, opts *Options) error { // Disable local caching, so we get up-to-date response from TUF repository tufOpt.CacheValidity = 0 + // Target will be either the default trusted root, or the trust domain-qualified one + ghTR := defaultTR + if opts.TrustDomain != "" { + ghTR = fmt.Sprintf("%s.%s", opts.TrustDomain, defaultTR) + } + if opts.TufUrl != "" && opts.TufRootPath != "" { tufRoot, err := os.ReadFile(opts.TufRootPath) if err != nil { @@ -126,7 +132,7 @@ func getTrustedRoot(makeTUF tufClientInstantiator, opts *Options) error { tufOpt.RepositoryBaseURL = opts.TufUrl tufOptions = append(tufOptions, tufConfig{ tufOptions: tufOpt, - targets: []string{defaultTR}, + targets: []string{ghTR}, }) } else { // Get from both Sigstore public good and GitHub private instance @@ -137,14 +143,9 @@ func getTrustedRoot(makeTUF tufClientInstantiator, opts *Options) error { tufOpt = verification.GitHubTUFOptions() tufOpt.CacheValidity = 0 - targets := []string{defaultTR} - if opts.TrustDomain != "" { - targets = append(targets, fmt.Sprintf("%s.%s", - opts.TrustDomain, defaultTR)) - } tufOptions = append(tufOptions, tufConfig{ tufOptions: tufOpt, - targets: targets, + targets: []string{ghTR}, }) } From 5dd52463071d0eb053d675796eca1ff47bb20550 Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Thu, 19 Sep 2024 14:52:16 -0700 Subject: [PATCH 14/22] Replace "GitHub Enterprise Server" with "other" in `gh auth login` prompt This change is meant to better support the login flow for other customers besides GitHub Enterprise Server customers that use the same login flow as GHES. --- pkg/cmd/auth/login/login.go | 2 +- pkg/cmd/auth/login/login_test.go | 52 ++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 9e27f28ac..2eded806e 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -222,7 +222,7 @@ func loginRun(opts *LoginOptions) error { } func promptForHostname(opts *LoginOptions) (string, error) { - options := []string{"GitHub.com", "GitHub Enterprise Server"} + options := []string{"GitHub.com", "other"} hostType, err := opts.Prompter.Select( "What account do you want to log into?", options[0], diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index d53dd3f0b..555606d56 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -2,6 +2,7 @@ package login import ( "bytes" + "fmt" "net/http" "regexp" "runtime" @@ -546,7 +547,7 @@ func Test_loginRun_Survey(t *testing.T) { wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://rebecca.chambers/settings/tokens"), }, { - name: "choose enterprise", + name: "choose other", wantHosts: heredoc.Doc(` brad.vickers: users: @@ -564,7 +565,7 @@ func Test_loginRun_Survey(t *testing.T) { pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What account do you want to log into?": - return prompter.IndexFor(opts, "GitHub Enterprise Server") + return prompter.IndexFor(opts, "other") case "What is your preferred protocol for Git operations on this host?": return prompter.IndexFor(opts, "HTTPS") case "How would you like to authenticate GitHub CLI?": @@ -803,3 +804,50 @@ func Test_loginRun_Survey(t *testing.T) { }) } } + +func Test_promptForHostname(t *testing.T) { + tests := []struct { + name string + options []string + selectedIndex int + // This is so we can test that the options in the function don't change + expectedSelection string + inputHostname string + expect string + }{ + { + name: "select GitHub.com", + selectedIndex: 0, + expectedSelection: "GitHub.com", + expect: "github.com", + }, + { + name: "select other", + selectedIndex: 1, + expectedSelection: "other", + inputHostname: "github.enterprise.com", + expect: "github.enterprise.com", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + promptMock := &prompter.PrompterMock{ + SelectFunc: func(_ string, _ string, options []string) (int, error) { + if options[tt.selectedIndex] != tt.expectedSelection { + return 0, fmt.Errorf("expected %s at index %d, but got %s", tt.expectedSelection, tt.selectedIndex, options[tt.selectedIndex]) + } + return tt.selectedIndex, nil + }, + InputHostnameFunc: func() (string, error) { + return tt.inputHostname, nil + }, + } + opts := &LoginOptions{ + Prompter: promptMock, + } + hostname, err := promptForHostname(opts) + require.NoError(t, err) + require.Equal(t, tt.expect, hostname) + }) + } +} From 46790977bb69023ae51a47469b39f6855d9c90af Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Thu, 19 Sep 2024 15:11:02 -0700 Subject: [PATCH 15/22] Add documentation explaining how to use `hostname` for `gh auth login` --- pkg/cmd/auth/login/login.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 2eded806e..613555dd7 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -59,6 +59,10 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm Long: heredoc.Docf(` Authenticate with a GitHub host. + Your %[1]shostname%[1]s is the domain where the GitHub instance you are logging into is hosted. + For example, "github.com" is the default hostname for GitHub.com. To authenticate with + a different hostname like github.enterprise.com, use that hostname instead. + The default authentication mode is a web-based browser flow. After completion, an authentication token will be stored securely in the system credential store. If a credential store is not found or there is an issue using it gh will fallback From 1ef71409f3605709e01beab4e7a227a9bc44272f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:11:28 +0000 Subject: [PATCH 16/22] build(deps): bump github.com/henvic/httpretty from 0.1.3 to 0.1.4 Bumps [github.com/henvic/httpretty](https://github.com/henvic/httpretty) from 0.1.3 to 0.1.4. - [Commits](https://github.com/henvic/httpretty/compare/v0.1.3...v0.1.4) --- updated-dependencies: - dependency-name: github.com/henvic/httpretty dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 54d02ec8e..9bf6be8e4 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-version v1.3.0 - github.com/henvic/httpretty v0.1.3 + github.com/henvic/httpretty v0.1.4 github.com/in-toto/attestation v1.1.0 github.com/joho/godotenv v1.5.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 diff --git a/go.sum b/go.sum index 416f2ee59..cdde6c210 100644 --- a/go.sum +++ b/go.sum @@ -251,8 +251,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/vault/api v1.12.2 h1:7YkCTE5Ni90TcmYHDBExdt4WGJxhpzaHqR6uGbQb/rE= github.com/hashicorp/vault/api v1.12.2/go.mod h1:LSGf1NGT1BnvFFnKVtnvcaLBM2Lz+gJdpL6HUYed8KE= -github.com/henvic/httpretty v0.1.3 h1:4A6vigjz6Q/+yAfTD4wqipCv+Px69C7Th/NhT0ApuU8= -github.com/henvic/httpretty v0.1.3/go.mod h1:UUEv7c2kHZ5SPQ51uS3wBpzPDibg2U3Y+IaXyHy5GBg= +github.com/henvic/httpretty v0.1.4 h1:Jo7uwIRWVFxkqOnErcoYfH90o3ddQyVrSANeS4cxYmU= +github.com/henvic/httpretty v0.1.4/go.mod h1:Dn60sQTZfbt2dYsdUSNsCljyF4AfdqnuJFDLJA1I4AM= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= From bc587f6576dc7a939545e791ee69ef969bcf5815 Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Fri, 20 Sep 2024 13:55:20 -0700 Subject: [PATCH 17/22] Sentence case 'Other' option in hostname prompt --- pkg/cmd/auth/login/login.go | 2 +- pkg/cmd/auth/login/login_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 613555dd7..9066abd5d 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -226,7 +226,7 @@ func loginRun(opts *LoginOptions) error { } func promptForHostname(opts *LoginOptions) (string, error) { - options := []string{"GitHub.com", "other"} + options := []string{"GitHub.com", "Other"} hostType, err := opts.Prompter.Select( "What account do you want to log into?", options[0], diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 555606d56..1cd955b1f 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -547,7 +547,7 @@ func Test_loginRun_Survey(t *testing.T) { wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://rebecca.chambers/settings/tokens"), }, { - name: "choose other", + name: "choose Other", wantHosts: heredoc.Doc(` brad.vickers: users: @@ -565,7 +565,7 @@ func Test_loginRun_Survey(t *testing.T) { pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What account do you want to log into?": - return prompter.IndexFor(opts, "other") + return prompter.IndexFor(opts, "Other") case "What is your preferred protocol for Git operations on this host?": return prompter.IndexFor(opts, "HTTPS") case "How would you like to authenticate GitHub CLI?": @@ -816,15 +816,15 @@ func Test_promptForHostname(t *testing.T) { expect string }{ { - name: "select GitHub.com", + name: "select 'GitHub.com'", selectedIndex: 0, expectedSelection: "GitHub.com", expect: "github.com", }, { - name: "select other", + name: "select 'Other'", selectedIndex: 1, - expectedSelection: "other", + expectedSelection: "Other", inputHostname: "github.enterprise.com", expect: "github.enterprise.com", }, From 13e916bcfb22366d2d5db10b486ae066ce54b494 Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Fri, 20 Sep 2024 14:10:05 -0700 Subject: [PATCH 18/22] Change prompts for `gh auth login` to reflect change from GHE to Other --- internal/prompter/prompter.go | 2 +- pkg/cmd/auth/login/login.go | 2 +- pkg/cmd/auth/login/login_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/prompter/prompter.go b/internal/prompter/prompter.go index 44579b189..1d4b11cbc 100644 --- a/internal/prompter/prompter.go +++ b/internal/prompter/prompter.go @@ -92,7 +92,7 @@ func (p *surveyPrompter) InputHostname() (string, error) { var result string err := p.ask( &survey.Input{ - Message: "GHE hostname:", + Message: "Hostname:", }, &result, survey.WithValidator(func(v interface{}) error { return ghinstance.HostnameValidator(v.(string)) })) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 9066abd5d..4d4db3259 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -228,7 +228,7 @@ func loginRun(opts *LoginOptions) error { func promptForHostname(opts *LoginOptions) (string, error) { options := []string{"GitHub.com", "Other"} hostType, err := opts.Prompter.Select( - "What account do you want to log into?", + "Where do you use GitHub?", options[0], options) if err != nil { diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 1cd955b1f..3264ed91c 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -564,7 +564,7 @@ func Test_loginRun_Survey(t *testing.T) { prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { - case "What account do you want to log into?": + case "Where do you use GitHub?": return prompter.IndexFor(opts, "Other") case "What is your preferred protocol for Git operations on this host?": return prompter.IndexFor(opts, "HTTPS") @@ -607,7 +607,7 @@ func Test_loginRun_Survey(t *testing.T) { prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { - case "What account do you want to log into?": + case "Where do you use GitHub?": return prompter.IndexFor(opts, "GitHub.com") case "What is your preferred protocol for Git operations on this host?": return prompter.IndexFor(opts, "HTTPS") @@ -641,7 +641,7 @@ func Test_loginRun_Survey(t *testing.T) { prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { - case "What account do you want to log into?": + case "Where do you use GitHub?": return prompter.IndexFor(opts, "GitHub.com") case "What is your preferred protocol for Git operations on this host?": return prompter.IndexFor(opts, "SSH") From 2059c630a27443df0d4c2185b26e22c592aaf3ef Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Fri, 20 Sep 2024 14:12:13 -0700 Subject: [PATCH 19/22] Update language on docstring for `gh auth login` --- pkg/cmd/auth/login/login.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 4d4db3259..a5e601960 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -59,8 +59,8 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm Long: heredoc.Docf(` Authenticate with a GitHub host. - Your %[1]shostname%[1]s is the domain where the GitHub instance you are logging into is hosted. - For example, "github.com" is the default hostname for GitHub.com. To authenticate with + The %[1]shostname%[1]s is the domain where the GitHub instance you are logging into is hosted. + For example, "github.com" is the hostname for GitHub.com. To authenticate with a different hostname like github.enterprise.com, use that hostname instead. The default authentication mode is a web-based browser flow. After completion, an From ccb830ca3674dc480cae08f026f3e298662e35e1 Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Fri, 20 Sep 2024 15:51:07 -0700 Subject: [PATCH 20/22] Shorten language on Authenticate with a GitHub host. The default authentication mode is a web-based browser flow. After completion, an authentication token will be stored securely in the system credential store. If a credential store is not found or there is an issue using it gh will fallback to writing the token to a plain text file. See `gh auth status` for its stored location. Alternatively, use `--with-token` to pass in a token on standard input. The minimum required scopes for the token are: `repo`, `read:org`, and `gist`. Alternatively, gh will use the authentication token found in environment variables. This method is most suitable for "headless" use of gh such as in automation. See `gh help environment` for more info. To use gh in GitHub Actions, add `GH_TOKEN: ${{ github.token }}` to `env`. The git protocol to use for git operations on this host can be set with `--git-protocol`, or during the interactive prompting. Although login is for a single account on a host, setting the git protocol will take effect for all users on the host. Specifying `ssh` for the git protocol will detect existing SSH keys to upload, prompting to create and upload a new key if one is not found. This can be skipped with `--skip-ssh-key` flag. USAGE gh auth login [flags] FLAGS -p, --git-protocol string The protocol to use for git operations on this host: {ssh|https} -h, --hostname string The hostname of the GitHub instance to authenticate with --insecure-storage Save authentication credentials in plain text instead of credential store -s, --scopes strings Additional authentication scopes to request --skip-ssh-key Skip generate/upload SSH key prompt -w, --web Open a browser to authenticate --with-token Read token from standard input INHERITED FLAGS --help Show help for command EXAMPLES # Start interactive setup $ gh auth login # Authenticate against github.com by reading the token from a file $ gh auth login --with-token < mytoken.txt # Authenticate with specific host $ gh auth login --hostname enterprise.internal LEARN MORE Use `gh --help` for more information about a command. Read the manual at https://cli.github.com/manual Learn about exit codes using `gh help exit-codes` around Tylers-GitHub-MacBook.local --- pkg/cmd/auth/login/login.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index a5e601960..2a4f118cc 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -59,9 +59,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm Long: heredoc.Docf(` Authenticate with a GitHub host. - The %[1]shostname%[1]s is the domain where the GitHub instance you are logging into is hosted. - For example, "github.com" is the hostname for GitHub.com. To authenticate with - a different hostname like github.enterprise.com, use that hostname instead. + The %[1]shostname%[1]s is where you log in to GitHub. The default hostname is %[1]sgithub.com%[1]s. The default authentication mode is a web-based browser flow. After completion, an authentication token will be stored securely in the system credential store. From 029dc8ffc128361ac94b04414675089f3207f4f1 Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Mon, 23 Sep 2024 09:04:03 -0700 Subject: [PATCH 21/22] Change conditional in promptForHostname to better reflect prompter changes The old isEnterprise check no longer makes sense, given the prompter is providing 'other', not 'GitHub Enterprise Server' as its non-GitHub.com option. Additionally, there was an opportunity for cleaning up the code via early returns and the removal of the default hostname lookup if we don't need it. --- pkg/cmd/auth/login/login.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 2a4f118cc..a25bd9f85 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -233,12 +233,10 @@ func promptForHostname(opts *LoginOptions) (string, error) { return "", err } - isEnterprise := hostType == 1 - - hostname := ghinstance.Default() - if isEnterprise { - hostname, err = opts.Prompter.InputHostname() + isGitHubDotCom := hostType == 0 + if isGitHubDotCom { + return ghinstance.Default(), nil } - return hostname, err + return opts.Prompter.InputHostname() } From f4af65d9dfb246ce8c3cbbd09f247917e34de3bd Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Mon, 23 Sep 2024 09:35:57 -0700 Subject: [PATCH 22/22] Update docs language to remove possible confusion around 'where you log in' --- pkg/cmd/auth/login/login.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index a25bd9f85..1480a29a0 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -59,7 +59,8 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm Long: heredoc.Docf(` Authenticate with a GitHub host. - The %[1]shostname%[1]s is where you log in to GitHub. The default hostname is %[1]sgithub.com%[1]s. + The default hostname is %[1]sgithub.com%[1]s. This can be overridden using the %[1]s--hostname%[1]s + flag. The default authentication mode is a web-based browser flow. After completion, an authentication token will be stored securely in the system credential store.