| 32 | } |
| 33 | |
| 34 | func NewCmdRerun(f *cmdutil.Factory, runF func(*RerunOptions) error) *cobra.Command { |
| 35 | opts := &RerunOptions{ |
| 36 | IO: f.IOStreams, |
| 37 | Prompter: f.Prompter, |
| 38 | HttpClient: f.HttpClient, |
| 39 | } |
| 40 | |
| 41 | cmd := &cobra.Command{ |
| 42 | Use: "rerun [<run-id>]", |
| 43 | Short: "Rerun a run", |
| 44 | Long: heredoc.Docf(` |
| 45 | Rerun an entire run, only failed jobs, or a specific job from a run. |
| 46 | |
| 47 | Note that due to historical reasons, the %[1]s--job%[1]s flag may not take what you expect. |
| 48 | Specifically, when navigating to a job in the browser, the URL looks like this: |
| 49 | %[1]shttps://github.com/<owner>/<repo>/actions/runs/<run-id>/jobs/<number>%[1]s. |
| 50 | |
| 51 | However, this %[1]s<number>%[1]s should not be used with the %[1]s--job%[1]s flag and will result in the |
| 52 | API returning %[1]s404 NOT FOUND%[1]s. Instead, you can get the correct job IDs using the following command: |
| 53 | |
| 54 | gh run view <run-id> --json jobs --jq '.jobs[] | {name, databaseId}' |
| 55 | |
| 56 | You will need to use databaseId field for triggering job re-runs. |
| 57 | `, "`"), |
| 58 | Args: cobra.MaximumNArgs(1), |
| 59 | RunE: func(cmd *cobra.Command, args []string) error { |
| 60 | // support `-R, --repo` override |
| 61 | opts.BaseRepo = f.BaseRepo |
| 62 | |
| 63 | if len(args) == 0 && opts.JobID == "" { |
| 64 | if !opts.IO.CanPrompt() { |
| 65 | return cmdutil.FlagErrorf("`<run-id>` or `--job` required when not running interactively") |
| 66 | } else { |
| 67 | opts.Prompt = true |
| 68 | } |
| 69 | } else if len(args) > 0 { |
| 70 | opts.RunID = args[0] |
| 71 | } |
| 72 | |
| 73 | if opts.RunID != "" && opts.JobID != "" { |
| 74 | opts.RunID = "" |
| 75 | if opts.IO.CanPrompt() { |
| 76 | cs := opts.IO.ColorScheme() |
| 77 | fmt.Fprintf(opts.IO.ErrOut, "%s both run and job IDs specified; ignoring run ID\n", cs.WarningIcon()) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if runF != nil { |
| 82 | return runF(opts) |
| 83 | } |
| 84 | return runRerun(opts) |
| 85 | }, |
| 86 | } |
| 87 | |
| 88 | cmd.Flags().BoolVar(&opts.OnlyFailed, "failed", false, "Rerun only failed jobs, including dependencies") |
| 89 | cmd.Flags().StringVarP(&opts.JobID, "job", "j", "", "Rerun a specific job ID from a run, including dependencies") |
| 90 | cmd.Flags().BoolVarP(&opts.Debug, "debug", "d", false, "Rerun with debug logging") |
| 91 | |