Merge pull request #3332 from cli/run-prompt-refactor

small refactor around prompting for runs
This commit is contained in:
Nate Smith 2021-03-30 14:51:59 -07:00 committed by GitHub
commit 6bbebcdee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -96,7 +96,12 @@ func runView(opts *ViewOptions) error {
jobID := opts.JobID
if opts.Prompt {
runID, err := shared.PromptForRun(cs, client, repo)
// TODO arbitrary limit
runs, err := shared.GetRuns(client, repo, 10)
if err != nil {
return fmt.Errorf("failed to get runs: %w", err)
}
runID, err := shared.PromptForRun(cs, runs)
if err != nil {
return err
}

View file

@ -218,13 +218,7 @@ func GetJobs(client *api.Client, repo ghrepo.Interface, run Run) ([]Job, error)
return result.Jobs, nil
}
func PromptForRun(cs *iostreams.ColorScheme, client *api.Client, repo ghrepo.Interface) (string, error) {
// TODO arbitrary limit
runs, err := GetRuns(client, repo, 10)
if err != nil {
return "", err
}
func PromptForRun(cs *iostreams.ColorScheme, runs []Run) (string, error) {
var selected int
candidates := []string{}
@ -237,7 +231,7 @@ func PromptForRun(cs *iostreams.ColorScheme, client *api.Client, repo ghrepo.Int
// TODO consider custom filter so it's fuzzier. right now matches start anywhere in string but
// become contiguous
err = prompt.SurveyAskOne(&survey.Select{
err := prompt.SurveyAskOne(&survey.Select{
Message: "Select a workflow run",
Options: candidates,
PageSize: 10,

View file

@ -92,7 +92,12 @@ func runView(opts *ViewOptions) error {
if opts.Prompt {
cs := opts.IO.ColorScheme()
runID, err = shared.PromptForRun(cs, client, repo)
// TODO arbitrary limit
runs, err := shared.GetRuns(client, repo, 10)
if err != nil {
return fmt.Errorf("failed to get runs: %w", err)
}
runID, err = shared.PromptForRun(cs, runs)
if err != nil {
return err
}