MCPcopy Create free account
hub / github.com/cli/cli / runRerun

Function runRerun

pkg/cmd/run/rerun/rerun.go:97–188  ·  view source on GitHub ↗
(opts *RerunOptions)

Source from the content-addressed store, hash-verified

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

Callers 2

NewCmdRerunFunction · 0.85
TestRerunFunction · 0.85

Calls 15

NewClientFromHTTPFunction · 0.92
GetJobFunction · 0.92
GetRunsWithFilterFunction · 0.92
SelectRunFunction · 0.92
GetRunFunction · 0.92
rerunJobFunction · 0.85
rerunRunFunction · 0.85
ColorSchemeMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconMethod · 0.80
CyanfMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestRerunFunction · 0.68