| 93 | } |
| 94 | |
| 95 | func runRerun(opts *RerunOptions) error { |
| 96 | c, err := opts.HttpClient() |
| 97 | if err != nil { |
| 98 | return fmt.Errorf("failed to create http client: %w", err) |
| 99 | } |
| 100 | client := api.NewClientFromHTTP(c) |
| 101 | |
| 102 | repo, err := opts.BaseRepo() |
| 103 | if err != nil { |
| 104 | return fmt.Errorf("failed to determine base repo: %w", err) |
| 105 | } |
| 106 | |
| 107 | cs := opts.IO.ColorScheme() |
| 108 | |
| 109 | runID := opts.RunID |
| 110 | jobID := opts.JobID |
| 111 | var selectedJob *shared.Job |
| 112 | |
| 113 | if jobID != "" { |
| 114 | opts.IO.StartProgressIndicator() |
| 115 | selectedJob, err = shared.GetJob(client, repo, jobID) |
| 116 | opts.IO.StopProgressIndicator() |
| 117 | if err != nil { |
| 118 | return fmt.Errorf("failed to get job: %w", err) |
| 119 | } |
| 120 | runID = fmt.Sprintf("%d", selectedJob.RunID) |
| 121 | } |
| 122 | |
| 123 | if opts.Prompt { |
| 124 | runs, err := shared.GetRunsWithFilter(client, repo, nil, 10, func(run shared.Run) bool { |
| 125 | if run.Status != shared.Completed { |
| 126 | return false |
| 127 | } |
| 128 | // TODO StartupFailure indicates a bad yaml file; such runs can never be |
| 129 | // rerun. But hiding them from the prompt might confuse people? |
| 130 | return run.Conclusion != shared.Success && run.Conclusion != shared.StartupFailure |
| 131 | }) |
| 132 | if err != nil { |
| 133 | return fmt.Errorf("failed to get runs: %w", err) |
| 134 | } |
| 135 | if len(runs) == 0 { |
| 136 | return errors.New("no recent runs have failed; please specify a specific `<run-id>`") |
| 137 | } |
| 138 | if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil { |
| 139 | return err |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | debugMsg := "" |
| 144 | if opts.Debug { |
| 145 | debugMsg = " with debug logging enabled" |
| 146 | } |
| 147 | |
| 148 | if opts.JobID != "" { |
| 149 | err = rerunJob(client, repo, selectedJob, opts.Debug) |
| 150 | if err != nil { |
| 151 | return err |
| 152 | } |