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

Function NewCmdRerun

pkg/cmd/run/rerun/rerun.go:36–95  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*RerunOptions) error)

Source from the content-addressed store, hash-verified

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

Callers 1

TestNewCmdRerunFunction · 0.85

Calls 5

FlagErrorfFunction · 0.92
runRerunFunction · 0.85
CanPromptMethod · 0.80
ColorSchemeMethod · 0.80
WarningIconMethod · 0.80

Tested by 1

TestNewCmdRerunFunction · 0.68