From 07776d23b19612de357d31463d416b4ef11af344 Mon Sep 17 00:00:00 2001 From: nate smith Date: Mon, 10 Apr 2023 16:35:00 -0700 Subject: [PATCH] use new prompter in run rerun --- pkg/cmd/run/rerun/rerun.go | 5 +++-- pkg/cmd/run/rerun/rerun_test.go | 38 +++++++++++++++++---------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pkg/cmd/run/rerun/rerun.go b/pkg/cmd/run/rerun/rerun.go index 2522e632c..b640f41f7 100644 --- a/pkg/cmd/run/rerun/rerun.go +++ b/pkg/cmd/run/rerun/rerun.go @@ -20,6 +20,7 @@ type RerunOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams BaseRepo func() (ghrepo.Interface, error) + Prompter shared.Prompter RunID string OnlyFailed bool @@ -32,6 +33,7 @@ type RerunOptions struct { func NewCmdRerun(f *cmdutil.Factory, runF func(*RerunOptions) error) *cobra.Command { opts := &RerunOptions{ IO: f.IOStreams, + Prompter: f.Prompter, HttpClient: f.HttpClient, } @@ -114,8 +116,7 @@ func runRerun(opts *RerunOptions) error { if len(runs) == 0 { return errors.New("no recent runs have failed; please specify a specific ``") } - runID, err = shared.PromptForRun(cs, runs) - if err != nil { + if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil { return err } } diff --git a/pkg/cmd/run/rerun/rerun_test.go b/pkg/cmd/run/rerun/rerun_test.go index 730952f1f..991ab5f3a 100644 --- a/pkg/cmd/run/rerun/rerun_test.go +++ b/pkg/cmd/run/rerun/rerun_test.go @@ -8,12 +8,12 @@ import ( "testing" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmd/run/shared" workflowShared "github.com/cli/cli/v2/pkg/cmd/workflow/shared" "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" ) @@ -161,15 +161,15 @@ func TestNewCmdRerun(t *testing.T) { func TestRerun(t *testing.T) { tests := []struct { - name string - httpStubs func(*httpmock.Registry) - askStubs func(*prompt.AskStubber) - opts *RerunOptions - tty bool - wantErr bool - errOut string - wantOut string - wantDebug bool + name string + httpStubs func(*httpmock.Registry) + promptStubs func(*prompter.MockPrompter) + opts *RerunOptions + tty bool + wantErr bool + errOut string + wantOut string + wantDebug bool }{ { name: "arg", @@ -336,9 +336,12 @@ func TestRerun(t *testing.T) { httpmock.REST("POST", "repos/OWNER/REPO/actions/runs/1234/rerun"), httpmock.StringResponse("{}")) }, - askStubs: func(as *prompt.AskStubber) { - //nolint:staticcheck // SA1019: as.StubOne is deprecated: use StubPrompt - as.StubOne(2) + promptStubs: func(pm *prompter.MockPrompter) { + pm.RegisterSelect("Select a workflow run", + []string{"X cool commit, CI (trunk) Feb 23, 2021", "X cool commit, CI (trunk) Feb 23, 2021", "X cool commit, CI (trunk) Feb 23, 2021", "- cool commit, CI (trunk) Feb 23, 2021", "- cool commit, CI (trunk) Feb 23, 2021", "X cool commit, CI (trunk) Feb 23, 2021"}, + func(_, _ string, opts []string) (int, error) { + return 2, nil + }) }, wantOut: "✓ Requested rerun of run 1234\n", }, @@ -408,11 +411,10 @@ func TestRerun(t *testing.T) { return ghrepo.FromFullName("OWNER/REPO") } - //nolint:staticcheck // SA1019: prompt.InitAskStubber is deprecated: use NewAskStubber - as, teardown := prompt.InitAskStubber() - defer teardown() - if tt.askStubs != nil { - tt.askStubs(as) + pm := prompter.NewMockPrompter(t) + tt.opts.Prompter = pm + if tt.promptStubs != nil { + tt.promptStubs(pm) } t.Run(tt.name, func(t *testing.T) {