Skip to content

Commit 6bbebcd

Browse files
author
Nate Smith
authored
Merge pull request cli#3332 from cli/run-prompt-refactor
small refactor around prompting for runs
2 parents 23b2594 + 0ecb04c commit 6bbebcd

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

pkg/cmd/job/view/view.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ func runView(opts *ViewOptions) error {
9696

9797
jobID := opts.JobID
9898
if opts.Prompt {
99-
runID, err := shared.PromptForRun(cs, client, repo)
99+
// TODO arbitrary limit
100+
runs, err := shared.GetRuns(client, repo, 10)
101+
if err != nil {
102+
return fmt.Errorf("failed to get runs: %w", err)
103+
}
104+
runID, err := shared.PromptForRun(cs, runs)
100105
if err != nil {
101106
return err
102107
}

pkg/cmd/run/shared/shared.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,7 @@ func GetJobs(client *api.Client, repo ghrepo.Interface, run Run) ([]Job, error)
218218
return result.Jobs, nil
219219
}
220220

221-
func PromptForRun(cs *iostreams.ColorScheme, client *api.Client, repo ghrepo.Interface) (string, error) {
222-
// TODO arbitrary limit
223-
runs, err := GetRuns(client, repo, 10)
224-
if err != nil {
225-
return "", err
226-
}
227-
221+
func PromptForRun(cs *iostreams.ColorScheme, runs []Run) (string, error) {
228222
var selected int
229223

230224
candidates := []string{}
@@ -237,7 +231,7 @@ func PromptForRun(cs *iostreams.ColorScheme, client *api.Client, repo ghrepo.Int
237231

238232
// TODO consider custom filter so it's fuzzier. right now matches start anywhere in string but
239233
// become contiguous
240-
err = prompt.SurveyAskOne(&survey.Select{
234+
err := prompt.SurveyAskOne(&survey.Select{
241235
Message: "Select a workflow run",
242236
Options: candidates,
243237
PageSize: 10,

pkg/cmd/run/view/view.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ func runView(opts *ViewOptions) error {
9292

9393
if opts.Prompt {
9494
cs := opts.IO.ColorScheme()
95-
runID, err = shared.PromptForRun(cs, client, repo)
95+
// TODO arbitrary limit
96+
runs, err := shared.GetRuns(client, repo, 10)
97+
if err != nil {
98+
return fmt.Errorf("failed to get runs: %w", err)
99+
}
100+
runID, err = shared.PromptForRun(cs, runs)
96101
if err != nil {
97102
return err
98103
}

0 commit comments

Comments
 (0)