From 4afb567d06a99055b8c31cb2358251f39240d3c8 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Thu, 21 Jul 2022 13:35:53 -0500 Subject: [PATCH 1/9] WIP: survey wrapper --- internal/ghinstance/host.go | 7 +- internal/ghinstance/host_test.go | 7 +- pkg/cmd/auth/login/login.go | 42 +-- pkg/cmd/auth/login/login_test.go | 110 ++++--- pkg/cmd/auth/shared/git_credential.go | 13 +- pkg/cmd/auth/shared/login_flow.go | 93 +++--- pkg/cmd/auth/shared/login_flow_test.go | 33 +- pkg/cmd/extension/command.go | 22 +- pkg/cmd/extension/command_test.go | 41 +-- pkg/cmd/factory/default.go | 7 + pkg/cmd/repo/delete/delete.go | 22 +- pkg/cmd/repo/delete/delete_test.go | 49 ++- pkg/cmdutil/factory.go | 16 + pkg/cmdutil/prompt.go | 123 ++++++++ pkg/cmdutil/prompter_mock.go | 408 +++++++++++++++++++++++++ 15 files changed, 768 insertions(+), 225 deletions(-) create mode 100644 pkg/cmdutil/prompt.go create mode 100644 pkg/cmdutil/prompter_mock.go diff --git a/internal/ghinstance/host.go b/internal/ghinstance/host.go index b96852a4d..30dafb796 100644 --- a/internal/ghinstance/host.go +++ b/internal/ghinstance/host.go @@ -36,12 +36,7 @@ func NormalizeHostname(h string) string { return hostname } -func HostnameValidator(v interface{}) error { - hostname, valid := v.(string) - if !valid { - return errors.New("hostname is not a string") - } - +func HostnameValidator(hostname string) error { if len(strings.TrimSpace(hostname)) < 1 { return errors.New("a value is required") } diff --git a/internal/ghinstance/host_test.go b/internal/ghinstance/host_test.go index d29cd45ea..5feecbe63 100644 --- a/internal/ghinstance/host_test.go +++ b/internal/ghinstance/host_test.go @@ -95,7 +95,7 @@ func TestNormalizeHostname(t *testing.T) { func TestHostnameValidator(t *testing.T) { tests := []struct { name string - input interface{} + input string wantsErr bool }{ { @@ -118,11 +118,6 @@ func TestHostnameValidator(t *testing.T) { input: "internal.instance:2205", wantsErr: true, }, - { - name: "non-string hostname", - input: 62, - wantsErr: true, - }, } for _, tt := range tests { diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 474c21588..937b72a2e 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -6,14 +6,12 @@ import ( "net/http" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/spf13/cobra" ) @@ -21,6 +19,7 @@ type LoginOptions struct { IO *iostreams.IOStreams Config func() (config.Config, error) HttpClient func() (*http.Client, error) + Prompter cmdutil.Prompter MainExecutable string @@ -38,6 +37,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm IO: f.IOStreams, Config: f.Config, HttpClient: f.HttpClient, + Prompter: f.Prompter, } var tokenStdin bool @@ -129,7 +129,7 @@ func loginRun(opts *LoginOptions) error { hostname := opts.Hostname if opts.Interactive && hostname == "" { var err error - hostname, err = promptForHostname() + hostname, err = promptForHostname(opts) if err != nil { return err } @@ -159,15 +159,9 @@ func loginRun(opts *LoginOptions) error { existingToken, _ := cfg.AuthToken(hostname) if existingToken != "" && opts.Interactive { if err := shared.HasMinimumScopes(httpClient, hostname, existingToken); err == nil { - var keepGoing bool - err = prompt.SurveyAskOne(&survey.Confirm{ - Message: fmt.Sprintf( - "You're already logged into %s. Do you want to re-authenticate?", - hostname), - Default: false, - }, &keepGoing) + keepGoing, err := opts.Prompter.Confirm(fmt.Sprintf("You're already logged into %s. Do you want to re-authenticate?", hostname), false) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } if !keepGoing { return nil @@ -185,34 +179,28 @@ func loginRun(opts *LoginOptions) error { Scopes: opts.Scopes, Executable: opts.MainExecutable, GitProtocol: opts.GitProtocol, + Prompter: opts.Prompter, }) } -func promptForHostname() (string, error) { - var hostType int - err := prompt.SurveyAskOne(&survey.Select{ - Message: "What account do you want to log into?", - Options: []string{ +func promptForHostname(opts *LoginOptions) (string, error) { + hostType, err := opts.Prompter.Select( + "What account do you want to log into?", + "", + []string{ "GitHub.com", "GitHub Enterprise Server", - }, - }, &hostType) - + }) if err != nil { - return "", fmt.Errorf("could not prompt: %w", err) + return "", err } isEnterprise := hostType == 1 hostname := ghinstance.Default() if isEnterprise { - err := prompt.SurveyAskOne(&survey.Input{ - Message: "GHE hostname:", - }, &hostname, survey.WithValidator(ghinstance.HostnameValidator)) - if err != nil { - return "", fmt.Errorf("could not prompt: %w", err) - } + hostname, err = opts.Prompter.InputHostname() } - return hostname, nil + return hostname, err } diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 4a48aece7..28bac297b 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -14,7 +14,6 @@ import ( "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/google/shlex" "github.com/stretchr/testify/assert" ) @@ -362,14 +361,14 @@ func Test_loginRun_Survey(t *testing.T) { stubHomeDir(t, t.TempDir()) tests := []struct { - name string - opts *LoginOptions - httpStubs func(*httpmock.Registry) - askStubs func(*prompt.AskStubber) - runStubs func(*run.CommandStubber) - wantHosts string - wantErrOut *regexp.Regexp - cfgStubs func(*config.ConfigMock) + name string + opts *LoginOptions + httpStubs func(*httpmock.Registry) + prompterStubs func(*cmdutil.PrompterMock) + runStubs func(*run.CommandStubber) + wantHosts string + wantErrOut *regexp.Regexp + cfgStubs func(*config.ConfigMock) }{ { name: "already authenticated", @@ -384,9 +383,10 @@ func Test_loginRun_Survey(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org")) }, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What account do you want to log into?").AnswerWith("GitHub.com") - as.StubPrompt("You're already logged into github.com. Do you want to re-authenticate?").AnswerWith(false) + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.SelectFunc = func(_, _ string, _ []string) (int, error) { + return 0, nil + } }, wantHosts: "", wantErrOut: nil, @@ -403,11 +403,16 @@ func Test_loginRun_Survey(t *testing.T) { user: jillv git_protocol: https `), - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What is your preferred protocol for Git operations?").AnswerWith("HTTPS") - as.StubPrompt("Authenticate Git with your GitHub credentials?").AnswerWith(false) - as.StubPrompt("How would you like to authenticate GitHub CLI?").AnswerWith("Paste an authentication token") - as.StubPrompt("Paste your authentication token:").AnswerWith("def456") + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + switch prompt { + case "What is your preferred protocol for Git operations?": + return 0, nil + case "How would you like to authenticate GitHub CLI?": + return 1, nil + } + return -1, nil + } }, runStubs: func(rs *run.CommandStubber) { rs.Register(`git config credential\.https:/`, 1, "") @@ -432,13 +437,21 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What account do you want to log into?").AnswerWith("GitHub Enterprise Server") - as.StubPrompt("GHE hostname:").AnswerWith("brad.vickers") - as.StubPrompt("What is your preferred protocol for Git operations?").AnswerWith("HTTPS") - as.StubPrompt("Authenticate Git with your GitHub credentials?").AnswerWith(false) - as.StubPrompt("How would you like to authenticate GitHub CLI?").AnswerWith("Paste an authentication token") - as.StubPrompt("Paste your authentication token:").AnswerWith("def456") + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + switch prompt { + case "What account do you want to log into?": + return 1, nil + case "What is your preferred protocol for Git operations?": + return 0, nil + case "How would you like to authenticate GitHub CLI?": + return 1, nil + } + return -1, nil + } + pm.InputHostnameFunc = func() (string, error) { + return "brad.vickers", nil + } }, runStubs: func(rs *run.CommandStubber) { rs.Register(`git config credential\.https:/`, 1, "") @@ -463,12 +476,18 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What account do you want to log into?").AnswerWith("GitHub.com") - as.StubPrompt("What is your preferred protocol for Git operations?").AnswerWith("HTTPS") - as.StubPrompt("Authenticate Git with your GitHub credentials?").AnswerWith(false) - as.StubPrompt("How would you like to authenticate GitHub CLI?").AnswerWith("Paste an authentication token") - as.StubPrompt("Paste your authentication token:").AnswerWith("def456") + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + switch prompt { + case "What account do you want to log into?": + return 0, nil + case "What is your preferred protocol for Git operations?": + return 0, nil + case "How would you like to authenticate GitHub CLI?": + return 1, nil + } + return -1, nil + } }, runStubs: func(rs *run.CommandStubber) { rs.Register(`git config credential\.https:/`, 1, "") @@ -487,12 +506,18 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What account do you want to log into?").AnswerWith("GitHub.com") - as.StubPrompt("What is your preferred protocol for Git operations?").AnswerWith("SSH") - as.StubPrompt("Generate a new SSH key to add to your GitHub account?").AnswerWith(false) - as.StubPrompt("How would you like to authenticate GitHub CLI?").AnswerWith("Paste an authentication token") - as.StubPrompt("Paste your authentication token:").AnswerWith("def456") + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + switch prompt { + case "What account do you want to log into?": + return 0, nil + case "What is your preferred protocol for Git operations?": + return 1, nil + case "How would you like to authenticate GitHub CLI?": + return 1, nil + } + return -1, nil + } }, wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://github.com/settings/tokens"), }, @@ -535,10 +560,17 @@ func Test_loginRun_Survey(t *testing.T) { httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`)) } - as := prompt.NewAskStubber(t) - if tt.askStubs != nil { - tt.askStubs(as) + pm := &cmdutil.PrompterMock{} + pm.ConfirmFunc = func(_ string, _ bool) (bool, error) { + return false, nil } + pm.AuthTokenFunc = func() (string, error) { + return "def456", nil + } + if tt.prompterStubs != nil { + tt.prompterStubs(pm) + } + tt.opts.Prompter = pm rs, restoreRun := run.Stub() defer restoreRun(t) diff --git a/pkg/cmd/auth/shared/git_credential.go b/pkg/cmd/auth/shared/git_credential.go index fb8ba31c2..22a68da6b 100644 --- a/pkg/cmd/auth/shared/git_credential.go +++ b/pkg/cmd/auth/shared/git_credential.go @@ -7,17 +7,17 @@ import ( "path/filepath" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/run" - "github.com/cli/cli/v2/pkg/prompt" + "github.com/cli/cli/v2/pkg/cmdutil" "github.com/google/shlex" ) type GitCredentialFlow struct { Executable string + Prompter cmdutil.Prompter shouldSetup bool helper string @@ -32,13 +32,12 @@ func (flow *GitCredentialFlow) Prompt(hostname string) error { return nil } - err := prompt.SurveyAskOne(&survey.Confirm{ - Message: "Authenticate Git with your GitHub credentials?", - Default: true, - }, &flow.shouldSetup) + result, err := flow.Prompter.Confirm("Authenticate Git with your GitHub credentials?", true) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } + flow.shouldSetup = result + if flow.shouldSetup { if isGitMissing(gitErr) { return gitErr diff --git a/pkg/cmd/auth/shared/login_flow.go b/pkg/cmd/auth/shared/login_flow.go index 0afb84981..590fb242d 100644 --- a/pkg/cmd/auth/shared/login_flow.go +++ b/pkg/cmd/auth/shared/login_flow.go @@ -6,14 +6,13 @@ import ( "os" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/authflow" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/pkg/cmd/ssh-key/add" + "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/cli/cli/v2/pkg/ssh" ) @@ -35,6 +34,7 @@ type LoginOptions struct { Scopes []string Executable string GitProtocol string + Prompter cmdutil.Prompter sshContext ssh.Context } @@ -47,23 +47,23 @@ func Login(opts *LoginOptions) error { gitProtocol := strings.ToLower(opts.GitProtocol) if opts.Interactive && gitProtocol == "" { - var proto string - err := prompt.SurveyAskOne(&survey.Select{ - Message: "What is your preferred protocol for Git operations?", - Options: []string{ - "HTTPS", - "SSH", - }, - }, &proto) - if err != nil { - return fmt.Errorf("could not prompt: %w", err) + options := []string{ + "HTTPS", + "SSH", } + result, err := opts.Prompter.Select( + "What is your preferred protocol for Git operations?", + "", options) + if err != nil { + return err + } + proto := options[result] gitProtocol = strings.ToLower(proto) } var additionalScopes []string - credentialFlow := &GitCredentialFlow{Executable: opts.Executable} + credentialFlow := &GitCredentialFlow{Executable: opts.Executable, Prompter: opts.Prompter} if opts.Interactive && gitProtocol == "https" { if err := credentialFlow.Prompt(hostname); err != nil { return err @@ -80,33 +80,25 @@ func Login(opts *LoginOptions) error { } if len(pubKeys) > 0 { - var keyChoice int - err := prompt.SurveyAskOne(&survey.Select{ - Message: "Upload your SSH public key to your GitHub account?", - Options: append(pubKeys, "Skip"), - }, &keyChoice) + options := append(pubKeys, "Skip") + keyChoice, err := opts.Prompter.Select( + "Upload your SSH public key to your GitHub account?", "", + options) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } if keyChoice < len(pubKeys) { keyToUpload = pubKeys[keyChoice] } } else if opts.sshContext.HasKeygen() { - var sshChoice bool - err := prompt.SurveyAskOne(&survey.Confirm{ - Message: "Generate a new SSH key to add to your GitHub account?", - Default: true, - }, &sshChoice) - + sshChoice, err := opts.Prompter.Confirm("Generate a new SSH key to add to your GitHub account?", true) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } if sshChoice { - passphrase, err := promptForSshKeyPassphrase() - if err != nil { - return fmt.Errorf("could not prompt for key passphrase: %w", err) - } + passphrase, err := opts.Prompter.Password( + "Enter a passphrase for your new SSH key (Optional)") keyPair, err := opts.sshContext.GenerateSSHKey("id_ed25519", passphrase) if err != nil { @@ -117,12 +109,11 @@ func Login(opts *LoginOptions) error { } if keyToUpload != "" { - err := prompt.SurveyAskOne(&survey.Input{ - Message: "Title for your SSH key:", - Default: defaultSSHKeyTitle, - }, &keyTitle) + var err error + keyTitle, err = opts.Prompter.Input( + "Title for your SSH key:", defaultSSHKeyTitle) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } additionalScopes = append(additionalScopes, "admin:public_key") @@ -133,15 +124,14 @@ func Login(opts *LoginOptions) error { if opts.Web { authMode = 0 } else if opts.Interactive { - err := prompt.SurveyAskOne(&survey.Select{ - Message: "How would you like to authenticate GitHub CLI?", - Options: []string{ + var err error + authMode, err = opts.Prompter.Select( + "How would you like to authenticate GitHub CLI?", "", + []string{ "Login with a web browser", - "Paste an authentication token", - }, - }, &authMode) + "Paste an authentication token"}) if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } } @@ -163,11 +153,9 @@ func Login(opts *LoginOptions) error { The minimum required scopes are %s. `, hostname, scopesSentence(minimumScopes, ghinstance.IsEnterprise(hostname)))) - err := prompt.SurveyAskOne(&survey.Password{ - Message: "Paste your authentication token:", - }, &authToken, survey.WithValidator(survey.Required)) + authToken, err := opts.Prompter.AuthToken() if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err } if err := HasMinimumScopes(httpClient, hostname, authToken); err != nil { @@ -221,19 +209,6 @@ func Login(opts *LoginOptions) error { return nil } -func promptForSshKeyPassphrase() (string, error) { - var sshPassphrase string - err := prompt.SurveyAskOne(&survey.Password{ - Message: "Enter a passphrase for your new SSH key (Optional)", - }, &sshPassphrase) - - if err != nil { - return "", err - } - - return sshPassphrase, nil -} - func scopesSentence(scopes []string, isEnterprise bool) string { quoted := make([]string, len(scopes)) for i, s := range scopes { diff --git a/pkg/cmd/auth/shared/login_flow_test.go b/pkg/cmd/auth/shared/login_flow_test.go index 467388c6a..27db56bad 100644 --- a/pkg/cmd/auth/shared/login_flow_test.go +++ b/pkg/cmd/auth/shared/login_flow_test.go @@ -9,9 +9,9 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/run" + "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/cli/cli/v2/pkg/ssh" "github.com/stretchr/testify/assert" ) @@ -47,14 +47,28 @@ func TestLogin_ssh(t *testing.T) { httpmock.REST("POST", "api/v3/user/keys"), httpmock.StringResponse(`{}`)) - ask := prompt.NewAskStubber(t) - - ask.StubPrompt("What is your preferred protocol for Git operations?").AnswerWith("SSH") - ask.StubPrompt("Generate a new SSH key to add to your GitHub account?").AnswerWith(true) - ask.StubPrompt("Enter a passphrase for your new SSH key (Optional)").AnswerWith("monkey") - ask.StubPrompt("Title for your SSH key:").AnswerWith("Test Key") - ask.StubPrompt("How would you like to authenticate GitHub CLI?").AnswerWith("Paste an authentication token") - ask.StubPrompt("Paste your authentication token:").AnswerWith("ATOKEN") + pm := &cmdutil.PrompterMock{} + pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + switch prompt { + case "What is your preferred protocol for Git operations?": + return 1, nil + case "How would you like to authenticate GitHub CLI?": + return 1, nil + } + return -1, nil + } + pm.PasswordFunc = func(_ string) (string, error) { + return "monkey", nil + } + pm.ConfirmFunc = func(prompt string, _ bool) (bool, error) { + return true, nil + } + pm.AuthTokenFunc = func() (string, error) { + return "ATOKEN", nil + } + pm.InputFunc = func(_, _ string) (string, error) { + return "Test Key", nil + } rs, runRestore := run.Stub() defer runRestore(t) @@ -77,6 +91,7 @@ func TestLogin_ssh(t *testing.T) { err := Login(&LoginOptions{ IO: ios, Config: &cfg, + Prompter: pm, HTTPClient: &http.Client{Transport: &tr}, Hostname: "example.com", Interactive: true, diff --git a/pkg/cmd/extension/command.go b/pkg/cmd/extension/command.go index cefda803b..a0a6243f0 100644 --- a/pkg/cmd/extension/command.go +++ b/pkg/cmd/extension/command.go @@ -6,13 +6,11 @@ import ( "os" "strings" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/extensions" - "github.com/cli/cli/v2/pkg/prompt" "github.com/cli/cli/v2/utils" "github.com/spf13/cobra" ) @@ -20,6 +18,7 @@ import ( func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { m := f.ExtensionManager io := f.IOStreams + prompter := f.Prompter extCmd := cobra.Command{ Use: "extension", @@ -244,22 +243,15 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { }, func() *cobra.Command { promptCreate := func() (string, extensions.ExtTemplateType, error) { - var extName string - var extTmplType int - err := prompt.SurveyAskOne(&survey.Input{ - Message: "Extension name:", - }, &extName) + extName, err := prompter.Input("Extension name:", "") if err != nil { return extName, -1, err } - err = prompt.SurveyAskOne(&survey.Select{ - Message: "What kind of extension?", - Options: []string{ - "Script (Bash, Ruby, Python, etc)", - "Go", - "Other Precompiled (C++, Rust, etc)", - }, - }, &extTmplType) + extTmplType, err := prompter.Select("What kind of extension?", "", []string{ + "Script (Bash, Ruby, Python, etc)", + "Go", + "Other Precompiled (C++, Rust, etc)", + }) return extName, extensions.ExtTemplateType(extTmplType), err } var flagType string diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index fdf7588ef..6d1090d5c 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -16,7 +16,6 @@ import ( "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" ) @@ -28,15 +27,15 @@ func TestNewCmdExtension(t *testing.T) { t.Cleanup(func() { _ = os.Chdir(oldWd) }) tests := []struct { - name string - args []string - managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T) - askStubs func(as *prompt.AskStubber) - isTTY bool - wantErr bool - errMsg string - wantStdout string - wantStderr string + name string + args []string + managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T) + prompterStubs func(pm *cmdutil.PrompterMock) + isTTY bool + wantErr bool + errMsg string + wantStdout string + wantStderr string }{ { name: "install an extension", @@ -387,11 +386,16 @@ func TestNewCmdExtension(t *testing.T) { } }, isTTY: true, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("Extension name:").AnswerWith("test") - as.StubPrompt("What kind of extension?"). - AssertOptions([]string{"Script (Bash, Ruby, Python, etc)", "Go", "Other Precompiled (C++, Rust, etc)"}). - AnswerDefault() + prompterStubs: func(pm *cmdutil.PrompterMock) { + pm.InputFunc = func(prompt, defVal string) (string, error) { + if prompt == "Extension name:" { + return "test", nil + } + return "", nil + } + pm.SelectFunc = func(prompt, defVal string, opts []string) (int, error) { + return 0, nil + } }, wantStdout: heredoc.Doc(` ✓ Created directory gh-test @@ -562,9 +566,9 @@ func TestNewCmdExtension(t *testing.T) { assertFunc = tt.managerStubs(em) } - as := prompt.NewAskStubber(t) - if tt.askStubs != nil { - tt.askStubs(as) + pm := &cmdutil.PrompterMock{} + if tt.prompterStubs != nil { + tt.prompterStubs(pm) } reg := httpmock.Registry{} @@ -577,6 +581,7 @@ func TestNewCmdExtension(t *testing.T) { }, IOStreams: ios, ExtensionManager: em, + Prompter: pm, HttpClient: func() (*http.Client, error) { return &client, nil }, diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index fdc56bb3e..8c0cd06b9 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -31,6 +31,7 @@ func New(appVersion string) *cmdutil.Factory { f.HttpClient = httpClientFunc(f, appVersion) // Depends on Config, IOStreams, and appVersion f.Remotes = remotesFunc(f) // Depends on Config f.BaseRepo = BaseRepoFunc(f) // Depends on Remotes + f.Prompter = prompter(f) // Depends on Config and IOStreams f.Browser = browser(f) // Depends on Config, and IOStreams f.ExtensionManager = extensionManager(f) // Depends on Config, HttpClient, and IOStreams @@ -107,6 +108,12 @@ func browser(f *cmdutil.Factory) cmdutil.Browser { return cmdutil.NewBrowser(browserLauncher(f), io.Out, io.ErrOut) } +func prompter(f *cmdutil.Factory) cmdutil.Prompter { + editor, _ := cmdutil.DetermineEditor(f.Config) + io := f.IOStreams + return cmdutil.NewPrompter(editor, io.In, io.Out, io.ErrOut) +} + // Browser precedence // 1. GH_BROWSER // 2. browser from config diff --git a/pkg/cmd/repo/delete/delete.go b/pkg/cmd/repo/delete/delete.go index 5fd5a5340..34e58780c 100644 --- a/pkg/cmd/repo/delete/delete.go +++ b/pkg/cmd/repo/delete/delete.go @@ -9,9 +9,7 @@ import ( "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmdutil" - "github.com/cli/cli/v2/pkg/prompt" - "github.com/AlecAivazis/survey/v2" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" ) @@ -19,6 +17,7 @@ import ( type DeleteOptions struct { HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) + Prompter cmdutil.Prompter IO *iostreams.IOStreams RepoArg string Confirmed bool @@ -29,6 +28,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co IO: f.IOStreams, HttpClient: f.HttpClient, BaseRepo: f.BaseRepo, + Prompter: f.Prompter, } cmd := &cobra.Command{ @@ -91,19 +91,13 @@ func deleteRun(opts *DeleteOptions) error { fullName := ghrepo.FullName(toDelete) if !opts.Confirmed { - var valid string - err := prompt.SurveyAskOne( - &survey.Input{Message: fmt.Sprintf("Type %s to confirm deletion:", fullName)}, - &valid, - survey.WithValidator( - func(val interface{}) error { - if str := val.(string); !strings.EqualFold(str, fullName) { - return fmt.Errorf("You entered %s", str) - } - return nil - })) + result, err := opts.Prompter.Input( + fmt.Sprintf("Type %s to confirm deletion:", fullName), "") if err != nil { - return fmt.Errorf("could not prompt: %w", err) + return err + } + if !strings.EqualFold(result, fullName) { + return fmt.Errorf("You entered %s", result) } } diff --git a/pkg/cmd/repo/delete/delete_test.go b/pkg/cmd/repo/delete/delete_test.go index beb66c183..7dc443aac 100644 --- a/pkg/cmd/repo/delete/delete_test.go +++ b/pkg/cmd/repo/delete/delete_test.go @@ -9,7 +9,6 @@ import ( "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/google/shlex" "github.com/stretchr/testify/assert" ) @@ -77,25 +76,24 @@ func TestNewCmdDelete(t *testing.T) { func Test_deleteRun(t *testing.T) { tests := []struct { - name string - tty bool - opts *DeleteOptions - httpStubs func(*httpmock.Registry) - askStubs func(*prompt.AskStubber) - wantStdout string - wantErr bool - errMsg string + name string + tty bool + opts *DeleteOptions + httpStubs func(*httpmock.Registry) + prompterStubs func(*cmdutil.PrompterMock) + wantStdout string + wantErr bool + errMsg string }{ { name: "prompting confirmation tty", tty: true, opts: &DeleteOptions{RepoArg: "OWNER/REPO"}, wantStdout: "✓ Deleted repository OWNER/REPO\n", - askStubs: func(q *prompt.AskStubber) { - // TODO: survey stubber doesn't have WithValidator support - // so this always passes regardless of prompt input - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt - q.StubOne("OWNER/REPO") + prompterStubs: func(p *cmdutil.PrompterMock) { + p.InputFunc = func(_, _ string) (string, error) { + return "OWNER/REPO", nil + } }, httpStubs: func(reg *httpmock.Registry) { reg.Register( @@ -108,9 +106,10 @@ func Test_deleteRun(t *testing.T) { tty: true, opts: &DeleteOptions{}, wantStdout: "✓ Deleted repository OWNER/REPO\n", - askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt - q.StubOne("OWNER/REPO") + prompterStubs: func(p *cmdutil.PrompterMock) { + p.InputFunc = func(_, _ string) (string, error) { + return "OWNER/REPO", nil + } }, httpStubs: func(reg *httpmock.Registry) { reg.Register( @@ -135,9 +134,10 @@ func Test_deleteRun(t *testing.T) { opts: &DeleteOptions{RepoArg: "REPO"}, wantStdout: "✓ Deleted repository OWNER/REPO\n", tty: true, - askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt - q.StubOne("OWNER/REPO") + prompterStubs: func(p *cmdutil.PrompterMock) { + p.InputFunc = func(_, _ string) (string, error) { + return "OWNER/REPO", nil + } }, httpStubs: func(reg *httpmock.Registry) { reg.Register( @@ -150,12 +150,11 @@ func Test_deleteRun(t *testing.T) { }, } for _, tt := range tests { - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber - q, teardown := prompt.InitAskStubber() - defer teardown() - if tt.askStubs != nil { - tt.askStubs(q) + pm := &cmdutil.PrompterMock{} + if tt.prompterStubs != nil { + tt.prompterStubs(pm) } + tt.opts.Prompter = pm tt.opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil diff --git a/pkg/cmdutil/factory.go b/pkg/cmdutil/factory.go index 668cd637c..bace0dfd6 100644 --- a/pkg/cmdutil/factory.go +++ b/pkg/cmdutil/factory.go @@ -17,9 +17,25 @@ type Browser interface { Browse(string) error } +// TODO fix current breaking tests +// TODO linter warning for using the prompt package + +//go:generate moq -rm -out prompter_mock.go . Prompter +type Prompter interface { + Select(string, string, []string) (int, error) + MultiSelect(string, string, []string) (int, error) + Input(string, string) (string, error) + InputHostname() (string, error) + Password(string) (string, error) + AuthToken() (string, error) + Confirm(string, bool) (bool, error) + MarkdownEditor(string, string, bool) (string, error) +} + type Factory struct { IOStreams *iostreams.IOStreams Browser Browser + Prompter Prompter HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) diff --git a/pkg/cmdutil/prompt.go b/pkg/cmdutil/prompt.go new file mode 100644 index 000000000..9b9354b2c --- /dev/null +++ b/pkg/cmdutil/prompt.go @@ -0,0 +1,123 @@ +package cmdutil + +import ( + "fmt" + "io" + + "github.com/AlecAivazis/survey/v2" + "github.com/AlecAivazis/survey/v2/terminal" + "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/pkg/surveyext" +) + +func NewPrompter(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter { + return &surveyPrompter{ + editorCmd: editorCmd, + stdin: stdin.(terminal.FileReader), + stdout: stdout.(terminal.FileWriter), + stderr: stderr, + } +} + +type surveyPrompter struct { + editorCmd string + stdin terminal.FileReader + stdout terminal.FileWriter + stderr io.Writer +} + +func (p *surveyPrompter) Select(message, defaultValue string, options []string) (result int, err error) { + q := &survey.Select{ + Message: message, + Default: defaultValue, + Options: options, + PageSize: 20, + } + + err = p.ask(q, &result) + + return +} + +func (p *surveyPrompter) MultiSelect(message, defaultValue string, options []string) (result int, err error) { + q := &survey.MultiSelect{ + Message: message, + Default: defaultValue, + Options: options, + PageSize: 20, + } + + err = p.ask(q, &result) + + return +} + +func (p *surveyPrompter) ask(q survey.Prompt, response interface{}, opts ...survey.AskOpt) error { + opts = append(opts, survey.WithStdio(p.stdin, p.stdout, p.stderr)) + err := survey.AskOne(q, response, opts...) + if err == nil { + return nil + } + return fmt.Errorf("could not prompt: %w", err) +} + +func (p *surveyPrompter) Input(prompt, defaultValue string) (result string, err error) { + err = p.ask(&survey.Input{ + Message: prompt, + Default: defaultValue, + }, &result) + + return +} + +func (p *surveyPrompter) InputHostname() (result string, err error) { + err = p.ask( + &survey.Input{ + Message: "GHE hostname:", + }, &result, survey.WithValidator(func(v interface{}) error { + return ghinstance.HostnameValidator(v.(string)) + })) + + return +} + +func (p *surveyPrompter) Password(prompt string) (result string, err error) { + err = p.ask(&survey.Password{ + Message: prompt, + }, &result) + + return +} + +func (p *surveyPrompter) Confirm(prompt string, defaultValue bool) (result bool, err error) { + err = p.ask(&survey.Confirm{ + Message: prompt, + Default: defaultValue, + }, &result) + + return +} +func (p *surveyPrompter) MarkdownEditor(message, defaultValue string, blankAllowed bool) (result string, err error) { + + err = p.ask(&surveyext.GhEditor{ + BlankAllowed: blankAllowed, + EditorCommand: p.editorCmd, + Editor: &survey.Editor{ + Message: message, + Default: defaultValue, + FileName: "*.md", + HideDefault: true, + AppendDefault: true, + }, + }, &result) + + return +} + +func (p *surveyPrompter) AuthToken() (result string, err error) { + err = p.ask(&survey.Password{ + Message: "Paste your authentication token:", + }, &result, survey.WithValidator(survey.Required)) + + return +} diff --git a/pkg/cmdutil/prompter_mock.go b/pkg/cmdutil/prompter_mock.go new file mode 100644 index 000000000..e2fcd339e --- /dev/null +++ b/pkg/cmdutil/prompter_mock.go @@ -0,0 +1,408 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package cmdutil + +import ( + "sync" +) + +// Ensure, that PrompterMock does implement Prompter. +// If this is not the case, regenerate this file with moq. +var _ Prompter = &PrompterMock{} + +// PrompterMock is a mock implementation of Prompter. +// +// func TestSomethingThatUsesPrompter(t *testing.T) { +// +// // make and configure a mocked Prompter +// mockedPrompter := &PrompterMock{ +// AuthTokenFunc: func() (string, error) { +// panic("mock out the AuthToken method") +// }, +// ConfirmFunc: func(s string, b bool) (bool, error) { +// panic("mock out the Confirm method") +// }, +// InputFunc: func(s1 string, s2 string) (string, error) { +// panic("mock out the Input method") +// }, +// InputHostnameFunc: func() (string, error) { +// panic("mock out the InputHostname method") +// }, +// MarkdownEditorFunc: func(s1 string, s2 string, b bool) (string, error) { +// panic("mock out the MarkdownEditor method") +// }, +// MultiSelectFunc: func(s1 string, s2 string, strings []string) (int, error) { +// panic("mock out the MultiSelect method") +// }, +// PasswordFunc: func(s string) (string, error) { +// panic("mock out the Password method") +// }, +// SelectFunc: func(s1 string, s2 string, strings []string) (int, error) { +// panic("mock out the Select method") +// }, +// } +// +// // use mockedPrompter in code that requires Prompter +// // and then make assertions. +// +// } +type PrompterMock struct { + // AuthTokenFunc mocks the AuthToken method. + AuthTokenFunc func() (string, error) + + // ConfirmFunc mocks the Confirm method. + ConfirmFunc func(s string, b bool) (bool, error) + + // InputFunc mocks the Input method. + InputFunc func(s1 string, s2 string) (string, error) + + // InputHostnameFunc mocks the InputHostname method. + InputHostnameFunc func() (string, error) + + // MarkdownEditorFunc mocks the MarkdownEditor method. + MarkdownEditorFunc func(s1 string, s2 string, b bool) (string, error) + + // MultiSelectFunc mocks the MultiSelect method. + MultiSelectFunc func(s1 string, s2 string, strings []string) (int, error) + + // PasswordFunc mocks the Password method. + PasswordFunc func(s string) (string, error) + + // SelectFunc mocks the Select method. + SelectFunc func(s1 string, s2 string, strings []string) (int, error) + + // calls tracks calls to the methods. + calls struct { + // AuthToken holds details about calls to the AuthToken method. + AuthToken []struct { + } + // Confirm holds details about calls to the Confirm method. + Confirm []struct { + // S is the s argument value. + S string + // B is the b argument value. + B bool + } + // Input holds details about calls to the Input method. + Input []struct { + // S1 is the s1 argument value. + S1 string + // S2 is the s2 argument value. + S2 string + } + // InputHostname holds details about calls to the InputHostname method. + InputHostname []struct { + } + // MarkdownEditor holds details about calls to the MarkdownEditor method. + MarkdownEditor []struct { + // S1 is the s1 argument value. + S1 string + // S2 is the s2 argument value. + S2 string + // B is the b argument value. + B bool + } + // MultiSelect holds details about calls to the MultiSelect method. + MultiSelect []struct { + // S1 is the s1 argument value. + S1 string + // S2 is the s2 argument value. + S2 string + // Strings is the strings argument value. + Strings []string + } + // Password holds details about calls to the Password method. + Password []struct { + // S is the s argument value. + S string + } + // Select holds details about calls to the Select method. + Select []struct { + // S1 is the s1 argument value. + S1 string + // S2 is the s2 argument value. + S2 string + // Strings is the strings argument value. + Strings []string + } + } + lockAuthToken sync.RWMutex + lockConfirm sync.RWMutex + lockInput sync.RWMutex + lockInputHostname sync.RWMutex + lockMarkdownEditor sync.RWMutex + lockMultiSelect sync.RWMutex + lockPassword sync.RWMutex + lockSelect sync.RWMutex +} + +// AuthToken calls AuthTokenFunc. +func (mock *PrompterMock) AuthToken() (string, error) { + if mock.AuthTokenFunc == nil { + panic("PrompterMock.AuthTokenFunc: method is nil but Prompter.AuthToken was just called") + } + callInfo := struct { + }{} + mock.lockAuthToken.Lock() + mock.calls.AuthToken = append(mock.calls.AuthToken, callInfo) + mock.lockAuthToken.Unlock() + return mock.AuthTokenFunc() +} + +// AuthTokenCalls gets all the calls that were made to AuthToken. +// Check the length with: +// len(mockedPrompter.AuthTokenCalls()) +func (mock *PrompterMock) AuthTokenCalls() []struct { +} { + var calls []struct { + } + mock.lockAuthToken.RLock() + calls = mock.calls.AuthToken + mock.lockAuthToken.RUnlock() + return calls +} + +// Confirm calls ConfirmFunc. +func (mock *PrompterMock) Confirm(s string, b bool) (bool, error) { + if mock.ConfirmFunc == nil { + panic("PrompterMock.ConfirmFunc: method is nil but Prompter.Confirm was just called") + } + callInfo := struct { + S string + B bool + }{ + S: s, + B: b, + } + mock.lockConfirm.Lock() + mock.calls.Confirm = append(mock.calls.Confirm, callInfo) + mock.lockConfirm.Unlock() + return mock.ConfirmFunc(s, b) +} + +// ConfirmCalls gets all the calls that were made to Confirm. +// Check the length with: +// len(mockedPrompter.ConfirmCalls()) +func (mock *PrompterMock) ConfirmCalls() []struct { + S string + B bool +} { + var calls []struct { + S string + B bool + } + mock.lockConfirm.RLock() + calls = mock.calls.Confirm + mock.lockConfirm.RUnlock() + return calls +} + +// Input calls InputFunc. +func (mock *PrompterMock) Input(s1 string, s2 string) (string, error) { + if mock.InputFunc == nil { + panic("PrompterMock.InputFunc: method is nil but Prompter.Input was just called") + } + callInfo := struct { + S1 string + S2 string + }{ + S1: s1, + S2: s2, + } + mock.lockInput.Lock() + mock.calls.Input = append(mock.calls.Input, callInfo) + mock.lockInput.Unlock() + return mock.InputFunc(s1, s2) +} + +// InputCalls gets all the calls that were made to Input. +// Check the length with: +// len(mockedPrompter.InputCalls()) +func (mock *PrompterMock) InputCalls() []struct { + S1 string + S2 string +} { + var calls []struct { + S1 string + S2 string + } + mock.lockInput.RLock() + calls = mock.calls.Input + mock.lockInput.RUnlock() + return calls +} + +// InputHostname calls InputHostnameFunc. +func (mock *PrompterMock) InputHostname() (string, error) { + if mock.InputHostnameFunc == nil { + panic("PrompterMock.InputHostnameFunc: method is nil but Prompter.InputHostname was just called") + } + callInfo := struct { + }{} + mock.lockInputHostname.Lock() + mock.calls.InputHostname = append(mock.calls.InputHostname, callInfo) + mock.lockInputHostname.Unlock() + return mock.InputHostnameFunc() +} + +// InputHostnameCalls gets all the calls that were made to InputHostname. +// Check the length with: +// len(mockedPrompter.InputHostnameCalls()) +func (mock *PrompterMock) InputHostnameCalls() []struct { +} { + var calls []struct { + } + mock.lockInputHostname.RLock() + calls = mock.calls.InputHostname + mock.lockInputHostname.RUnlock() + return calls +} + +// MarkdownEditor calls MarkdownEditorFunc. +func (mock *PrompterMock) MarkdownEditor(s1 string, s2 string, b bool) (string, error) { + if mock.MarkdownEditorFunc == nil { + panic("PrompterMock.MarkdownEditorFunc: method is nil but Prompter.MarkdownEditor was just called") + } + callInfo := struct { + S1 string + S2 string + B bool + }{ + S1: s1, + S2: s2, + B: b, + } + mock.lockMarkdownEditor.Lock() + mock.calls.MarkdownEditor = append(mock.calls.MarkdownEditor, callInfo) + mock.lockMarkdownEditor.Unlock() + return mock.MarkdownEditorFunc(s1, s2, b) +} + +// MarkdownEditorCalls gets all the calls that were made to MarkdownEditor. +// Check the length with: +// len(mockedPrompter.MarkdownEditorCalls()) +func (mock *PrompterMock) MarkdownEditorCalls() []struct { + S1 string + S2 string + B bool +} { + var calls []struct { + S1 string + S2 string + B bool + } + mock.lockMarkdownEditor.RLock() + calls = mock.calls.MarkdownEditor + mock.lockMarkdownEditor.RUnlock() + return calls +} + +// MultiSelect calls MultiSelectFunc. +func (mock *PrompterMock) MultiSelect(s1 string, s2 string, strings []string) (int, error) { + if mock.MultiSelectFunc == nil { + panic("PrompterMock.MultiSelectFunc: method is nil but Prompter.MultiSelect was just called") + } + callInfo := struct { + S1 string + S2 string + Strings []string + }{ + S1: s1, + S2: s2, + Strings: strings, + } + mock.lockMultiSelect.Lock() + mock.calls.MultiSelect = append(mock.calls.MultiSelect, callInfo) + mock.lockMultiSelect.Unlock() + return mock.MultiSelectFunc(s1, s2, strings) +} + +// MultiSelectCalls gets all the calls that were made to MultiSelect. +// Check the length with: +// len(mockedPrompter.MultiSelectCalls()) +func (mock *PrompterMock) MultiSelectCalls() []struct { + S1 string + S2 string + Strings []string +} { + var calls []struct { + S1 string + S2 string + Strings []string + } + mock.lockMultiSelect.RLock() + calls = mock.calls.MultiSelect + mock.lockMultiSelect.RUnlock() + return calls +} + +// Password calls PasswordFunc. +func (mock *PrompterMock) Password(s string) (string, error) { + if mock.PasswordFunc == nil { + panic("PrompterMock.PasswordFunc: method is nil but Prompter.Password was just called") + } + callInfo := struct { + S string + }{ + S: s, + } + mock.lockPassword.Lock() + mock.calls.Password = append(mock.calls.Password, callInfo) + mock.lockPassword.Unlock() + return mock.PasswordFunc(s) +} + +// PasswordCalls gets all the calls that were made to Password. +// Check the length with: +// len(mockedPrompter.PasswordCalls()) +func (mock *PrompterMock) PasswordCalls() []struct { + S string +} { + var calls []struct { + S string + } + mock.lockPassword.RLock() + calls = mock.calls.Password + mock.lockPassword.RUnlock() + return calls +} + +// Select calls SelectFunc. +func (mock *PrompterMock) Select(s1 string, s2 string, strings []string) (int, error) { + if mock.SelectFunc == nil { + panic("PrompterMock.SelectFunc: method is nil but Prompter.Select was just called") + } + callInfo := struct { + S1 string + S2 string + Strings []string + }{ + S1: s1, + S2: s2, + Strings: strings, + } + mock.lockSelect.Lock() + mock.calls.Select = append(mock.calls.Select, callInfo) + mock.lockSelect.Unlock() + return mock.SelectFunc(s1, s2, strings) +} + +// SelectCalls gets all the calls that were made to Select. +// Check the length with: +// len(mockedPrompter.SelectCalls()) +func (mock *PrompterMock) SelectCalls() []struct { + S1 string + S2 string + Strings []string +} { + var calls []struct { + S1 string + S2 string + Strings []string + } + mock.lockSelect.RLock() + calls = mock.calls.Select + mock.lockSelect.RUnlock() + return calls +} From 710212fb3d02281784fc5f419e704ee2a17e6458 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 26 Jul 2022 14:53:10 -0500 Subject: [PATCH 2/9] use Prompter in pr review --- pkg/cmd/pr/review/review.go | 85 ++++++++------------------------ pkg/cmd/pr/review/review_test.go | 80 ++++++++---------------------- 2 files changed, 40 insertions(+), 125 deletions(-) diff --git a/pkg/cmd/pr/review/review.go b/pkg/cmd/pr/review/review.go index 07593d747..7549fe921 100644 --- a/pkg/cmd/pr/review/review.go +++ b/pkg/cmd/pr/review/review.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" - "github.com/AlecAivazis/survey/v2" "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/config" @@ -13,8 +12,6 @@ import ( "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/markdown" - "github.com/cli/cli/v2/pkg/prompt" - "github.com/cli/cli/v2/pkg/surveyext" "github.com/spf13/cobra" ) @@ -22,6 +19,7 @@ type ReviewOptions struct { HttpClient func() (*http.Client, error) Config func() (config.Config, error) IO *iostreams.IOStreams + Prompter cmdutil.Prompter Finder shared.PRFinder @@ -36,6 +34,7 @@ func NewCmdReview(f *cmdutil.Factory, runF func(*ReviewOptions) error) *cobra.Co IO: f.IOStreams, HttpClient: f.HttpClient, Config: f.Config, + Prompter: f.Prompter, } var ( @@ -160,7 +159,7 @@ func reviewRun(opts *ReviewOptions) error { if err != nil { return err } - reviewData, err = reviewSurvey(opts.IO, editorCommand) + reviewData, err = reviewSurvey(opts, editorCommand) if err != nil { return err } @@ -204,95 +203,51 @@ func reviewRun(opts *ReviewOptions) error { return nil } -func reviewSurvey(io *iostreams.IOStreams, editorCommand string) (*api.PullRequestReviewInput, error) { - typeAnswers := struct { - ReviewType string - }{} - typeQs := []*survey.Question{ - { - Name: "reviewType", - Prompt: &survey.Select{ - Message: "What kind of review do you want to give?", - Options: []string{ - "Comment", - "Approve", - "Request changes", - }, - }, - }, - } - - err := prompt.SurveyAsk(typeQs, &typeAnswers) +func reviewSurvey(opts *ReviewOptions, editorCommand string) (*api.PullRequestReviewInput, error) { + reviewType, err := opts.Prompter.Select( + "What kind of review do you want to give?", "", + []string{"Comment", "Approve", "Request Changes"}) if err != nil { return nil, err } var reviewState api.PullRequestReviewState - switch typeAnswers.ReviewType { - case "Approve": - reviewState = api.ReviewApprove - case "Request changes": - reviewState = api.ReviewRequestChanges - case "Comment": + switch reviewType { + case 0: reviewState = api.ReviewComment + case 1: + reviewState = api.ReviewApprove + case 2: + reviewState = api.ReviewRequestChanges default: panic("unreachable state") } - bodyAnswers := struct { - Body string - }{} - blankAllowed := false if reviewState == api.ReviewApprove { blankAllowed = true } - bodyQs := []*survey.Question{ - { - Name: "body", - Prompt: &surveyext.GhEditor{ - BlankAllowed: blankAllowed, - EditorCommand: editorCommand, - Editor: &survey.Editor{ - Message: "Review body", - FileName: "*.md", - }, - }, - }, - } - - err = prompt.SurveyAsk(bodyQs, &bodyAnswers) + body, err := opts.Prompter.MarkdownEditor("Review body", "", blankAllowed) if err != nil { return nil, err } - if bodyAnswers.Body == "" && (reviewState == api.ReviewComment || reviewState == api.ReviewRequestChanges) { + if body == "" && (reviewState == api.ReviewComment || reviewState == api.ReviewRequestChanges) { return nil, errors.New("this type of review cannot be blank") } - if len(bodyAnswers.Body) > 0 { - renderedBody, err := markdown.Render(bodyAnswers.Body, markdown.WithIO(io)) + if len(body) > 0 { + renderedBody, err := markdown.Render(body, markdown.WithIO(opts.IO)) if err != nil { return nil, err } - fmt.Fprintf(io.Out, "Got:\n%s", renderedBody) + fmt.Fprintf(opts.IO.Out, "Got:\n%s", renderedBody) } - confirm := false - confirmQs := []*survey.Question{ - { - Name: "confirm", - Prompt: &survey.Confirm{ - Message: "Submit?", - Default: true, - }, - }, - } - - err = prompt.SurveyAsk(confirmQs, &confirm) + confirm, err := opts.Prompter.Confirm("Submit?", true) if err != nil { return nil, err } @@ -302,7 +257,7 @@ func reviewSurvey(io *iostreams.IOStreams, editorCommand string) (*api.PullReque } return &api.PullRequestReviewInput{ - Body: bodyAnswers.Body, + Body: body, State: reviewState, }, nil } diff --git a/pkg/cmd/pr/review/review_test.go b/pkg/cmd/pr/review/review_test.go index 13c9aab1a..ab41af9fb 100644 --- a/pkg/cmd/pr/review/review_test.go +++ b/pkg/cmd/pr/review/review_test.go @@ -18,7 +18,6 @@ import ( "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" - "github.com/cli/cli/v2/pkg/prompt" "github.com/cli/cli/v2/test" "github.com/google/shlex" "github.com/stretchr/testify/assert" @@ -166,7 +165,7 @@ func Test_NewCmdReview(t *testing.T) { } } -func runCommand(rt http.RoundTripper, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) { +func runCommand(rt http.RoundTripper, prompter cmdutil.Prompter, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) { ios, _, stdout, stderr := iostreams.Test() ios.SetStdoutTTY(isTTY) ios.SetStdinTTY(isTTY) @@ -180,6 +179,7 @@ func runCommand(rt http.RoundTripper, remotes context.Remotes, isTTY bool, cli s Config: func() (config.Config, error) { return config.NewBlankConfig(), nil }, + Prompter: prompter, } cmd := NewCmdReview(factory, nil) @@ -248,7 +248,7 @@ func TestPRReview(t *testing.T) { }), ) - output, err := runCommand(http, nil, false, tt.args) + output, err := runCommand(http, nil, nil, false, tt.args) assert.NoError(t, err) assert.Equal(t, "", output.String()) assert.Equal(t, "", output.Stderr()) @@ -271,33 +271,13 @@ func TestPRReview_interactive(t *testing.T) { }), ) - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber - as, teardown := prompt.InitAskStubber() - defer teardown() + pm := &cmdutil.PrompterMock{ + SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil }, + MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "cool story", nil }, + ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil }, + } - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "reviewType", - Value: "Approve", - }, - }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "body", - Value: "cool story", - }, - }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "confirm", - Value: true, - }, - }) - - output, err := runCommand(http, nil, true, "") + output, err := runCommand(http, pm, nil, true, "") assert.NoError(t, err) assert.Equal(t, heredoc.Doc(` Got: @@ -314,12 +294,12 @@ func TestPRReview_interactive_no_body(t *testing.T) { shared.RunCommandFinder("", &api.PullRequest{ID: "THE-ID", Number: 123}, ghrepo.New("OWNER", "REPO")) - as := prompt.NewAskStubber(t) + pm := &cmdutil.PrompterMock{ + SelectFunc: func(_, _ string, _ []string) (int, error) { return 2, nil }, + MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "", nil }, + } - as.StubPrompt("What kind of review do you want to give?").AnswerWith("Request changes") - as.StubPrompt("Review body").AnswerWith("") - - _, err := runCommand(http, nil, true, "") + _, err := runCommand(http, pm, nil, true, "") assert.EqualError(t, err, "this type of review cannot be blank") } @@ -338,33 +318,13 @@ func TestPRReview_interactive_blank_approve(t *testing.T) { }), ) - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber - as, teardown := prompt.InitAskStubber() - defer teardown() + pm := &cmdutil.PrompterMock{ + SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil }, + MarkdownEditorFunc: func(_, defVal string, _ bool) (string, error) { return defVal, nil }, + ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil }, + } - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "reviewType", - Value: "Approve", - }, - }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "body", - Default: true, - }, - }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt - as.Stub([]*prompt.QuestionStub{ - { - Name: "confirm", - Value: true, - }, - }) - - output, err := runCommand(http, nil, true, "") + output, err := runCommand(http, pm, nil, true, "") assert.NoError(t, err) assert.Equal(t, "", output.String()) assert.Equal(t, "✓ Approved pull request #123\n", output.Stderr()) From 40ecb8c18825297871310dd9ce9304474a23d26f Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 26 Jul 2022 16:06:52 -0500 Subject: [PATCH 3/9] update linter checks --- pkg/cmd/auth/logout/logout_test.go | 1 + pkg/cmd/auth/refresh/refresh_test.go | 1 + pkg/cmd/gist/edit/edit_test.go | 4 ++ pkg/cmd/gist/view/view_test.go | 3 ++ pkg/cmd/issue/create/create_test.go | 8 ++++ pkg/cmd/issue/delete/delete_test.go | 2 + pkg/cmd/label/delete_test.go | 1 + pkg/cmd/pr/create/create_test.go | 30 ++++++++---- pkg/cmd/pr/merge/merge_test.go | 19 ++++++++ pkg/cmd/pr/shared/survey_test.go | 12 ++--- pkg/cmd/pr/shared/templates_test.go | 2 + pkg/cmd/release/create/create_test.go | 27 +++++++++++ pkg/cmd/repo/archive/archive_test.go | 6 +-- pkg/cmd/repo/create/create_test.go | 60 ++++++++++++------------ pkg/cmd/repo/edit/edit_test.go | 10 ++++ pkg/cmd/repo/fork/fork_test.go | 12 ++--- pkg/cmd/repo/rename/rename_test.go | 10 ++-- pkg/cmd/run/cancel/cancel_test.go | 4 +- pkg/cmd/run/rerun/rerun_test.go | 4 +- pkg/cmd/run/view/view_test.go | 28 +++++------ pkg/cmd/run/watch/watch_test.go | 2 + pkg/cmd/secret/set/set_test.go | 1 + pkg/cmd/workflow/disable/disable_test.go | 2 + pkg/cmd/workflow/enable/enable_test.go | 2 + pkg/cmd/workflow/run/run_test.go | 4 ++ pkg/prompt/stubber.go | 11 +++-- 26 files changed, 187 insertions(+), 79 deletions(-) diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index aa176f9f0..7ccb4bd48 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -106,6 +106,7 @@ func Test_logoutRun_tty(t *testing.T) { cfgHosts: []string{"cheryl.mason", "github.com"}, wantHosts: "cheryl.mason:\n oauth_token: abc123\n", askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What account do you want to log out of?").AnswerWith("github.com") }, wantErrOut: regexp.MustCompile(`Logged out of github.com account 'cybilb'`), diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 3de01897f..7267ced0f 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -194,6 +194,7 @@ func Test_refreshRun(t *testing.T) { Hostname: "", }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What account do you want to refresh auth for?").AnswerWith("github.com") }, wantAuthArgs: authArgs{ diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index 7318f26f8..0957ebddb 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -162,7 +162,9 @@ func Test_editRun(t *testing.T) { { name: "multiple files, submit", askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Edit which file?").AnswerWith("unix.md") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What next?").AnswerWith("Submit") }, gist: &shared.Gist{ @@ -207,7 +209,9 @@ func Test_editRun(t *testing.T) { { name: "multiple files, cancel", askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Edit which file?").AnswerWith("unix.md") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What next?").AnswerWith("Cancel") }, wantErr: "CancelError", diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 42ec91fef..58fb1ee7f 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -356,6 +356,7 @@ func Test_viewRun(t *testing.T) { ) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerDefault() } @@ -401,6 +402,7 @@ func Test_promptGists(t *testing.T) { { name: "multiple files, select first gist", askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerWith("cool.txt about 6 hours ago") }, response: `{ "data": { "viewer": { "gists": { "nodes": [ @@ -424,6 +426,7 @@ func Test_promptGists(t *testing.T) { { name: "multiple files, select second gist", askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerWith("gistfile0.txt about 6 hours ago") }, response: `{ "data": { "viewer": { "gists": { "nodes": [ diff --git a/pkg/cmd/issue/create/create_test.go b/pkg/cmd/issue/create/create_test.go index ae98535c5..b2ebbd69b 100644 --- a/pkg/cmd/issue/create/create_test.go +++ b/pkg/cmd/issue/create/create_test.go @@ -404,8 +404,11 @@ func TestIssueCreate_recover(t *testing.T) { as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*") @@ -471,8 +474,11 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) { as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template").AnswerWith("Submit a request") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Continue in browser", "Cancel"}). AnswerWith("Submit") @@ -501,7 +507,9 @@ func TestIssueCreate_continueInBrowser(t *testing.T) { as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerWith("hello") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Continue in browser") _, cmdTeardown := run.Stub() diff --git a/pkg/cmd/issue/delete/delete_test.go b/pkg/cmd/issue/delete/delete_test.go index 2cf323e56..2a2837c47 100644 --- a/pkg/cmd/issue/delete/delete_test.go +++ b/pkg/cmd/issue/delete/delete_test.go @@ -77,6 +77,7 @@ func TestIssueDelete(t *testing.T) { ) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("13") output, err := runCommand(httpRegistry, true, "13") @@ -137,6 +138,7 @@ func TestIssueDelete_cancel(t *testing.T) { ) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("14") output, err := runCommand(httpRegistry, true, "13") diff --git a/pkg/cmd/label/delete_test.go b/pkg/cmd/label/delete_test.go index 48fba81c5..918e12c76 100644 --- a/pkg/cmd/label/delete_test.go +++ b/pkg/cmd/label/delete_test.go @@ -105,6 +105,7 @@ func TestDeleteRun(t *testing.T) { askStubs: func(as *prompt.AskStubber) { // TODO: survey stubber doesn't have WithValidator support // so this always passes regardless of prompt input + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Type test to confirm deletion:").AnswerWith("test") }, wantStdout: "✓ Label \"test\" deleted from OWNER/REPO\n", diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index 33feafa40..e4710d546 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -311,12 +311,15 @@ func TestPRCreate_recover(t *testing.T) { cs.Register(`git status --porcelain`, 0, "") cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, teardown := prompt.InitAskStubber() defer teardown() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerDefault() tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*") @@ -409,10 +412,11 @@ func TestPRCreate(t *testing.T) { cs.Register(`git show-ref --verify -- HEAD refs/remotes/origin/feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body"`) @@ -456,10 +460,11 @@ func TestPRCreate_NoMaintainerModify(t *testing.T) { cs.Register(`git show-ref --verify -- HEAD refs/remotes/origin/feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body" --no-maintainer-edit`) @@ -508,10 +513,11 @@ func TestPRCreate_createFork(t *testing.T) { cs.Register(`git remote add -f fork https://github.com/monalisa/REPO.git`, 0, "") cs.Register(`git push --set-upstream fork HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?"). AssertOptions([]string{"OWNER/REPO", "Create a fork of OWNER/REPO", "Skip pushing the branch", "Cancel"}). AnswerWith("Create a fork of OWNER/REPO") @@ -568,7 +574,7 @@ func TestPRCreate_pushedToNonBaseRepo(t *testing.T) { deadbeef refs/remotes/origin/feature `)) // determineTrackingBranch - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock _, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() @@ -610,7 +616,7 @@ func TestPRCreate_pushedToDifferentBranchName(t *testing.T) { deadbeef refs/remotes/origin/my-feat2 `)) // determineTrackingBranch - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock _, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() @@ -656,10 +662,13 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) { as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"template1", "template2", "Open a blank pull request"}). AnswerWith("template1") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Submit as draft", "Continue in browser", "Add metadata", "Cancel"}). AnswerDefault() @@ -801,10 +810,11 @@ func TestPRCreate_web(t *testing.T) { cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?"). AssertOptions([]string{"OWNER/REPO", "Skip pushing the branch", "Cancel"}). AnswerDefault() @@ -876,10 +886,11 @@ func TestPRCreate_webProject(t *testing.T) { cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `--web -p Triage`) @@ -918,8 +929,11 @@ func TestPRCreate_draft(t *testing.T) { as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Submit as draft", "Continue in browser", "Add metadata", "Cancel"}). AnswerWith("Submit as draft") diff --git a/pkg/cmd/pr/merge/merge_test.go b/pkg/cmd/pr/merge/merge_test.go index 4afa03ab4..591cf450c 100644 --- a/pkg/cmd/pr/merge/merge_test.go +++ b/pkg/cmd/pr/merge/merge_test.go @@ -961,6 +961,7 @@ func TestPrMerge_alreadyMerged(t *testing.T) { cs.Register(`git pull --ff-only`, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) output, err := runCommand(http, "blueberries", true, "pr merge 4") @@ -1022,6 +1023,7 @@ func TestPrMerge_alreadyMerged_withMergeStrategy_TTY(t *testing.T) { cs.Register(`git branch -D `, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) output, err := runCommand(http, "blueberries", true, "pr merge 4 --merge") @@ -1101,8 +1103,11 @@ func TestPRMergeTTY(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") output, err := runCommand(http, "blueberries", true, "") @@ -1162,7 +1167,9 @@ func TestPRMergeTTY_withDeleteBranch(t *testing.T) { cs.Register(`git pull --ff-only`, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") output, err := runCommand(http, "blueberries", true, "-d") @@ -1221,10 +1228,15 @@ func TestPRMergeTTY_squashEditCommitMsgAndSubject(t *testing.T) { defer cmdTeardown(t) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerWith("Squash and merge") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch on GitHub?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Edit commit message") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Edit commit subject") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") err := mergeRun(&MergeOptions{ @@ -1299,8 +1311,11 @@ func TestPRTTY_cancelled(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Cancel") output, err := runCommand(http, "blueberries", true, "") @@ -1318,6 +1333,7 @@ func Test_mergeMethodSurvey(t *testing.T) { SquashMergeAllowed: true, } as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerWith("Rebase and merge") method, err := mergeMethodSurvey(repo) @@ -1625,8 +1641,11 @@ func TestPrAddToMergeQueueAdmin(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerDefault() output, err := runCommand(http, "blueberries", true, "pr merge 1 --admin") diff --git a/pkg/cmd/pr/shared/survey_test.go b/pkg/cmd/pr/shared/survey_test.go index 0bc27e8d6..d25858435 100644 --- a/pkg/cmd/pr/shared/survey_test.go +++ b/pkg/cmd/pr/shared/survey_test.go @@ -43,18 +43,18 @@ func TestMetadataSurvey_selectAll(t *testing.T) { }, } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, restoreAsk := prompt.InitAskStubber() defer restoreAsk() - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ { Name: "metadata", Value: []string{"Labels", "Projects", "Assignees", "Reviewers", "Milestone"}, }, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ { Name: "reviewers", @@ -112,18 +112,18 @@ func TestMetadataSurvey_keepExisting(t *testing.T) { }, } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, restoreAsk := prompt.InitAskStubber() defer restoreAsk() - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ { Name: "metadata", Value: []string{"Labels", "Projects"}, }, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ { Name: "labels", diff --git a/pkg/cmd/pr/shared/templates_test.go b/pkg/cmd/pr/shared/templates_test.go index 752de47c1..12335b61a 100644 --- a/pkg/cmd/pr/shared/templates_test.go +++ b/pkg/cmd/pr/shared/templates_test.go @@ -48,6 +48,7 @@ func TestTemplateManager_hasAPI(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"Bug report", "Feature request", "Open a blank issue"}). AnswerWith("Feature request") @@ -94,6 +95,7 @@ func TestTemplateManager_hasAPI_PullRequest(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"bug_pr.md", "feature_pr.md", "Open a blank pull request"}). AnswerWith("bug_pr.md") diff --git a/pkg/cmd/release/create/create_test.go b/pkg/cmd/release/create/create_test.go index b4a95e1e6..c3ab9cdd3 100644 --- a/pkg/cmd/release/create/create_test.go +++ b/pkg/cmd/release/create/create_test.go @@ -597,14 +597,19 @@ func Test_createRun_interactive(t *testing.T) { name: "create a release from existing tag", opts: &CreateOptions{}, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a tag"). AssertOptions([]string{"v1.2.3", "v1.2.2", "v1.0.0", "v0.1.2", "Create a new tag"}). AnswerWith("v1.2.3") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Leave blank") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?"). AssertOptions([]string{"Publish release", "Save as draft", "Cancel"}).AnswerWith("Publish release") }, @@ -632,13 +637,19 @@ func Test_createRun_interactive(t *testing.T) { name: "create a release from new tag", opts: &CreateOptions{}, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a tag").AnswerWith("Create a new tag") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Tag name").AnswerWith("v1.2.3") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Leave blank") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -667,11 +678,15 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Write using generated notes as template") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -705,11 +720,15 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using commit log as template", "Leave blank"}). AnswerWith("Write using commit log as template") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -741,11 +760,15 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using git tag message as template", "Leave blank"}). AnswerWith("Write using git tag message as template") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -793,11 +816,15 @@ func Test_createRun_interactive(t *testing.T) { Target: "main", }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Write using git tag message as template", "Leave blank"}). AnswerWith("Leave blank") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { diff --git a/pkg/cmd/repo/archive/archive_test.go b/pkg/cmd/repo/archive/archive_test.go index 6d681e784..788ec2a8f 100644 --- a/pkg/cmd/repo/archive/archive_test.go +++ b/pkg/cmd/repo/archive/archive_test.go @@ -80,7 +80,7 @@ func Test_ArchiveRun(t *testing.T) { name: "unarchived repo tty", wantStdout: "✓ Archived repository OWNER/REPO\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne(true) }, isTTY: true, @@ -99,7 +99,7 @@ func Test_ArchiveRun(t *testing.T) { wantStdout: "✓ Archived repository OWNER/REPO\n", opts: ArchiveOptions{}, askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne(true) }, isTTY: true, @@ -140,7 +140,7 @@ func Test_ArchiveRun(t *testing.T) { ios, _, stdout, stderr := iostreams.Test() tt.opts.IO = ios - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index 75dd3a0d1..074f0b2df 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -187,30 +187,30 @@ func Test_createRun(t *testing.T) { tty: true, wantStdout: "✓ Created repository OWNER/REPO on GitHub\n", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("Create a new repository on GitHub from scratch") - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "addGitIgnore", Value: true}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "chooseGitIgnore", Value: "Go"}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "addLicense", Value: true}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "chooseLicense", Value: "GNU Lesser General Public License v3.0"}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "confirmSubmit", Value: true}}) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) //clone locally? }, httpStubs: func(reg *httpmock.Registry) { @@ -234,21 +234,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("Create a new repository on GitHub from scratch") - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "addGitIgnore", Value: false}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "addLicense", Value: false}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "confirmSubmit", Value: false}}) }, @@ -261,17 +261,17 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(false) }, httpStubs: func(reg *httpmock.Registry) { @@ -302,21 +302,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) //ask for adding a remote - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("origin") //ask for remote name - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(false) //ask to push to remote }, httpStubs: func(reg *httpmock.Registry) { @@ -348,21 +348,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) //ask for adding a remote - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne("origin") //ask for remote name - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) //ask to push to remote }, httpStubs: func(reg *httpmock.Registry) { @@ -452,7 +452,7 @@ func Test_createRun(t *testing.T) { }, } for _, tt := range tests { - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index dc4198581..769846972 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -173,7 +173,9 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Description"}) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Description of the repository").AnswerWith("awesome repo description") }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { @@ -213,9 +215,13 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Description", "Topics"}) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Description of the repository").AnswerWith("awesome repo description") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Add topics?(csv format)").AnswerWith("a, b,c,d ") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Remove Topics").AnswerWith([]string{"x"}) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { @@ -260,9 +266,13 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Merge Options"}) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Allowed merge strategies").AnswerWith([]string{allowMergeCommits, allowRebaseMerge}) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Enable Auto Merge?").AnswerWith(false) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Automatically delete head branches after merging?").AnswerWith(false) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index 111eb98f6..c395190a6 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -272,7 +272,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(false) }, wantErrOut: "✓ Created fork someone/REPO\n", @@ -291,7 +291,7 @@ func TestRepoFork(t *testing.T) { cs.Register(`git remote add -f origin https://github.com/someone/REPO.git`, 0, "") }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) }, wantErrOut: "✓ Created fork someone/REPO\n✓ Added remote origin\n", @@ -494,7 +494,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(false) }, wantErrOut: "✓ Created fork someone/REPO\n", @@ -508,7 +508,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) }, execStubs: func(cs *run.CommandStubber) { @@ -529,7 +529,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(true) }, execStubs: func(cs *run.CommandStubber) { @@ -700,7 +700,7 @@ func TestRepoFork(t *testing.T) { return tt.remotes, nil } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/rename/rename_test.go b/pkg/cmd/repo/rename/rename_test.go index 97e1aebb7..f536f2ab0 100644 --- a/pkg/cmd/repo/rename/rename_test.go +++ b/pkg/cmd/repo/rename/rename_test.go @@ -117,7 +117,7 @@ func TestRenameRun(t *testing.T) { name: "none argument", wantOut: "✓ Renamed repository OWNER/NEW_REPO\n✓ Updated the \"origin\" remote\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne("NEW_REPO") }, httpStubs: func(reg *httpmock.Registry) { @@ -137,7 +137,7 @@ func TestRenameRun(t *testing.T) { }, wantOut: "✓ Renamed repository OWNER/NEW_REPO\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne("NEW_REPO") }, httpStubs: func(reg *httpmock.Registry) { @@ -186,7 +186,7 @@ func TestRenameRun(t *testing.T) { }, wantOut: "✓ Renamed repository OWNER/NEW_REPO\n✓ Updated the \"origin\" remote\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne(true) }, httpStubs: func(reg *httpmock.Registry) { @@ -207,7 +207,7 @@ func TestRenameRun(t *testing.T) { DoConfirm: true, }, askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock q.StubOne(false) }, wantOut: "", @@ -215,7 +215,7 @@ func TestRenameRun(t *testing.T) { } for _, tt := range testCases { - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/cancel/cancel_test.go b/pkg/cmd/run/cancel/cancel_test.go index 4875918d7..a66e58552 100644 --- a/pkg/cmd/run/cancel/cancel_test.go +++ b/pkg/cmd/run/cancel/cancel_test.go @@ -174,7 +174,7 @@ func TestRunCancel(t *testing.T) { httpmock.StatusStringResponse(202, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(0) }, wantOut: "✓ Request to cancel workflow submitted.\n", @@ -196,7 +196,7 @@ func TestRunCancel(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/rerun/rerun_test.go b/pkg/cmd/run/rerun/rerun_test.go index 5d9dd3dc0..0bce30edb 100644 --- a/pkg/cmd/run/rerun/rerun_test.go +++ b/pkg/cmd/run/rerun/rerun_test.go @@ -294,7 +294,7 @@ func TestRerun(t *testing.T) { httpmock.StringResponse("{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) }, wantOut: "✓ Requested rerun of run 1234\n", @@ -351,7 +351,7 @@ func TestRerun(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index c2a9e51c9..b61f9ec35 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -374,7 +374,7 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse([]shared.Annotation{})) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) }, opts: &ViewOptions{ @@ -411,9 +411,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(1) }, wantOut: coolJobRunLogOutput, @@ -466,9 +466,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(0) }, wantOut: expectedRunLogOutput, @@ -527,9 +527,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(4) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) }, wantOut: quuxTheBarfLogOutput, @@ -582,9 +582,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(4) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(0) }, wantOut: quuxTheBarfLogOutput, @@ -708,9 +708,9 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse(shared.FailedJobAnnotations)) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(0) }, wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n\nFor more information about a job, try: gh run view --job=\nView this run on GitHub: https://github.com/runs/3\n", @@ -743,9 +743,9 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse([]shared.Annotation{})) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt + //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock as.StubOne(1) }, wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\nTo see the full job log, try: gh run view --log --job=10\nView this run on GitHub: https://github.com/runs/3\n", @@ -842,7 +842,7 @@ func TestViewRun(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/watch/watch_test.go b/pkg/cmd/run/watch/watch_test.go index bdb08a58d..80105c48d 100644 --- a/pkg/cmd/run/watch/watch_test.go +++ b/pkg/cmd/run/watch/watch_test.go @@ -230,6 +230,7 @@ func TestWatchRun(t *testing.T) { }, httpStubs: successfulRunStubs, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow run"). AssertOptions([]string{"* cool commit, run (trunk) Feb 23, 2021", "* cool commit, more runs (trunk) Feb 23, 2021"}). AnswerWith("* cool commit, more runs (trunk) Feb 23, 2021") @@ -246,6 +247,7 @@ func TestWatchRun(t *testing.T) { }, httpStubs: failedRunStubs, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow run"). AssertOptions([]string{"* cool commit, run (trunk) Feb 23, 2021", "* cool commit, more runs (trunk) Feb 23, 2021"}). AnswerWith("* cool commit, more runs (trunk) Feb 23, 2021") diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index c9843a5a9..976ef4593 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -561,6 +561,7 @@ func Test_getBodyPrompt(t *testing.T) { ios.SetStdoutTTY(true) as := prompt.NewAskStubber(t) + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Paste your secret").AnswerWith("cool secret") body, err := getBody(&SetOptions{ diff --git a/pkg/cmd/workflow/disable/disable_test.go b/pkg/cmd/workflow/disable/disable_test.go index bc46212ed..2397b2f80 100644 --- a/pkg/cmd/workflow/disable/disable_test.go +++ b/pkg/cmd/workflow/disable/disable_test.go @@ -121,6 +121,7 @@ func TestDisableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerWith("another workflow (another.yml)") }, wantOut: "✓ Disabled another workflow\n", @@ -176,6 +177,7 @@ func TestDisableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Which workflow do you mean?").AnswerWith("another workflow (yetanother.yml)") }, wantOut: "✓ Disabled another workflow\n", diff --git a/pkg/cmd/workflow/enable/enable_test.go b/pkg/cmd/workflow/enable/enable_test.go index ffc679a93..d200fbbce 100644 --- a/pkg/cmd/workflow/enable/enable_test.go +++ b/pkg/cmd/workflow/enable/enable_test.go @@ -121,6 +121,7 @@ func TestEnableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerWith("a disabled workflow (disabled.yml)") }, wantOut: "✓ Enabled a disabled workflow\n", @@ -176,6 +177,7 @@ func TestEnableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Which workflow do you mean?").AnswerWith("a disabled workflow (anotherDisabled.yml)") }, wantOut: "✓ Enabled a disabled workflow\n", diff --git a/pkg/cmd/workflow/run/run_test.go b/pkg/cmd/workflow/run/run_test.go index 125e3fcfb..8622f4a24 100644 --- a/pkg/cmd/workflow/run/run_test.go +++ b/pkg/cmd/workflow/run/run_test.go @@ -558,6 +558,7 @@ jobs: httpmock.StatusStringResponse(204, "cool")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerDefault() }, wantBody: map[string]interface{}{ @@ -595,8 +596,11 @@ jobs: httpmock.StatusStringResponse(204, "cool")) }, askStubs: func(as *prompt.AskStubber) { + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerDefault() + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("greeting").AnswerWith("hi") + //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("name").AnswerWith("scully") }, wantBody: map[string]interface{}{ diff --git a/pkg/prompt/stubber.go b/pkg/prompt/stubber.go index 8d9e22520..51912cd70 100644 --- a/pkg/prompt/stubber.go +++ b/pkg/prompt/stubber.go @@ -18,6 +18,7 @@ type testing interface { Cleanup(func()) } +// Deprecated: use PrompterMock func NewAskStubber(t testing) *AskStubber { as, teardown := InitAskStubber() t.Cleanup(func() { @@ -31,7 +32,7 @@ func NewAskStubber(t testing) *AskStubber { return as } -// Deprecated: use NewAskStubber +// Deprecated: use PrompterMock func InitAskStubber() (*AskStubber, func()) { origSurveyAsk := SurveyAsk origSurveyAskOne := SurveyAskOne @@ -157,34 +158,38 @@ type QuestionStub struct { } // AssertOptions asserts the options presented to the user in Selects and MultiSelects. +// Deprecated: use PrompterMock func (s *QuestionStub) AssertOptions(opts []string) *QuestionStub { s.options = opts return s } // AnswerWith defines an answer for the given stub. +// Deprecated: use PrompterMock func (s *QuestionStub) AnswerWith(v interface{}) *QuestionStub { s.Value = v return s } // AnswerDefault marks the current stub to be answered with the default value for the prompt question. +// Deprecated: use PrompterMock func (s *QuestionStub) AnswerDefault() *QuestionStub { s.Default = true return s } -// Deprecated: use StubPrompt +// Deprecated: use PrompterMock func (as *AskStubber) StubOne(value interface{}) { as.Stub([]*QuestionStub{{Value: value}}) } -// Deprecated: use StubPrompt +// Deprecated: use PrompterMock func (as *AskStubber) Stub(stubbedQuestions []*QuestionStub) { as.stubs = append(as.stubs, stubbedQuestions...) } // StubPrompt records a stub for an interactive prompt matched by its message. +// Deprecated: use PrompterMock func (as *AskStubber) StubPrompt(msg string) *QuestionStub { stub := &QuestionStub{message: msg} as.stubs = append(as.stubs, stub) From f7d5c5f725bab46e84ab79f4d52a6889374188cd Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 26 Jul 2022 16:17:01 -0500 Subject: [PATCH 4/9] move prompter to own package --- .../prompt.go => internal/prompter/prompter.go | 14 +++++++++++++- .../prompter}/prompter_mock.go | 2 +- pkg/cmd/auth/login/login.go | 3 ++- pkg/cmd/auth/login/login_test.go | 15 ++++++++------- pkg/cmd/auth/shared/git_credential.go | 4 ++-- pkg/cmd/auth/shared/login_flow.go | 4 ++-- pkg/cmd/auth/shared/login_flow_test.go | 4 ++-- pkg/cmd/extension/command_test.go | 7 ++++--- pkg/cmd/factory/default.go | 7 ++++--- pkg/cmd/pr/review/review.go | 3 ++- pkg/cmd/pr/review/review_test.go | 9 +++++---- pkg/cmd/repo/delete/delete.go | 3 ++- pkg/cmd/repo/delete/delete_test.go | 11 ++++++----- pkg/cmdutil/factory.go | 18 ++---------------- 14 files changed, 55 insertions(+), 49 deletions(-) rename pkg/cmdutil/prompt.go => internal/prompter/prompter.go (86%) rename {pkg/cmdutil => internal/prompter}/prompter_mock.go (99%) diff --git a/pkg/cmdutil/prompt.go b/internal/prompter/prompter.go similarity index 86% rename from pkg/cmdutil/prompt.go rename to internal/prompter/prompter.go index 9b9354b2c..6b89867b6 100644 --- a/pkg/cmdutil/prompt.go +++ b/internal/prompter/prompter.go @@ -1,4 +1,4 @@ -package cmdutil +package prompter import ( "fmt" @@ -10,6 +10,18 @@ import ( "github.com/cli/cli/v2/pkg/surveyext" ) +//go:generate moq -rm -out prompter_mock.go . Prompter +type Prompter interface { + Select(string, string, []string) (int, error) + MultiSelect(string, string, []string) (int, error) + Input(string, string) (string, error) + InputHostname() (string, error) + Password(string) (string, error) + AuthToken() (string, error) + Confirm(string, bool) (bool, error) + MarkdownEditor(string, string, bool) (string, error) +} + func NewPrompter(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter { return &surveyPrompter{ editorCmd: editorCmd, diff --git a/pkg/cmdutil/prompter_mock.go b/internal/prompter/prompter_mock.go similarity index 99% rename from pkg/cmdutil/prompter_mock.go rename to internal/prompter/prompter_mock.go index e2fcd339e..eea5393b2 100644 --- a/pkg/cmdutil/prompter_mock.go +++ b/internal/prompter/prompter_mock.go @@ -1,7 +1,7 @@ // Code generated by moq; DO NOT EDIT. // github.com/matryer/moq -package cmdutil +package prompter import ( "sync" diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 937b72a2e..06cdb59a9 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -9,6 +9,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/auth/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -19,7 +20,7 @@ type LoginOptions struct { IO *iostreams.IOStreams Config func() (config.Config, error) HttpClient func() (*http.Client, error) - Prompter cmdutil.Prompter + Prompter prompter.Prompter MainExecutable string diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 28bac297b..c05d9b9de 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/internal/config" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -364,7 +365,7 @@ func Test_loginRun_Survey(t *testing.T) { name string opts *LoginOptions httpStubs func(*httpmock.Registry) - prompterStubs func(*cmdutil.PrompterMock) + prompterStubs func(*prompter.PrompterMock) runStubs func(*run.CommandStubber) wantHosts string wantErrOut *regexp.Regexp @@ -383,7 +384,7 @@ func Test_loginRun_Survey(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org")) }, - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(_, _ string, _ []string) (int, error) { return 0, nil } @@ -403,7 +404,7 @@ func Test_loginRun_Survey(t *testing.T) { user: jillv git_protocol: https `), - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { switch prompt { case "What is your preferred protocol for Git operations?": @@ -437,7 +438,7 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { switch prompt { case "What account do you want to log into?": @@ -476,7 +477,7 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { switch prompt { case "What account do you want to log into?": @@ -506,7 +507,7 @@ func Test_loginRun_Survey(t *testing.T) { opts: &LoginOptions{ Interactive: true, }, - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { switch prompt { case "What account do you want to log into?": @@ -560,7 +561,7 @@ func Test_loginRun_Survey(t *testing.T) { httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`)) } - pm := &cmdutil.PrompterMock{} + pm := &prompter.PrompterMock{} pm.ConfirmFunc = func(_ string, _ bool) (bool, error) { return false, nil } diff --git a/pkg/cmd/auth/shared/git_credential.go b/pkg/cmd/auth/shared/git_credential.go index 22a68da6b..e6cbe3c29 100644 --- a/pkg/cmd/auth/shared/git_credential.go +++ b/pkg/cmd/auth/shared/git_credential.go @@ -10,14 +10,14 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/git" "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" - "github.com/cli/cli/v2/pkg/cmdutil" "github.com/google/shlex" ) type GitCredentialFlow struct { Executable string - Prompter cmdutil.Prompter + Prompter prompter.Prompter shouldSetup bool helper string diff --git a/pkg/cmd/auth/shared/login_flow.go b/pkg/cmd/auth/shared/login_flow.go index 590fb242d..373cc299d 100644 --- a/pkg/cmd/auth/shared/login_flow.go +++ b/pkg/cmd/auth/shared/login_flow.go @@ -10,8 +10,8 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/authflow" "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/ssh-key/add" - "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/ssh" ) @@ -34,7 +34,7 @@ type LoginOptions struct { Scopes []string Executable string GitProtocol string - Prompter cmdutil.Prompter + Prompter prompter.Prompter sshContext ssh.Context } diff --git a/pkg/cmd/auth/shared/login_flow_test.go b/pkg/cmd/auth/shared/login_flow_test.go index 27db56bad..8bcecfc6a 100644 --- a/pkg/cmd/auth/shared/login_flow_test.go +++ b/pkg/cmd/auth/shared/login_flow_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/internal/run" - "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/ssh" @@ -47,7 +47,7 @@ func TestLogin_ssh(t *testing.T) { httpmock.REST("POST", "api/v3/user/keys"), httpmock.StringResponse(`{}`)) - pm := &cmdutil.PrompterMock{} + pm := &prompter.PrompterMock{} pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { switch prompt { case "What is your preferred protocol for Git operations?": diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index 6d1090d5c..8cdb45d45 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -12,6 +12,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/httpmock" @@ -30,7 +31,7 @@ func TestNewCmdExtension(t *testing.T) { name string args []string managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T) - prompterStubs func(pm *cmdutil.PrompterMock) + prompterStubs func(pm *prompter.PrompterMock) isTTY bool wantErr bool errMsg string @@ -386,7 +387,7 @@ func TestNewCmdExtension(t *testing.T) { } }, isTTY: true, - prompterStubs: func(pm *cmdutil.PrompterMock) { + prompterStubs: func(pm *prompter.PrompterMock) { pm.InputFunc = func(prompt, defVal string) (string, error) { if prompt == "Extension name:" { return "test", nil @@ -566,7 +567,7 @@ func TestNewCmdExtension(t *testing.T) { assertFunc = tt.managerStubs(em) } - pm := &cmdutil.PrompterMock{} + pm := &prompter.PrompterMock{} if tt.prompterStubs != nil { tt.prompterStubs(pm) } diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index 8c0cd06b9..5cfa82701 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.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/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/extension" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -31,7 +32,7 @@ func New(appVersion string) *cmdutil.Factory { f.HttpClient = httpClientFunc(f, appVersion) // Depends on Config, IOStreams, and appVersion f.Remotes = remotesFunc(f) // Depends on Config f.BaseRepo = BaseRepoFunc(f) // Depends on Remotes - f.Prompter = prompter(f) // Depends on Config and IOStreams + f.Prompter = newPrompter(f) // Depends on Config and IOStreams f.Browser = browser(f) // Depends on Config, and IOStreams f.ExtensionManager = extensionManager(f) // Depends on Config, HttpClient, and IOStreams @@ -108,10 +109,10 @@ func browser(f *cmdutil.Factory) cmdutil.Browser { return cmdutil.NewBrowser(browserLauncher(f), io.Out, io.ErrOut) } -func prompter(f *cmdutil.Factory) cmdutil.Prompter { +func newPrompter(f *cmdutil.Factory) prompter.Prompter { editor, _ := cmdutil.DetermineEditor(f.Config) io := f.IOStreams - return cmdutil.NewPrompter(editor, io.In, io.Out, io.ErrOut) + return prompter.NewPrompter(editor, io.In, io.Out, io.ErrOut) } // Browser precedence diff --git a/pkg/cmd/pr/review/review.go b/pkg/cmd/pr/review/review.go index 7549fe921..0d65cffa2 100644 --- a/pkg/cmd/pr/review/review.go +++ b/pkg/cmd/pr/review/review.go @@ -8,6 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/pr/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -19,7 +20,7 @@ type ReviewOptions struct { HttpClient func() (*http.Client, error) Config func() (config.Config, error) IO *iostreams.IOStreams - Prompter cmdutil.Prompter + Prompter prompter.Prompter Finder shared.PRFinder diff --git a/pkg/cmd/pr/review/review_test.go b/pkg/cmd/pr/review/review_test.go index ab41af9fb..9d1ad6ff9 100644 --- a/pkg/cmd/pr/review/review_test.go +++ b/pkg/cmd/pr/review/review_test.go @@ -14,6 +14,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/pr/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/httpmock" @@ -165,7 +166,7 @@ func Test_NewCmdReview(t *testing.T) { } } -func runCommand(rt http.RoundTripper, prompter cmdutil.Prompter, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) { +func runCommand(rt http.RoundTripper, prompter prompter.Prompter, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) { ios, _, stdout, stderr := iostreams.Test() ios.SetStdoutTTY(isTTY) ios.SetStdinTTY(isTTY) @@ -271,7 +272,7 @@ func TestPRReview_interactive(t *testing.T) { }), ) - pm := &cmdutil.PrompterMock{ + pm := &prompter.PrompterMock{ SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil }, MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "cool story", nil }, ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil }, @@ -294,7 +295,7 @@ func TestPRReview_interactive_no_body(t *testing.T) { shared.RunCommandFinder("", &api.PullRequest{ID: "THE-ID", Number: 123}, ghrepo.New("OWNER", "REPO")) - pm := &cmdutil.PrompterMock{ + pm := &prompter.PrompterMock{ SelectFunc: func(_, _ string, _ []string) (int, error) { return 2, nil }, MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "", nil }, } @@ -318,7 +319,7 @@ func TestPRReview_interactive_blank_approve(t *testing.T) { }), ) - pm := &cmdutil.PrompterMock{ + pm := &prompter.PrompterMock{ SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil }, MarkdownEditorFunc: func(_, defVal string, _ bool) (string, error) { return defVal, nil }, ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil }, diff --git a/pkg/cmd/repo/delete/delete.go b/pkg/cmd/repo/delete/delete.go index 34e58780c..9e1d6d1d8 100644 --- a/pkg/cmd/repo/delete/delete.go +++ b/pkg/cmd/repo/delete/delete.go @@ -8,6 +8,7 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" @@ -17,7 +18,7 @@ import ( type DeleteOptions struct { HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) - Prompter cmdutil.Prompter + Prompter prompter.Prompter IO *iostreams.IOStreams RepoArg string Confirmed bool diff --git a/pkg/cmd/repo/delete/delete_test.go b/pkg/cmd/repo/delete/delete_test.go index 7dc443aac..a49bbff4f 100644 --- a/pkg/cmd/repo/delete/delete_test.go +++ b/pkg/cmd/repo/delete/delete_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "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_deleteRun(t *testing.T) { tty bool opts *DeleteOptions httpStubs func(*httpmock.Registry) - prompterStubs func(*cmdutil.PrompterMock) + prompterStubs func(*prompter.PrompterMock) wantStdout string wantErr bool errMsg string @@ -90,7 +91,7 @@ func Test_deleteRun(t *testing.T) { tty: true, opts: &DeleteOptions{RepoArg: "OWNER/REPO"}, wantStdout: "✓ Deleted repository OWNER/REPO\n", - prompterStubs: func(p *cmdutil.PrompterMock) { + prompterStubs: func(p *prompter.PrompterMock) { p.InputFunc = func(_, _ string) (string, error) { return "OWNER/REPO", nil } @@ -106,7 +107,7 @@ func Test_deleteRun(t *testing.T) { tty: true, opts: &DeleteOptions{}, wantStdout: "✓ Deleted repository OWNER/REPO\n", - prompterStubs: func(p *cmdutil.PrompterMock) { + prompterStubs: func(p *prompter.PrompterMock) { p.InputFunc = func(_, _ string) (string, error) { return "OWNER/REPO", nil } @@ -134,7 +135,7 @@ func Test_deleteRun(t *testing.T) { opts: &DeleteOptions{RepoArg: "REPO"}, wantStdout: "✓ Deleted repository OWNER/REPO\n", tty: true, - prompterStubs: func(p *cmdutil.PrompterMock) { + prompterStubs: func(p *prompter.PrompterMock) { p.InputFunc = func(_, _ string) (string, error) { return "OWNER/REPO", nil } @@ -150,7 +151,7 @@ func Test_deleteRun(t *testing.T) { }, } for _, tt := range tests { - pm := &cmdutil.PrompterMock{} + pm := &prompter.PrompterMock{} if tt.prompterStubs != nil { tt.prompterStubs(pm) } diff --git a/pkg/cmdutil/factory.go b/pkg/cmdutil/factory.go index bace0dfd6..3f3f0de0e 100644 --- a/pkg/cmdutil/factory.go +++ b/pkg/cmdutil/factory.go @@ -9,6 +9,7 @@ import ( "github.com/cli/cli/v2/context" "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/iostreams" ) @@ -17,25 +18,10 @@ type Browser interface { Browse(string) error } -// TODO fix current breaking tests -// TODO linter warning for using the prompt package - -//go:generate moq -rm -out prompter_mock.go . Prompter -type Prompter interface { - Select(string, string, []string) (int, error) - MultiSelect(string, string, []string) (int, error) - Input(string, string) (string, error) - InputHostname() (string, error) - Password(string) (string, error) - AuthToken() (string, error) - Confirm(string, bool) (bool, error) - MarkdownEditor(string, string, bool) (string, error) -} - type Factory struct { IOStreams *iostreams.IOStreams Browser Browser - Prompter Prompter + Prompter prompter.Prompter HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) From e1238015f5440d2abbfcc1506ac3fdaeb9875d4f Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 26 Jul 2022 16:45:28 -0500 Subject: [PATCH 5/9] linter appeasement --- pkg/cmd/auth/shared/login_flow.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/auth/shared/login_flow.go b/pkg/cmd/auth/shared/login_flow.go index 373cc299d..10a371872 100644 --- a/pkg/cmd/auth/shared/login_flow.go +++ b/pkg/cmd/auth/shared/login_flow.go @@ -99,7 +99,9 @@ func Login(opts *LoginOptions) error { if sshChoice { passphrase, err := opts.Prompter.Password( "Enter a passphrase for your new SSH key (Optional)") - + if err != nil { + return err + } keyPair, err := opts.sshContext.GenerateSSHKey("id_ed25519", passphrase) if err != nil { return err From d5334f4115149d0de5817379152f71aa18401209 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 27 Jul 2022 13:30:41 -0500 Subject: [PATCH 6/9] Revert "update linter checks" This reverts commit 40ecb8c18825297871310dd9ce9304474a23d26f. --- pkg/cmd/auth/logout/logout_test.go | 1 - pkg/cmd/auth/refresh/refresh_test.go | 1 - pkg/cmd/gist/edit/edit_test.go | 4 -- pkg/cmd/gist/view/view_test.go | 3 -- pkg/cmd/issue/create/create_test.go | 8 ---- pkg/cmd/issue/delete/delete_test.go | 2 - pkg/cmd/label/delete_test.go | 1 - pkg/cmd/pr/create/create_test.go | 30 ++++-------- pkg/cmd/pr/merge/merge_test.go | 19 -------- pkg/cmd/pr/shared/survey_test.go | 12 ++--- pkg/cmd/pr/shared/templates_test.go | 2 - pkg/cmd/release/create/create_test.go | 27 ----------- pkg/cmd/repo/archive/archive_test.go | 6 +-- pkg/cmd/repo/create/create_test.go | 60 ++++++++++++------------ pkg/cmd/repo/edit/edit_test.go | 10 ---- pkg/cmd/repo/fork/fork_test.go | 12 ++--- pkg/cmd/repo/rename/rename_test.go | 10 ++-- pkg/cmd/run/cancel/cancel_test.go | 4 +- pkg/cmd/run/rerun/rerun_test.go | 4 +- pkg/cmd/run/view/view_test.go | 28 +++++------ pkg/cmd/run/watch/watch_test.go | 2 - pkg/cmd/secret/set/set_test.go | 1 - pkg/cmd/workflow/disable/disable_test.go | 2 - pkg/cmd/workflow/enable/enable_test.go | 2 - pkg/cmd/workflow/run/run_test.go | 4 -- pkg/prompt/stubber.go | 11 ++--- 26 files changed, 79 insertions(+), 187 deletions(-) diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index 7ccb4bd48..aa176f9f0 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -106,7 +106,6 @@ func Test_logoutRun_tty(t *testing.T) { cfgHosts: []string{"cheryl.mason", "github.com"}, wantHosts: "cheryl.mason:\n oauth_token: abc123\n", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What account do you want to log out of?").AnswerWith("github.com") }, wantErrOut: regexp.MustCompile(`Logged out of github.com account 'cybilb'`), diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 7267ced0f..3de01897f 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -194,7 +194,6 @@ func Test_refreshRun(t *testing.T) { Hostname: "", }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What account do you want to refresh auth for?").AnswerWith("github.com") }, wantAuthArgs: authArgs{ diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index 0957ebddb..7318f26f8 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -162,9 +162,7 @@ func Test_editRun(t *testing.T) { { name: "multiple files, submit", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Edit which file?").AnswerWith("unix.md") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What next?").AnswerWith("Submit") }, gist: &shared.Gist{ @@ -209,9 +207,7 @@ func Test_editRun(t *testing.T) { { name: "multiple files, cancel", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Edit which file?").AnswerWith("unix.md") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What next?").AnswerWith("Cancel") }, wantErr: "CancelError", diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 58fb1ee7f..42ec91fef 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -356,7 +356,6 @@ func Test_viewRun(t *testing.T) { ) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerDefault() } @@ -402,7 +401,6 @@ func Test_promptGists(t *testing.T) { { name: "multiple files, select first gist", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerWith("cool.txt about 6 hours ago") }, response: `{ "data": { "viewer": { "gists": { "nodes": [ @@ -426,7 +424,6 @@ func Test_promptGists(t *testing.T) { { name: "multiple files, select second gist", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a gist").AnswerWith("gistfile0.txt about 6 hours ago") }, response: `{ "data": { "viewer": { "gists": { "nodes": [ diff --git a/pkg/cmd/issue/create/create_test.go b/pkg/cmd/issue/create/create_test.go index b2ebbd69b..ae98535c5 100644 --- a/pkg/cmd/issue/create/create_test.go +++ b/pkg/cmd/issue/create/create_test.go @@ -404,11 +404,8 @@ func TestIssueCreate_recover(t *testing.T) { as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*") @@ -474,11 +471,8 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) { as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template").AnswerWith("Submit a request") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Continue in browser", "Cancel"}). AnswerWith("Submit") @@ -507,9 +501,7 @@ func TestIssueCreate_continueInBrowser(t *testing.T) { as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerWith("hello") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Continue in browser") _, cmdTeardown := run.Stub() diff --git a/pkg/cmd/issue/delete/delete_test.go b/pkg/cmd/issue/delete/delete_test.go index 2a2837c47..2cf323e56 100644 --- a/pkg/cmd/issue/delete/delete_test.go +++ b/pkg/cmd/issue/delete/delete_test.go @@ -77,7 +77,6 @@ func TestIssueDelete(t *testing.T) { ) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("13") output, err := runCommand(httpRegistry, true, "13") @@ -138,7 +137,6 @@ func TestIssueDelete_cancel(t *testing.T) { ) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("14") output, err := runCommand(httpRegistry, true, "13") diff --git a/pkg/cmd/label/delete_test.go b/pkg/cmd/label/delete_test.go index 918e12c76..48fba81c5 100644 --- a/pkg/cmd/label/delete_test.go +++ b/pkg/cmd/label/delete_test.go @@ -105,7 +105,6 @@ func TestDeleteRun(t *testing.T) { askStubs: func(as *prompt.AskStubber) { // TODO: survey stubber doesn't have WithValidator support // so this always passes regardless of prompt input - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Type test to confirm deletion:").AnswerWith("test") }, wantStdout: "✓ Label \"test\" deleted from OWNER/REPO\n", diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index e4710d546..33feafa40 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -311,15 +311,12 @@ func TestPRCreate_recover(t *testing.T) { cs.Register(`git status --porcelain`, 0, "") cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, teardown := prompt.InitAskStubber() defer teardown() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerDefault() tmpfile, err := os.CreateTemp(t.TempDir(), "testrecover*") @@ -412,11 +409,10 @@ func TestPRCreate(t *testing.T) { cs.Register(`git show-ref --verify -- HEAD refs/remotes/origin/feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body"`) @@ -460,11 +456,10 @@ func TestPRCreate_NoMaintainerModify(t *testing.T) { cs.Register(`git show-ref --verify -- HEAD refs/remotes/origin/feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `-t "my title" -b "my body" --no-maintainer-edit`) @@ -513,11 +508,10 @@ func TestPRCreate_createFork(t *testing.T) { cs.Register(`git remote add -f fork https://github.com/monalisa/REPO.git`, 0, "") cs.Register(`git push --set-upstream fork HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?"). AssertOptions([]string{"OWNER/REPO", "Create a fork of OWNER/REPO", "Skip pushing the branch", "Cancel"}). AnswerWith("Create a fork of OWNER/REPO") @@ -574,7 +568,7 @@ func TestPRCreate_pushedToNonBaseRepo(t *testing.T) { deadbeef refs/remotes/origin/feature `)) // determineTrackingBranch - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber _, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() @@ -616,7 +610,7 @@ func TestPRCreate_pushedToDifferentBranchName(t *testing.T) { deadbeef refs/remotes/origin/my-feat2 `)) // determineTrackingBranch - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber _, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() @@ -662,13 +656,10 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) { as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"template1", "template2", "Open a blank pull request"}). AnswerWith("template1") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Submit as draft", "Continue in browser", "Add metadata", "Cancel"}). AnswerDefault() @@ -810,11 +801,10 @@ func TestPRCreate_web(t *testing.T) { cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?"). AssertOptions([]string{"OWNER/REPO", "Skip pushing the branch", "Cancel"}). AnswerDefault() @@ -886,11 +876,10 @@ func TestPRCreate_webProject(t *testing.T) { cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "") cs.Register(`git push --set-upstream origin HEAD:feature`, 0, "") - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber ask, cleanupAsk := prompt.InitAskStubber() defer cleanupAsk() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock ask.StubPrompt("Where should we push the 'feature' branch?").AnswerDefault() output, err := runCommand(http, nil, "feature", true, `--web -p Triage`) @@ -929,11 +918,8 @@ func TestPRCreate_draft(t *testing.T) { as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Body").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?"). AssertOptions([]string{"Submit", "Submit as draft", "Continue in browser", "Add metadata", "Cancel"}). AnswerWith("Submit as draft") diff --git a/pkg/cmd/pr/merge/merge_test.go b/pkg/cmd/pr/merge/merge_test.go index 591cf450c..4afa03ab4 100644 --- a/pkg/cmd/pr/merge/merge_test.go +++ b/pkg/cmd/pr/merge/merge_test.go @@ -961,7 +961,6 @@ func TestPrMerge_alreadyMerged(t *testing.T) { cs.Register(`git pull --ff-only`, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) output, err := runCommand(http, "blueberries", true, "pr merge 4") @@ -1023,7 +1022,6 @@ func TestPrMerge_alreadyMerged_withMergeStrategy_TTY(t *testing.T) { cs.Register(`git branch -D `, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) output, err := runCommand(http, "blueberries", true, "pr merge 4 --merge") @@ -1103,11 +1101,8 @@ func TestPRMergeTTY(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") output, err := runCommand(http, "blueberries", true, "") @@ -1167,9 +1162,7 @@ func TestPRMergeTTY_withDeleteBranch(t *testing.T) { cs.Register(`git pull --ff-only`, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") output, err := runCommand(http, "blueberries", true, "-d") @@ -1228,15 +1221,10 @@ func TestPRMergeTTY_squashEditCommitMsgAndSubject(t *testing.T) { defer cmdTeardown(t) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerWith("Squash and merge") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch on GitHub?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Edit commit message") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Edit commit subject") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Submit") err := mergeRun(&MergeOptions{ @@ -1311,11 +1299,8 @@ func TestPRTTY_cancelled(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerWith("Cancel") output, err := runCommand(http, "blueberries", true, "") @@ -1333,7 +1318,6 @@ func Test_mergeMethodSurvey(t *testing.T) { SquashMergeAllowed: true, } as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerWith("Rebase and merge") method, err := mergeMethodSurvey(repo) @@ -1641,11 +1625,8 @@ func TestPrAddToMergeQueueAdmin(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What merge method would you like to use?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What's next?").AnswerDefault() output, err := runCommand(http, "blueberries", true, "pr merge 1 --admin") diff --git a/pkg/cmd/pr/shared/survey_test.go b/pkg/cmd/pr/shared/survey_test.go index d25858435..0bc27e8d6 100644 --- a/pkg/cmd/pr/shared/survey_test.go +++ b/pkg/cmd/pr/shared/survey_test.go @@ -43,18 +43,18 @@ func TestMetadataSurvey_selectAll(t *testing.T) { }, } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, restoreAsk := prompt.InitAskStubber() defer restoreAsk() - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ { Name: "metadata", Value: []string{"Labels", "Projects", "Assignees", "Reviewers", "Milestone"}, }, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ { Name: "reviewers", @@ -112,18 +112,18 @@ func TestMetadataSurvey_keepExisting(t *testing.T) { }, } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, restoreAsk := prompt.InitAskStubber() defer restoreAsk() - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ { Name: "metadata", Value: []string{"Labels", "Projects"}, }, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ { Name: "labels", diff --git a/pkg/cmd/pr/shared/templates_test.go b/pkg/cmd/pr/shared/templates_test.go index 12335b61a..752de47c1 100644 --- a/pkg/cmd/pr/shared/templates_test.go +++ b/pkg/cmd/pr/shared/templates_test.go @@ -48,7 +48,6 @@ func TestTemplateManager_hasAPI(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"Bug report", "Feature request", "Open a blank issue"}). AnswerWith("Feature request") @@ -95,7 +94,6 @@ func TestTemplateManager_hasAPI_PullRequest(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a template"). AssertOptions([]string{"bug_pr.md", "feature_pr.md", "Open a blank pull request"}). AnswerWith("bug_pr.md") diff --git a/pkg/cmd/release/create/create_test.go b/pkg/cmd/release/create/create_test.go index c3ab9cdd3..b4a95e1e6 100644 --- a/pkg/cmd/release/create/create_test.go +++ b/pkg/cmd/release/create/create_test.go @@ -597,19 +597,14 @@ func Test_createRun_interactive(t *testing.T) { name: "create a release from existing tag", opts: &CreateOptions{}, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a tag"). AssertOptions([]string{"v1.2.3", "v1.2.2", "v1.0.0", "v0.1.2", "Create a new tag"}). AnswerWith("v1.2.3") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Leave blank") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?"). AssertOptions([]string{"Publish release", "Save as draft", "Cancel"}).AnswerWith("Publish release") }, @@ -637,19 +632,13 @@ func Test_createRun_interactive(t *testing.T) { name: "create a release from new tag", opts: &CreateOptions{}, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Choose a tag").AnswerWith("Create a new tag") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Tag name").AnswerWith("v1.2.3") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Leave blank") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -678,15 +667,11 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Leave blank"}). AnswerWith("Write using generated notes as template") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -720,15 +705,11 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using commit log as template", "Leave blank"}). AnswerWith("Write using commit log as template") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -760,15 +741,11 @@ func Test_createRun_interactive(t *testing.T) { TagName: "v1.2.3", }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using git tag message as template", "Leave blank"}). AnswerWith("Write using git tag message as template") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { @@ -816,15 +793,11 @@ func Test_createRun_interactive(t *testing.T) { Target: "main", }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Title (optional)").AnswerWith("") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Release notes"). AssertOptions([]string{"Write my own", "Write using generated notes as template", "Write using git tag message as template", "Leave blank"}). AnswerWith("Leave blank") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Is this a prerelease?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Submit?").AnswerWith("Publish release") }, runStubs: func(rs *run.CommandStubber) { diff --git a/pkg/cmd/repo/archive/archive_test.go b/pkg/cmd/repo/archive/archive_test.go index 788ec2a8f..6d681e784 100644 --- a/pkg/cmd/repo/archive/archive_test.go +++ b/pkg/cmd/repo/archive/archive_test.go @@ -80,7 +80,7 @@ func Test_ArchiveRun(t *testing.T) { name: "unarchived repo tty", wantStdout: "✓ Archived repository OWNER/REPO\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne(true) }, isTTY: true, @@ -99,7 +99,7 @@ func Test_ArchiveRun(t *testing.T) { wantStdout: "✓ Archived repository OWNER/REPO\n", opts: ArchiveOptions{}, askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne(true) }, isTTY: true, @@ -140,7 +140,7 @@ func Test_ArchiveRun(t *testing.T) { ios, _, stdout, stderr := iostreams.Test() tt.opts.IO = ios - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/create/create_test.go b/pkg/cmd/repo/create/create_test.go index 074f0b2df..75dd3a0d1 100644 --- a/pkg/cmd/repo/create/create_test.go +++ b/pkg/cmd/repo/create/create_test.go @@ -187,30 +187,30 @@ func Test_createRun(t *testing.T) { tty: true, wantStdout: "✓ Created repository OWNER/REPO on GitHub\n", askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("Create a new repository on GitHub from scratch") - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "addGitIgnore", Value: true}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "chooseGitIgnore", Value: "Go"}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "addLicense", Value: true}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "chooseLicense", Value: "GNU Lesser General Public License v3.0"}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "confirmSubmit", Value: true}}) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) //clone locally? }, httpStubs: func(reg *httpmock.Registry) { @@ -234,21 +234,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("Create a new repository on GitHub from scratch") - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "addGitIgnore", Value: false}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "addLicense", Value: false}}) - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "confirmSubmit", Value: false}}) }, @@ -261,17 +261,17 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(false) }, httpStubs: func(reg *httpmock.Registry) { @@ -302,21 +302,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) //ask for adding a remote - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("origin") //ask for remote name - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(false) //ask to push to remote }, httpStubs: func(reg *httpmock.Registry) { @@ -348,21 +348,21 @@ func Test_createRun(t *testing.T) { opts: &CreateOptions{Interactive: true}, tty: true, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("Push an existing local repository to GitHub") - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(".") - //nolint:staticcheck // SA1019: as.Stub is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.Stub is deprecated: use StubPrompt as.Stub([]*prompt.QuestionStub{ {Name: "repoName", Value: "REPO"}, {Name: "repoDescription", Value: "my new repo"}, {Name: "repoVisibility", Value: "Private"}, }) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) //ask for adding a remote - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne("origin") //ask for remote name - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) //ask to push to remote }, httpStubs: func(reg *httpmock.Registry) { @@ -452,7 +452,7 @@ func Test_createRun(t *testing.T) { }, } for _, tt := range tests { - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index 769846972..dc4198581 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -173,9 +173,7 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Description"}) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Description of the repository").AnswerWith("awesome repo description") }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { @@ -215,13 +213,9 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Description", "Topics"}) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Description of the repository").AnswerWith("awesome repo description") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Add topics?(csv format)").AnswerWith("a, b,c,d ") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Remove Topics").AnswerWith([]string{"x"}) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { @@ -266,13 +260,9 @@ func Test_editRun_interactive(t *testing.T) { InteractiveMode: true, }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Merge Options"}) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Allowed merge strategies").AnswerWith([]string{allowMergeCommits, allowRebaseMerge}) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Enable Auto Merge?").AnswerWith(false) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Automatically delete head branches after merging?").AnswerWith(false) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index c395190a6..111eb98f6 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -272,7 +272,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(false) }, wantErrOut: "✓ Created fork someone/REPO\n", @@ -291,7 +291,7 @@ func TestRepoFork(t *testing.T) { cs.Register(`git remote add -f origin https://github.com/someone/REPO.git`, 0, "") }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) }, wantErrOut: "✓ Created fork someone/REPO\n✓ Added remote origin\n", @@ -494,7 +494,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(false) }, wantErrOut: "✓ Created fork someone/REPO\n", @@ -508,7 +508,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) }, execStubs: func(cs *run.CommandStubber) { @@ -529,7 +529,7 @@ func TestRepoFork(t *testing.T) { }, httpStubs: forkPost, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(true) }, execStubs: func(cs *run.CommandStubber) { @@ -700,7 +700,7 @@ func TestRepoFork(t *testing.T) { return tt.remotes, nil } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/repo/rename/rename_test.go b/pkg/cmd/repo/rename/rename_test.go index f536f2ab0..97e1aebb7 100644 --- a/pkg/cmd/repo/rename/rename_test.go +++ b/pkg/cmd/repo/rename/rename_test.go @@ -117,7 +117,7 @@ func TestRenameRun(t *testing.T) { name: "none argument", wantOut: "✓ Renamed repository OWNER/NEW_REPO\n✓ Updated the \"origin\" remote\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne("NEW_REPO") }, httpStubs: func(reg *httpmock.Registry) { @@ -137,7 +137,7 @@ func TestRenameRun(t *testing.T) { }, wantOut: "✓ Renamed repository OWNER/NEW_REPO\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne("NEW_REPO") }, httpStubs: func(reg *httpmock.Registry) { @@ -186,7 +186,7 @@ func TestRenameRun(t *testing.T) { }, wantOut: "✓ Renamed repository OWNER/NEW_REPO\n✓ Updated the \"origin\" remote\n", askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne(true) }, httpStubs: func(reg *httpmock.Registry) { @@ -207,7 +207,7 @@ func TestRenameRun(t *testing.T) { DoConfirm: true, }, askStubs: func(q *prompt.AskStubber) { - //nolint:staticcheck // SA1019: q.StubOne is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: q.StubOne is deprecated: use StubPrompt q.StubOne(false) }, wantOut: "", @@ -215,7 +215,7 @@ func TestRenameRun(t *testing.T) { } for _, tt := range testCases { - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber q, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/cancel/cancel_test.go b/pkg/cmd/run/cancel/cancel_test.go index a66e58552..4875918d7 100644 --- a/pkg/cmd/run/cancel/cancel_test.go +++ b/pkg/cmd/run/cancel/cancel_test.go @@ -174,7 +174,7 @@ func TestRunCancel(t *testing.T) { httpmock.StatusStringResponse(202, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(0) }, wantOut: "✓ Request to cancel workflow submitted.\n", @@ -196,7 +196,7 @@ func TestRunCancel(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/rerun/rerun_test.go b/pkg/cmd/run/rerun/rerun_test.go index 0bce30edb..5d9dd3dc0 100644 --- a/pkg/cmd/run/rerun/rerun_test.go +++ b/pkg/cmd/run/rerun/rerun_test.go @@ -294,7 +294,7 @@ func TestRerun(t *testing.T) { httpmock.StringResponse("{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) }, wantOut: "✓ Requested rerun of run 1234\n", @@ -351,7 +351,7 @@ func TestRerun(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index b61f9ec35..c2a9e51c9 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -374,7 +374,7 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse([]shared.Annotation{})) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) }, opts: &ViewOptions{ @@ -411,9 +411,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(1) }, wantOut: coolJobRunLogOutput, @@ -466,9 +466,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(0) }, wantOut: expectedRunLogOutput, @@ -527,9 +527,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(4) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) }, wantOut: quuxTheBarfLogOutput, @@ -582,9 +582,9 @@ func TestViewRun(t *testing.T) { httpmock.FileResponse("./fixtures/run_log.zip")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(4) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(0) }, wantOut: quuxTheBarfLogOutput, @@ -708,9 +708,9 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse(shared.FailedJobAnnotations)) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(0) }, wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n\nFor more information about a job, try: gh run view --job=\nView this run on GitHub: https://github.com/runs/3\n", @@ -743,9 +743,9 @@ func TestViewRun(t *testing.T) { httpmock.JSONResponse([]shared.Annotation{})) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(2) - //nolint:staticcheck // SA1019: as.StubOne is deprecated; use PrompterMock + //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt as.StubOne(1) }, wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\nTo see the full job log, try: gh run view --log --job=10\nView this run on GitHub: https://github.com/runs/3\n", @@ -842,7 +842,7 @@ func TestViewRun(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use PrompterMock + //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber as, teardown := prompt.InitAskStubber() defer teardown() if tt.askStubs != nil { diff --git a/pkg/cmd/run/watch/watch_test.go b/pkg/cmd/run/watch/watch_test.go index 80105c48d..bdb08a58d 100644 --- a/pkg/cmd/run/watch/watch_test.go +++ b/pkg/cmd/run/watch/watch_test.go @@ -230,7 +230,6 @@ func TestWatchRun(t *testing.T) { }, httpStubs: successfulRunStubs, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow run"). AssertOptions([]string{"* cool commit, run (trunk) Feb 23, 2021", "* cool commit, more runs (trunk) Feb 23, 2021"}). AnswerWith("* cool commit, more runs (trunk) Feb 23, 2021") @@ -247,7 +246,6 @@ func TestWatchRun(t *testing.T) { }, httpStubs: failedRunStubs, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow run"). AssertOptions([]string{"* cool commit, run (trunk) Feb 23, 2021", "* cool commit, more runs (trunk) Feb 23, 2021"}). AnswerWith("* cool commit, more runs (trunk) Feb 23, 2021") diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index 976ef4593..c9843a5a9 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -561,7 +561,6 @@ func Test_getBodyPrompt(t *testing.T) { ios.SetStdoutTTY(true) as := prompt.NewAskStubber(t) - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Paste your secret").AnswerWith("cool secret") body, err := getBody(&SetOptions{ diff --git a/pkg/cmd/workflow/disable/disable_test.go b/pkg/cmd/workflow/disable/disable_test.go index 2397b2f80..bc46212ed 100644 --- a/pkg/cmd/workflow/disable/disable_test.go +++ b/pkg/cmd/workflow/disable/disable_test.go @@ -121,7 +121,6 @@ func TestDisableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerWith("another workflow (another.yml)") }, wantOut: "✓ Disabled another workflow\n", @@ -177,7 +176,6 @@ func TestDisableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Which workflow do you mean?").AnswerWith("another workflow (yetanother.yml)") }, wantOut: "✓ Disabled another workflow\n", diff --git a/pkg/cmd/workflow/enable/enable_test.go b/pkg/cmd/workflow/enable/enable_test.go index d200fbbce..ffc679a93 100644 --- a/pkg/cmd/workflow/enable/enable_test.go +++ b/pkg/cmd/workflow/enable/enable_test.go @@ -121,7 +121,6 @@ func TestEnableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerWith("a disabled workflow (disabled.yml)") }, wantOut: "✓ Enabled a disabled workflow\n", @@ -177,7 +176,6 @@ func TestEnableRun(t *testing.T) { httpmock.StatusStringResponse(204, "{}")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Which workflow do you mean?").AnswerWith("a disabled workflow (anotherDisabled.yml)") }, wantOut: "✓ Enabled a disabled workflow\n", diff --git a/pkg/cmd/workflow/run/run_test.go b/pkg/cmd/workflow/run/run_test.go index 8622f4a24..125e3fcfb 100644 --- a/pkg/cmd/workflow/run/run_test.go +++ b/pkg/cmd/workflow/run/run_test.go @@ -558,7 +558,6 @@ jobs: httpmock.StatusStringResponse(204, "cool")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerDefault() }, wantBody: map[string]interface{}{ @@ -596,11 +595,8 @@ jobs: httpmock.StatusStringResponse(204, "cool")) }, askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("Select a workflow").AnswerDefault() - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("greeting").AnswerWith("hi") - //nolint:staticcheck // SA1019: as.StubPrompt is deprecated: use PrompterMock as.StubPrompt("name").AnswerWith("scully") }, wantBody: map[string]interface{}{ diff --git a/pkg/prompt/stubber.go b/pkg/prompt/stubber.go index 51912cd70..8d9e22520 100644 --- a/pkg/prompt/stubber.go +++ b/pkg/prompt/stubber.go @@ -18,7 +18,6 @@ type testing interface { Cleanup(func()) } -// Deprecated: use PrompterMock func NewAskStubber(t testing) *AskStubber { as, teardown := InitAskStubber() t.Cleanup(func() { @@ -32,7 +31,7 @@ func NewAskStubber(t testing) *AskStubber { return as } -// Deprecated: use PrompterMock +// Deprecated: use NewAskStubber func InitAskStubber() (*AskStubber, func()) { origSurveyAsk := SurveyAsk origSurveyAskOne := SurveyAskOne @@ -158,38 +157,34 @@ type QuestionStub struct { } // AssertOptions asserts the options presented to the user in Selects and MultiSelects. -// Deprecated: use PrompterMock func (s *QuestionStub) AssertOptions(opts []string) *QuestionStub { s.options = opts return s } // AnswerWith defines an answer for the given stub. -// Deprecated: use PrompterMock func (s *QuestionStub) AnswerWith(v interface{}) *QuestionStub { s.Value = v return s } // AnswerDefault marks the current stub to be answered with the default value for the prompt question. -// Deprecated: use PrompterMock func (s *QuestionStub) AnswerDefault() *QuestionStub { s.Default = true return s } -// Deprecated: use PrompterMock +// Deprecated: use StubPrompt func (as *AskStubber) StubOne(value interface{}) { as.Stub([]*QuestionStub{{Value: value}}) } -// Deprecated: use PrompterMock +// Deprecated: use StubPrompt func (as *AskStubber) Stub(stubbedQuestions []*QuestionStub) { as.stubs = append(as.stubs, stubbedQuestions...) } // StubPrompt records a stub for an interactive prompt matched by its message. -// Deprecated: use PrompterMock func (as *AskStubber) StubPrompt(msg string) *QuestionStub { stub := &QuestionStub{message: msg} as.stubs = append(as.stubs, stub) From 41385477c3b702fb7f3b4c599abc51e968396c80 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 27 Jul 2022 14:15:27 -0500 Subject: [PATCH 7/9] fix linting --- context/context.go | 1 + pkg/cmd/auth/logout/logout.go | 1 + pkg/cmd/auth/logout/logout_test.go | 1 + pkg/cmd/auth/refresh/refresh.go | 1 + pkg/cmd/auth/refresh/refresh_test.go | 1 + pkg/cmd/gist/edit/edit.go | 2 ++ pkg/cmd/gist/edit/edit_test.go | 1 + pkg/cmd/gist/view/view.go | 1 + pkg/cmd/gist/view/view_test.go | 2 ++ pkg/cmd/issue/create/create_test.go | 3 +++ pkg/cmd/issue/delete/delete.go | 1 + pkg/cmd/issue/delete/delete_test.go | 2 ++ pkg/cmd/label/delete.go | 1 + pkg/cmd/label/delete_test.go | 1 + pkg/cmd/pr/create/create.go | 1 + pkg/cmd/pr/create/create_test.go | 2 ++ pkg/cmd/pr/merge/merge.go | 4 ++++ pkg/cmd/pr/merge/merge_test.go | 8 ++++++++ pkg/cmd/pr/shared/survey.go | 5 +++++ pkg/cmd/pr/shared/templates.go | 1 + pkg/cmd/pr/shared/templates_test.go | 2 ++ pkg/cmd/release/create/create.go | 4 ++++ pkg/cmd/release/create/create_test.go | 1 + pkg/cmd/release/delete-asset/delete_asset.go | 1 + pkg/cmd/release/delete/delete.go | 1 + pkg/cmd/repo/archive/archive.go | 1 + pkg/cmd/repo/create/create.go | 12 ++++++++++++ pkg/cmd/repo/edit/edit.go | 15 +++++++++++++++ pkg/cmd/repo/edit/edit_test.go | 1 + pkg/cmd/repo/fork/fork.go | 2 ++ pkg/cmd/repo/rename/rename.go | 2 ++ pkg/cmd/run/download/download.go | 1 + pkg/cmd/run/shared/shared.go | 1 + pkg/cmd/run/view/view.go | 1 + pkg/cmd/run/watch/watch_test.go | 1 + pkg/cmd/secret/set/set.go | 1 + pkg/cmd/secret/set/set_test.go | 1 + pkg/cmd/workflow/disable/disable_test.go | 1 + pkg/cmd/workflow/enable/enable_test.go | 1 + pkg/cmd/workflow/run/run.go | 1 + pkg/cmd/workflow/run/run_test.go | 1 + pkg/cmd/workflow/shared/shared.go | 1 + pkg/prompt/prompt.go | 4 ++++ pkg/prompt/stubber.go | 1 + 44 files changed, 98 insertions(+) diff --git a/context/context.go b/context/context.go index 40a9383a3..dc5f71a3a 100644 --- a/context/context.go +++ b/context/context.go @@ -119,6 +119,7 @@ func (r *ResolvedRemotes) BaseRepo(io *iostreams.IOStreams) (ghrepo.Interface, e // hide the spinner in case a command started the progress indicator before base repo was fully // resolved, e.g. in `gh issue view` io.StopProgressIndicator() + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: "Which should be the base repository (used for e.g. querying issues) for this directory?", Options: repoNames, diff --git a/pkg/cmd/auth/logout/logout.go b/pkg/cmd/auth/logout/logout.go index 4027fd0f8..029d5971a 100644 --- a/pkg/cmd/auth/logout/logout.go +++ b/pkg/cmd/auth/logout/logout.go @@ -79,6 +79,7 @@ func logoutRun(opts *LogoutOptions) error { if len(candidates) == 1 { hostname = candidates[0] } else { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Select{ Message: "What account do you want to log out of?", Options: candidates, diff --git a/pkg/cmd/auth/logout/logout_test.go b/pkg/cmd/auth/logout/logout_test.go index aa176f9f0..71bca8cd7 100644 --- a/pkg/cmd/auth/logout/logout_test.go +++ b/pkg/cmd/auth/logout/logout_test.go @@ -158,6 +158,7 @@ func Test_logoutRun_tty(t *testing.T) { return &http.Client{Transport: reg}, nil } + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/auth/refresh/refresh.go b/pkg/cmd/auth/refresh/refresh.go index 32d1dade4..81c6d36da 100644 --- a/pkg/cmd/auth/refresh/refresh.go +++ b/pkg/cmd/auth/refresh/refresh.go @@ -94,6 +94,7 @@ func refreshRun(opts *RefreshOptions) error { if len(candidates) == 1 { hostname = candidates[0] } else { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: "What account do you want to refresh auth for?", Options: candidates, diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 3de01897f..0cb754117 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -272,6 +272,7 @@ func Test_refreshRun(t *testing.T) { ) tt.opts.httpClient = &http.Client{Transport: httpReg} + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/gist/edit/edit.go b/pkg/cmd/gist/edit/edit.go index 47b122c27..a96b3feb7 100644 --- a/pkg/cmd/gist/edit/edit.go +++ b/pkg/cmd/gist/edit/edit.go @@ -189,6 +189,7 @@ func editRun(opts *EditOptions) error { if !opts.IO.CanPrompt() { return errors.New("unsure what file to edit; either specify --filename or run interactively") } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Select{ Message: "Edit which file?", Options: candidates, @@ -249,6 +250,7 @@ func editRun(opts *EditOptions) error { choice := "" + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Select{ Message: "What next?", Options: []string{ diff --git a/pkg/cmd/gist/edit/edit_test.go b/pkg/cmd/gist/edit/edit_test.go index 7318f26f8..33223ddee 100644 --- a/pkg/cmd/gist/edit/edit_test.go +++ b/pkg/cmd/gist/edit/edit_test.go @@ -486,6 +486,7 @@ func Test_editRun(t *testing.T) { } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/gist/view/view.go b/pkg/cmd/gist/view/view.go index 1c4e618df..014ba2bdf 100644 --- a/pkg/cmd/gist/view/view.go +++ b/pkg/cmd/gist/view/view.go @@ -246,6 +246,7 @@ func promptGists(client *http.Client, host string, cs *iostreams.ColorScheme) (g Options: opts, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(questions, &result) if err != nil { diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 42ec91fef..8dbc9a748 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -355,6 +355,7 @@ func Test_viewRun(t *testing.T) { )), ) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Select a gist").AnswerDefault() } @@ -469,6 +470,7 @@ func Test_promptGists(t *testing.T) { client := &http.Client{Transport: reg} t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/issue/create/create_test.go b/pkg/cmd/issue/create/create_test.go index ae98535c5..6d1928f0d 100644 --- a/pkg/cmd/issue/create/create_test.go +++ b/pkg/cmd/issue/create/create_test.go @@ -402,6 +402,7 @@ func TestIssueCreate_recover(t *testing.T) { assert.Equal(t, []interface{}{"BUGID", "TODOID"}, inputs["labelIds"]) })) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Title").AnswerDefault() @@ -469,6 +470,7 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) { }), ) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Choose a template").AnswerWith("Submit a request") @@ -499,6 +501,7 @@ func TestIssueCreate_continueInBrowser(t *testing.T) { } } }`), ) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Title").AnswerWith("hello") diff --git a/pkg/cmd/issue/delete/delete.go b/pkg/cmd/issue/delete/delete.go index bf62dafac..b4a8752da 100644 --- a/pkg/cmd/issue/delete/delete.go +++ b/pkg/cmd/issue/delete/delete.go @@ -79,6 +79,7 @@ func deleteRun(opts *DeleteOptions) error { // already provided. Otherwise skip confirmation. if opts.IO.CanPrompt() && !opts.Confirmed { answer := "" + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne( &survey.Input{ Message: fmt.Sprintf("You're going to delete issue #%d. This action cannot be reversed. To confirm, type the issue number:", issue.Number), diff --git a/pkg/cmd/issue/delete/delete_test.go b/pkg/cmd/issue/delete/delete_test.go index 2cf323e56..e3b2613ce 100644 --- a/pkg/cmd/issue/delete/delete_test.go +++ b/pkg/cmd/issue/delete/delete_test.go @@ -76,6 +76,7 @@ func TestIssueDelete(t *testing.T) { }), ) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("13") @@ -136,6 +137,7 @@ func TestIssueDelete_cancel(t *testing.T) { } } }`), ) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("You're going to delete issue #13. This action cannot be reversed. To confirm, type the issue number:").AnswerWith("14") diff --git a/pkg/cmd/label/delete.go b/pkg/cmd/label/delete.go index 3b5aa1ce7..3d51cf4c4 100644 --- a/pkg/cmd/label/delete.go +++ b/pkg/cmd/label/delete.go @@ -67,6 +67,7 @@ func deleteRun(opts *deleteOptions) error { if !opts.Confirmed { var valid string + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne( &survey.Input{Message: fmt.Sprintf("Type %s to confirm deletion:", opts.Name)}, &valid, diff --git a/pkg/cmd/label/delete_test.go b/pkg/cmd/label/delete_test.go index 48fba81c5..d5d0ac195 100644 --- a/pkg/cmd/label/delete_test.go +++ b/pkg/cmd/label/delete_test.go @@ -153,6 +153,7 @@ func TestDeleteRun(t *testing.T) { return &http.Client{Transport: reg}, nil } + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 9f8e34fd4..31ff9c25c 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -569,6 +569,7 @@ func NewCreateContext(opts *CreateOptions) (*CreateContext, error) { pushOptions = append(pushOptions, "Cancel") var selectedOption int + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Select{ Message: fmt.Sprintf("Where should we push the '%s' branch?", headBranch), Options: pushOptions, diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index 33feafa40..fd2c6b431 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -654,6 +654,7 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) { cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "1234567890,commit 0\n2345678901,commit 1") cs.Register(`git status --porcelain`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Choose a template"). @@ -916,6 +917,7 @@ func TestPRCreate_draft(t *testing.T) { assert.Equal(t, true, input["draft"].(bool)) })) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Choose a template").AnswerDefault() diff --git a/pkg/cmd/pr/merge/merge.go b/pkg/cmd/pr/merge/merge.go index 5d9eb5ab9..635945572 100644 --- a/pkg/cmd/pr/merge/merge.go +++ b/pkg/cmd/pr/merge/merge.go @@ -370,6 +370,7 @@ func (m *mergeContext) deleteLocalBranch() error { if m.merged { // prompt for delete if m.opts.IO.CanPrompt() && !m.opts.IsDeleteBranchIndicated { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Confirm{ Message: fmt.Sprintf("Pull request #%d was already merged. Delete the branch locally?", m.pr.Number), Default: false, @@ -571,6 +572,7 @@ func mergeMethodSurvey(baseRepo *api.Repository) (PullRequestMergeMethod, error) } var result int + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(mergeQuestion, &result) return mergeOpts[result].method, err } @@ -589,6 +591,7 @@ func deleteBranchSurvey(opts *MergeOptions, crossRepoPR, localBranchExists bool) Message: message, Default: false, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(submit, &result) return result, err } @@ -615,6 +618,7 @@ func confirmSurvey(allowEditMsg bool) (shared.Action, error) { Message: "What's next?", Options: options, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(submit, &result) if err != nil { return shared.CancelAction, fmt.Errorf("could not prompt: %w", err) diff --git a/pkg/cmd/pr/merge/merge_test.go b/pkg/cmd/pr/merge/merge_test.go index 4afa03ab4..9428fd3e6 100644 --- a/pkg/cmd/pr/merge/merge_test.go +++ b/pkg/cmd/pr/merge/merge_test.go @@ -960,6 +960,7 @@ func TestPrMerge_alreadyMerged(t *testing.T) { cs.Register(`git branch -D blueberries`, 0, "") cs.Register(`git pull --ff-only`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) @@ -1021,6 +1022,7 @@ func TestPrMerge_alreadyMerged_withMergeStrategy_TTY(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") cs.Register(`git branch -D `, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Pull request #4 was already merged. Delete the branch locally?").AnswerWith(true) @@ -1100,6 +1102,7 @@ func TestPRMergeTTY(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerDefault() as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() @@ -1161,6 +1164,7 @@ func TestPRMergeTTY_withDeleteBranch(t *testing.T) { cs.Register(`git branch -D blueberries`, 0, "") cs.Register(`git pull --ff-only`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerDefault() as.StubPrompt("What's next?").AnswerWith("Submit") @@ -1220,6 +1224,7 @@ func TestPRMergeTTY_squashEditCommitMsgAndSubject(t *testing.T) { _, cmdTeardown := run.Stub() defer cmdTeardown(t) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerWith("Squash and merge") as.StubPrompt("Delete the branch on GitHub?").AnswerDefault() @@ -1298,6 +1303,7 @@ func TestPRTTY_cancelled(t *testing.T) { cs.Register(`git rev-parse --verify refs/heads/`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerDefault() as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() @@ -1317,6 +1323,7 @@ func Test_mergeMethodSurvey(t *testing.T) { RebaseMergeAllowed: true, SquashMergeAllowed: true, } + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerWith("Rebase and merge") @@ -1624,6 +1631,7 @@ func TestPrAddToMergeQueueAdmin(t *testing.T) { defer cmdTeardown(t) cs.Register(`git rev-parse --verify refs/heads/`, 0, "") + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("What merge method would you like to use?").AnswerDefault() as.StubPrompt("Delete the branch locally and on GitHub?").AnswerDefault() diff --git a/pkg/cmd/pr/shared/survey.go b/pkg/cmd/pr/shared/survey.go index 0285e22ff..31942c6a0 100644 --- a/pkg/cmd/pr/shared/survey.go +++ b/pkg/cmd/pr/shared/survey.go @@ -71,6 +71,7 @@ func confirmSubmission(allowPreview, allowMetadata, allowDraft, isDraft bool) (A }, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(confirmQs, &confirmAnswers) if err != nil { return -1, fmt.Errorf("could not prompt: %w", err) @@ -122,6 +123,7 @@ func BodySurvey(state *IssueMetadataState, templateContent, editorCommand string }, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(qs, state) if err != nil { return err @@ -148,6 +150,7 @@ func TitleSurvey(state *IssueMetadataState) error { }, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(qs, state) if err != nil { return err @@ -197,6 +200,7 @@ func MetadataSurvey(io *iostreams.IOStreams, baseRepo ghrepo.Interface, fetcher } extraFieldsOptions = append(extraFieldsOptions, "Assignees", "Labels", "Projects", "Milestone") + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk([]*survey.Question{ { Name: "metadata", @@ -327,6 +331,7 @@ func MetadataSurvey(io *iostreams.IOStreams, baseRepo ghrepo.Interface, fetcher Milestone string }{} + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(mqs, &values) if err != nil { return fmt.Errorf("could not prompt: %w", err) diff --git a/pkg/cmd/pr/shared/templates.go b/pkg/cmd/pr/shared/templates.go index 45c8ec0a7..2eac86ab7 100644 --- a/pkg/cmd/pr/shared/templates.go +++ b/pkg/cmd/pr/shared/templates.go @@ -189,6 +189,7 @@ func (m *templateManager) Choose() (Template, error) { } var selectedOption int + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: "Choose a template", Options: append(names, blankOption), diff --git a/pkg/cmd/pr/shared/templates_test.go b/pkg/cmd/pr/shared/templates_test.go index 752de47c1..cce39ad65 100644 --- a/pkg/cmd/pr/shared/templates_test.go +++ b/pkg/cmd/pr/shared/templates_test.go @@ -47,6 +47,7 @@ func TestTemplateManager_hasAPI(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Choose a template"). AssertOptions([]string{"Bug report", "Feature request", "Open a blank issue"}). @@ -93,6 +94,7 @@ func TestTemplateManager_hasAPI_PullRequest(t *testing.T) { assert.Equal(t, "LEGACY", string(m.LegacyBody())) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Choose a template"). AssertOptions([]string{"bug_pr.md", "feature_pr.md", "Open a blank pull request"}). diff --git a/pkg/cmd/release/create/create.go b/pkg/cmd/release/create/create.go index 7af34638f..6b692fc61 100644 --- a/pkg/cmd/release/create/create.go +++ b/pkg/cmd/release/create/create.go @@ -195,6 +195,7 @@ func createRun(opts *CreateOptions) error { Options: options, Default: options[0], } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(q, &tag) if err != nil { return fmt.Errorf("could not prompt: %w", err) @@ -209,6 +210,7 @@ func createRun(opts *CreateOptions) error { q := &survey.Input{ Message: "Tag name", } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(q, &opts.TagName) if err != nil { return fmt.Errorf("could not prompt: %w", err) @@ -309,6 +311,7 @@ func createRun(opts *CreateOptions) error { }, }, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(qs, opts) if err != nil { return fmt.Errorf("could not prompt: %w", err) @@ -373,6 +376,7 @@ func createRun(opts *CreateOptions) error { }, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(qs, opts) if err != nil { return fmt.Errorf("could not prompt: %w", err) diff --git a/pkg/cmd/release/create/create_test.go b/pkg/cmd/release/create/create_test.go index b4a95e1e6..494d29ab5 100644 --- a/pkg/cmd/release/create/create_test.go +++ b/pkg/cmd/release/create/create_test.go @@ -851,6 +851,7 @@ func Test_createRun_interactive(t *testing.T) { } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/release/delete-asset/delete_asset.go b/pkg/cmd/release/delete-asset/delete_asset.go index f50659021..1309729d5 100644 --- a/pkg/cmd/release/delete-asset/delete_asset.go +++ b/pkg/cmd/release/delete-asset/delete_asset.go @@ -69,6 +69,7 @@ func deleteAssetRun(opts *DeleteAssetOptions) error { if !opts.SkipConfirm && opts.IO.CanPrompt() { var confirmed bool + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Confirm{ Message: fmt.Sprintf("Delete asset %s in release %s in %s?", opts.AssetName, release.TagName, ghrepo.FullName(baseRepo)), Default: true, diff --git a/pkg/cmd/release/delete/delete.go b/pkg/cmd/release/delete/delete.go index 944320ec2..bb0ce0083 100644 --- a/pkg/cmd/release/delete/delete.go +++ b/pkg/cmd/release/delete/delete.go @@ -69,6 +69,7 @@ func deleteRun(opts *DeleteOptions) error { if !opts.SkipConfirm && opts.IO.CanPrompt() { var confirmed bool + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Confirm{ Message: fmt.Sprintf("Delete release %s in %s?", release.TagName, ghrepo.FullName(baseRepo)), Default: true, diff --git a/pkg/cmd/repo/archive/archive.go b/pkg/cmd/repo/archive/archive.go index 2c4487af6..9e18ea1c1 100644 --- a/pkg/cmd/repo/archive/archive.go +++ b/pkg/cmd/repo/archive/archive.go @@ -115,6 +115,7 @@ func archiveRun(opts *ArchiveOptions) error { Message: fmt.Sprintf("Archive %s?", fullName), Default: false, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(p, &opts.Confirmed) if err != nil { return fmt.Errorf("failed to prompt: %w", err) diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index 241453ed1..7857d90e8 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -232,6 +232,7 @@ func createRun(opts *CreateOptions) error { "Create a new repository on GitHub from scratch", "Push an existing local repository to GitHub", } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter if err := prompt.SurveyAskOne(&survey.Select{ Message: "What would you like to do?", Options: modeOptions, @@ -353,6 +354,7 @@ func createFromScratch(opts *CreateOptions) error { Message: "Clone the new repository locally?", Default: true, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(cloneQuestion, &opts.Clone) if err != nil { return err @@ -507,6 +509,7 @@ func createFromLocal(opts *CreateOptions) error { Message: `Add a remote?`, Default: true, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(remoteQuesiton, &addRemote) if err != nil { return err @@ -520,6 +523,7 @@ func createFromLocal(opts *CreateOptions) error { Message: "What should the new remote be called?", Default: "origin", } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(pushQuestion, &baseRemote) if err != nil { return err @@ -536,6 +540,7 @@ func createFromLocal(opts *CreateOptions) error { Message: fmt.Sprintf(`Would you like to push commits from the current branch to %q?`, baseRemote), Default: true, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(pushQuestion, &opts.Push) if err != nil { return err @@ -684,6 +689,7 @@ func interactiveGitIgnore(client *http.Client, hostname string) (string, error) } addGitIgnoreSurvey = append(addGitIgnoreSurvey, addGitIgnoreQuestion) + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(addGitIgnoreSurvey, &addGitIgnore) if err != nil { return "", err @@ -706,6 +712,7 @@ func interactiveGitIgnore(client *http.Client, hostname string) (string, error) }, } gitIg = append(gitIg, gitIgnoreQuestion) + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(gitIg, &wantedIgnoreTemplate) if err != nil { return "", err @@ -730,6 +737,7 @@ func interactiveLicense(client *http.Client, hostname string) (string, error) { } addLicenseSurvey = append(addLicenseSurvey, addLicenseQuestion) + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(addLicenseSurvey, &addLicense) if err != nil { return "", err @@ -757,6 +765,7 @@ func interactiveLicense(client *http.Client, hostname string) (string, error) { }, } licenseQs = append(licenseQs, licenseQuestion) + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(licenseQs, &wantedLicense) if err != nil { return "", err @@ -794,6 +803,7 @@ func interactiveRepoInfo(defaultName string) (string, string, string, error) { RepoVisibility string }{} + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk(qs, &answer) if err != nil { return "", "", "", err @@ -808,6 +818,7 @@ func interactiveSource() (string, error) { Message: "Path to local repository", Default: "."} + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(sourcePrompt, &sourcePath) if err != nil { return "", err @@ -823,6 +834,7 @@ func confirmSubmission(repoWithOwner, visibility string) error { var answer struct { ConfirmSubmit bool } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err := prompt.SurveyAsk([]*survey.Question{{ Name: "confirmSubmit", Prompt: &survey.Confirm{ diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index 538a507db..81ebee963 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -282,6 +282,7 @@ func interactiveChoice(r *api.Repository) ([]string, error) { options = append(options, optionAllowForking) } var answers []string + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.MultiSelect{ Message: "What do you want to edit?", Options: options, @@ -301,6 +302,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { switch c { case optionDescription: opts.Edits.Description = &r.Description + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Input{ Message: "Description of the repository", Default: r.Description, @@ -310,6 +312,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionHomePageURL: opts.Edits.Homepage = &r.HomepageURL + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Input{ Message: "Repository home page URL", Default: r.HomepageURL, @@ -319,6 +322,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionTopics: var addTopics string + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Input{ Message: "Add topics?(csv format)", }, &addTopics) @@ -330,6 +334,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } if len(opts.topicsCache) > 0 { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.MultiSelect{ Message: "Remove Topics", Options: opts.topicsCache, @@ -340,6 +345,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionDefaultBranchName: opts.Edits.DefaultBranch = &r.DefaultBranchRef.Name + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Input{ Message: "Default branch name", Default: r.DefaultBranchRef.Name, @@ -349,6 +355,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionWikis: opts.Edits.EnableWiki = &r.HasWikiEnabled + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Enable Wikis?", Default: r.HasWikiEnabled, @@ -358,6 +365,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionIssues: opts.Edits.EnableIssues = &r.HasIssuesEnabled + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Enable Issues?", Default: r.HasIssuesEnabled, @@ -367,6 +375,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionProjects: opts.Edits.EnableProjects = &r.HasProjectsEnabled + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Enable Projects?", Default: r.HasProjectsEnabled, @@ -376,6 +385,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionVisibility: opts.Edits.Visibility = &r.Visibility + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Select{ Message: "Visibility", Options: []string{"public", "private", "internal"}, @@ -396,6 +406,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { if r.RebaseMergeAllowed { defaultMergeOptions = append(defaultMergeOptions, allowRebaseMerge) } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.MultiSelect{ Message: "Allowed merge strategies", Default: defaultMergeOptions, @@ -415,6 +426,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } opts.Edits.EnableAutoMerge = &r.AutoMergeAllowed + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Enable Auto Merge?", Default: r.AutoMergeAllowed, @@ -424,6 +436,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } opts.Edits.DeleteBranchOnMerge = &r.DeleteBranchOnMerge + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Automatically delete head branches after merging?", Default: r.DeleteBranchOnMerge, @@ -433,6 +446,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionTemplateRepo: opts.Edits.IsTemplate = &r.IsTemplate + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Convert into a template repository?", Default: r.IsTemplate, @@ -442,6 +456,7 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } case optionAllowForking: opts.Edits.AllowForking = &r.ForkingAllowed + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(&survey.Confirm{ Message: "Allow forking (of an organization repository)?", Default: r.ForkingAllowed, diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index dc4198581..41193b057 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -319,6 +319,7 @@ func Test_editRun_interactive(t *testing.T) { opts := &tt.opts opts.HTTPClient = &http.Client{Transport: httpReg} opts.IO = ios + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/repo/fork/fork.go b/pkg/cmd/repo/fork/fork.go index d0b0f9c7a..324f8fb1b 100644 --- a/pkg/cmd/repo/fork/fork.go +++ b/pkg/cmd/repo/fork/fork.go @@ -260,6 +260,7 @@ func forkRun(opts *ForkOptions) error { remoteDesired := opts.Remote if opts.PromptRemote { + //nolint:staticcheck // SA1019: prompt.Confirm is deprecated: use Prompter err = prompt.Confirm("Would you like to add a remote for the fork?", &remoteDesired) if err != nil { return fmt.Errorf("failed to prompt: %w", err) @@ -302,6 +303,7 @@ func forkRun(opts *ForkOptions) error { } else { cloneDesired := opts.Clone if opts.PromptClone { + //nolint:staticcheck // SA1019: prompt.Confirm is deprecated: use Prompter err = prompt.Confirm("Would you like to clone the fork?", &cloneDesired) if err != nil { return fmt.Errorf("failed to prompt: %w", err) diff --git a/pkg/cmd/repo/rename/rename.go b/pkg/cmd/repo/rename/rename.go index baf376140..0b256d1d3 100644 --- a/pkg/cmd/repo/rename/rename.go +++ b/pkg/cmd/repo/rename/rename.go @@ -89,6 +89,7 @@ func renameRun(opts *RenameOptions) error { } if newRepoName == "" { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne( &survey.Input{ Message: fmt.Sprintf("Rename %s to: ", ghrepo.FullName(currRepo)), @@ -106,6 +107,7 @@ func renameRun(opts *RenameOptions) error { Message: fmt.Sprintf("Rename %s to %s?", ghrepo.FullName(currRepo), newRepoName), Default: false, } + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err = prompt.SurveyAskOne(p, &confirmed) if err != nil { return fmt.Errorf("failed to prompt: %w", err) diff --git a/pkg/cmd/run/download/download.go b/pkg/cmd/run/download/download.go index 86e612793..25eec5d62 100644 --- a/pkg/cmd/run/download/download.go +++ b/pkg/cmd/run/download/download.go @@ -198,6 +198,7 @@ func matchAnyPattern(patterns []string, name string) bool { type surveyPrompter struct{} func (sp *surveyPrompter) Prompt(message string, options []string, result interface{}) error { + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter return prompt.SurveyAskOne(&survey.MultiSelect{ Message: message, Options: options, diff --git a/pkg/cmd/run/shared/shared.go b/pkg/cmd/run/shared/shared.go index b2b17fbb1..6eb2f3300 100644 --- a/pkg/cmd/run/shared/shared.go +++ b/pkg/cmd/run/shared/shared.go @@ -356,6 +356,7 @@ func PromptForRun(cs *iostreams.ColorScheme, runs []Run) (string, error) { // TODO consider custom filter so it's fuzzier. right now matches start anywhere in string but // become contiguous + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: "Select a workflow run", Options: candidates, diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index 03c7c017c..973a67897 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -446,6 +446,7 @@ func promptForJob(cs *iostreams.ColorScheme, jobs []shared.Job) (*shared.Job, er } var selected int + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: "View a specific job in this run?", Options: candidates, diff --git a/pkg/cmd/run/watch/watch_test.go b/pkg/cmd/run/watch/watch_test.go index bdb08a58d..cabf680ac 100644 --- a/pkg/cmd/run/watch/watch_test.go +++ b/pkg/cmd/run/watch/watch_test.go @@ -277,6 +277,7 @@ func TestWatchRun(t *testing.T) { } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/secret/set/set.go b/pkg/cmd/secret/set/set.go index 9be244772..2ba90b888 100644 --- a/pkg/cmd/secret/set/set.go +++ b/pkg/cmd/secret/set/set.go @@ -373,6 +373,7 @@ func getBody(opts *SetOptions) ([]byte, error) { if opts.IO.CanPrompt() { var bodyInput string + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Password{ Message: "Paste your secret", }, &bodyInput) diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index c9843a5a9..ee86f1d10 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -560,6 +560,7 @@ func Test_getBodyPrompt(t *testing.T) { ios.SetStdinTTY(true) ios.SetStdoutTTY(true) + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) as.StubPrompt("Paste your secret").AnswerWith("cool secret") diff --git a/pkg/cmd/workflow/disable/disable_test.go b/pkg/cmd/workflow/disable/disable_test.go index bc46212ed..82d0bba2f 100644 --- a/pkg/cmd/workflow/disable/disable_test.go +++ b/pkg/cmd/workflow/disable/disable_test.go @@ -278,6 +278,7 @@ func TestDisableRun(t *testing.T) { } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/workflow/enable/enable_test.go b/pkg/cmd/workflow/enable/enable_test.go index ffc679a93..2c3db074d 100644 --- a/pkg/cmd/workflow/enable/enable_test.go +++ b/pkg/cmd/workflow/enable/enable_test.go @@ -327,6 +327,7 @@ func TestEnableRun(t *testing.T) { } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/workflow/run/run.go b/pkg/cmd/workflow/run/run.go index 23bf632e8..847683148 100644 --- a/pkg/cmd/workflow/run/run.go +++ b/pkg/cmd/workflow/run/run.go @@ -230,6 +230,7 @@ func collectInputs(yamlContent []byte) (map[string]string, error) { inputAnswer := InputAnswer{ providedInputs: providedInputs, } + //nolint:staticcheck // SA1019: prompt.SurveyAsk is deprecated: use Prompter err = prompt.SurveyAsk(qs, &inputAnswer) if err != nil { return nil, err diff --git a/pkg/cmd/workflow/run/run_test.go b/pkg/cmd/workflow/run/run_test.go index 125e3fcfb..42fc6e962 100644 --- a/pkg/cmd/workflow/run/run_test.go +++ b/pkg/cmd/workflow/run/run_test.go @@ -632,6 +632,7 @@ jobs: } t.Run(tt.name, func(t *testing.T) { + //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock as := prompt.NewAskStubber(t) if tt.askStubs != nil { tt.askStubs(as) diff --git a/pkg/cmd/workflow/shared/shared.go b/pkg/cmd/workflow/shared/shared.go index c3f0b6a93..efef97e1c 100644 --- a/pkg/cmd/workflow/shared/shared.go +++ b/pkg/cmd/workflow/shared/shared.go @@ -104,6 +104,7 @@ func SelectWorkflow(workflows []Workflow, promptMsg string, states []WorkflowSta var selected int + //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter err := prompt.SurveyAskOne(&survey.Select{ Message: promptMsg, Options: candidates, diff --git a/pkg/prompt/prompt.go b/pkg/prompt/prompt.go index 1c6fc7a61..683fad913 100644 --- a/pkg/prompt/prompt.go +++ b/pkg/prompt/prompt.go @@ -2,6 +2,7 @@ package prompt import "github.com/AlecAivazis/survey/v2" +// Deprecated: use PrompterMock func StubConfirm(result bool) func() { orig := Confirm Confirm = func(_ string, r *bool) error { @@ -13,6 +14,7 @@ func StubConfirm(result bool) func() { } } +// Deprecated: use Prompter var Confirm = func(prompt string, result *bool) error { p := &survey.Confirm{ Message: prompt, @@ -21,10 +23,12 @@ var Confirm = func(prompt string, result *bool) error { return SurveyAskOne(p, result) } +// Deprecated: use Prompter var SurveyAskOne = func(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error { return survey.AskOne(p, response, opts...) } +// Deprecated: use Prompter var SurveyAsk = func(qs []*survey.Question, response interface{}, opts ...survey.AskOpt) error { return survey.Ask(qs, response, opts...) } diff --git a/pkg/prompt/stubber.go b/pkg/prompt/stubber.go index 8d9e22520..8011c5924 100644 --- a/pkg/prompt/stubber.go +++ b/pkg/prompt/stubber.go @@ -18,6 +18,7 @@ type testing interface { Cleanup(func()) } +// Deprecated: use PrompterMock func NewAskStubber(t testing) *AskStubber { as, teardown := InitAskStubber() t.Cleanup(func() { From 8bba7f9624629173b844b20872334d5c4e818aaa Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 15 Aug 2022 13:28:15 -0500 Subject: [PATCH 8/9] rename NewPrompter to New --- internal/prompter/prompter.go | 2 +- pkg/cmd/factory/default.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/prompter/prompter.go b/internal/prompter/prompter.go index 6b89867b6..49516bd6a 100644 --- a/internal/prompter/prompter.go +++ b/internal/prompter/prompter.go @@ -22,7 +22,7 @@ type Prompter interface { MarkdownEditor(string, string, bool) (string, error) } -func NewPrompter(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter { +func New(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter { return &surveyPrompter{ editorCmd: editorCmd, stdin: stdin.(terminal.FileReader), diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index 9d5584147..e5be3dd0c 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -113,7 +113,7 @@ func browser(f *cmdutil.Factory) cmdutil.Browser { func newPrompter(f *cmdutil.Factory) prompter.Prompter { editor, _ := cmdutil.DetermineEditor(f.Config) io := f.IOStreams - return prompter.NewPrompter(editor, io.In, io.Out, io.ErrOut) + return prompter.New(editor, io.In, io.Out, io.ErrOut) } // Browser precedence From 2d093c1741aab1dbb28b774c90ec835f2c39254e Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 15 Aug 2022 13:53:43 -0500 Subject: [PATCH 9/9] add test helpers --- internal/prompter/test.go | 22 +++++++++++++ pkg/cmd/auth/login/login_test.go | 45 ++++++++++++++------------ pkg/cmd/auth/shared/login_flow_test.go | 8 ++--- pkg/cmd/extension/command_test.go | 2 +- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 internal/prompter/test.go diff --git a/internal/prompter/test.go b/internal/prompter/test.go new file mode 100644 index 000000000..ae7574ea9 --- /dev/null +++ b/internal/prompter/test.go @@ -0,0 +1,22 @@ +package prompter + +import "fmt" + +// Test helpers + +func IndexFor(options []string, answer string) (int, error) { + for ix, a := range options { + if a == answer { + return ix, nil + } + } + return -1, NoSuchAnswerErr(answer) +} + +func NoSuchAnswerErr(answer string) error { + return fmt.Errorf("no such answer '%s'", answer) +} + +func NoSuchPromptErr(prompt string) error { + return fmt.Errorf("no such prompt '%s'", prompt) +} diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index c05d9b9de..65de3065c 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -385,8 +385,11 @@ func Test_loginRun_Survey(t *testing.T) { reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org")) }, prompterStubs: func(pm *prompter.PrompterMock) { - pm.SelectFunc = func(_, _ string, _ []string) (int, error) { - return 0, nil + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { + if prompt == "What account do you want to log into?" { + return prompter.IndexFor(opts, "GitHub.com") + } + return -1, prompter.NoSuchPromptErr(prompt) } }, wantHosts: "", @@ -405,14 +408,14 @@ func Test_loginRun_Survey(t *testing.T) { git_protocol: https `), prompterStubs: func(pm *prompter.PrompterMock) { - pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What is your preferred protocol for Git operations?": - return 0, nil + return prompter.IndexFor(opts, "HTTPS") case "How would you like to authenticate GitHub CLI?": - return 1, nil + return prompter.IndexFor(opts, "Paste an authentication token") } - return -1, nil + return -1, prompter.NoSuchPromptErr(prompt) } }, runStubs: func(rs *run.CommandStubber) { @@ -439,16 +442,16 @@ func Test_loginRun_Survey(t *testing.T) { Interactive: true, }, prompterStubs: func(pm *prompter.PrompterMock) { - pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What account do you want to log into?": - return 1, nil + return prompter.IndexFor(opts, "GitHub Enterprise Server") case "What is your preferred protocol for Git operations?": - return 0, nil + return prompter.IndexFor(opts, "HTTPS") case "How would you like to authenticate GitHub CLI?": - return 1, nil + return prompter.IndexFor(opts, "Paste an authentication token") } - return -1, nil + return -1, prompter.NoSuchPromptErr(prompt) } pm.InputHostnameFunc = func() (string, error) { return "brad.vickers", nil @@ -478,16 +481,16 @@ func Test_loginRun_Survey(t *testing.T) { Interactive: true, }, prompterStubs: func(pm *prompter.PrompterMock) { - pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What account do you want to log into?": - return 0, nil + return prompter.IndexFor(opts, "GitHub.com") case "What is your preferred protocol for Git operations?": - return 0, nil + return prompter.IndexFor(opts, "HTTPS") case "How would you like to authenticate GitHub CLI?": - return 1, nil + return prompter.IndexFor(opts, "Paste an authentication token") } - return -1, nil + return -1, prompter.NoSuchPromptErr(prompt) } }, runStubs: func(rs *run.CommandStubber) { @@ -508,16 +511,16 @@ func Test_loginRun_Survey(t *testing.T) { Interactive: true, }, prompterStubs: func(pm *prompter.PrompterMock) { - pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What account do you want to log into?": - return 0, nil + return prompter.IndexFor(opts, "GitHub.com") case "What is your preferred protocol for Git operations?": - return 1, nil + return prompter.IndexFor(opts, "SSH") case "How would you like to authenticate GitHub CLI?": - return 1, nil + return prompter.IndexFor(opts, "Paste an authentication token") } - return -1, nil + return -1, prompter.NoSuchPromptErr(prompt) } }, wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://github.com/settings/tokens"), diff --git a/pkg/cmd/auth/shared/login_flow_test.go b/pkg/cmd/auth/shared/login_flow_test.go index 8bcecfc6a..40d045661 100644 --- a/pkg/cmd/auth/shared/login_flow_test.go +++ b/pkg/cmd/auth/shared/login_flow_test.go @@ -48,14 +48,14 @@ func TestLogin_ssh(t *testing.T) { httpmock.StringResponse(`{}`)) pm := &prompter.PrompterMock{} - pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) { + pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) { switch prompt { case "What is your preferred protocol for Git operations?": - return 1, nil + return prompter.IndexFor(opts, "SSH") case "How would you like to authenticate GitHub CLI?": - return 1, nil + return prompter.IndexFor(opts, "Paste an authentication token") } - return -1, nil + return -1, prompter.NoSuchPromptErr(prompt) } pm.PasswordFunc = func(_ string) (string, error) { return "monkey", nil diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index 8cdb45d45..fb4707320 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -395,7 +395,7 @@ func TestNewCmdExtension(t *testing.T) { return "", nil } pm.SelectFunc = func(prompt, defVal string, opts []string) (int, error) { - return 0, nil + return prompter.IndexFor(opts, "Script (Bash, Ruby, Python, etc)") } }, wantStdout: heredoc.Doc(`