| 50 | } |
| 51 | |
| 52 | func NewCmdChecks(f *cmdutil.Factory, runF func(*ChecksOptions) error) *cobra.Command { |
| 53 | var interval int |
| 54 | opts := &ChecksOptions{ |
| 55 | HttpClient: f.HttpClient, |
| 56 | IO: f.IOStreams, |
| 57 | Browser: f.Browser, |
| 58 | Interval: defaultInterval, |
| 59 | } |
| 60 | |
| 61 | cmd := &cobra.Command{ |
| 62 | Use: "checks [<number> | <url> | <branch>]", |
| 63 | Short: "Show CI status for a single pull request", |
| 64 | Long: heredoc.Docf(` |
| 65 | Show CI status for a single pull request. |
| 66 | |
| 67 | Without an argument, the pull request that belongs to the current branch |
| 68 | is selected. |
| 69 | |
| 70 | When the %[1]s--json%[1]s flag is used, it includes a %[1]sbucket%[1]s field, which categorizes |
| 71 | the %[1]sstate%[1]s field into %[1]spass%[1]s, %[1]sfail%[1]s, %[1]spending%[1]s, %[1]sskipping%[1]s, or %[1]scancel%[1]s. |
| 72 | |
| 73 | Additional exit codes: |
| 74 | 8: Checks pending |
| 75 | `, "`"), |
| 76 | Args: cobra.MaximumNArgs(1), |
| 77 | RunE: func(cmd *cobra.Command, args []string) error { |
| 78 | opts.Finder = shared.NewFinder(f) |
| 79 | |
| 80 | if opts.Exporter != nil && opts.Watch { |
| 81 | return cmdutil.FlagErrorf("cannot use `--watch` with `--json` flag") |
| 82 | } |
| 83 | |
| 84 | if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 { |
| 85 | return cmdutil.FlagErrorf("argument required when using the `--repo` flag") |
| 86 | } |
| 87 | |
| 88 | if opts.FailFast && !opts.Watch { |
| 89 | return cmdutil.FlagErrorf("cannot use `--fail-fast` flag without `--watch` flag") |
| 90 | } |
| 91 | |
| 92 | intervalChanged := cmd.Flags().Changed("interval") |
| 93 | if !opts.Watch && intervalChanged { |
| 94 | return cmdutil.FlagErrorf("cannot use `--interval` flag without `--watch` flag") |
| 95 | } |
| 96 | |
| 97 | if intervalChanged { |
| 98 | var err error |
| 99 | opts.Interval, err = time.ParseDuration(fmt.Sprintf("%ds", interval)) |
| 100 | if err != nil { |
| 101 | return cmdutil.FlagErrorf("could not parse `--interval` flag: %w", err) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if len(args) > 0 { |
| 106 | opts.SelectorArg = args[0] |
| 107 | } |
| 108 | |
| 109 | if runF != nil { |