| 188 | } |
| 189 | |
| 190 | func rerunRun(client *api.Client, repo ghrepo.Interface, run *shared.Run, onlyFailed, debug bool) error { |
| 191 | runVerb := "rerun" |
| 192 | if onlyFailed { |
| 193 | runVerb = "rerun-failed-jobs" |
| 194 | } |
| 195 | |
| 196 | body, err := requestBody(debug) |
| 197 | if err != nil { |
| 198 | return fmt.Errorf("failed to create rerun body: %w", err) |
| 199 | } |
| 200 | |
| 201 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", strconv.FormatInt(run.ID, 10), runVerb) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | err = client.REST(repo.RepoHost(), "POST", path.String(), body, nil) |
| 207 | if err != nil { |
| 208 | var httpError api.HTTPError |
| 209 | if errors.As(err, &httpError) && httpError.StatusCode == 403 { |
| 210 | return fmt.Errorf("run %d cannot be rerun; %s", run.ID, httpError.Message) |
| 211 | } |
| 212 | return fmt.Errorf("failed to rerun: %w", err) |
| 213 | } |
| 214 | return nil |
| 215 | } |
| 216 | |
| 217 | func rerunJob(client *api.Client, repo ghrepo.Interface, job *shared.Job, debug bool) error { |
| 218 | body, err := requestBody(debug) |