| 24 | } |
| 25 | |
| 26 | func NewCmdReady(f *cmdutil.Factory, runF func(*ReadyOptions) error) *cobra.Command { |
| 27 | opts := &ReadyOptions{ |
| 28 | IO: f.IOStreams, |
| 29 | HttpClient: f.HttpClient, |
| 30 | } |
| 31 | |
| 32 | cmd := &cobra.Command{ |
| 33 | Use: "ready [<number> | <url> | <branch>]", |
| 34 | Short: "Mark a pull request as ready for review", |
| 35 | Long: heredoc.Docf(` |
| 36 | Mark a pull request as ready for review. |
| 37 | |
| 38 | Without an argument, the pull request that belongs to the current branch |
| 39 | is marked as ready. |
| 40 | |
| 41 | If supported by your plan, convert to draft with %[1]s--undo%[1]s |
| 42 | `, "`"), |
| 43 | Args: cobra.MaximumNArgs(1), |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | opts.Finder = shared.NewFinder(f) |
| 46 | |
| 47 | if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 { |
| 48 | return cmdutil.FlagErrorf("argument required when using the --repo flag") |
| 49 | } |
| 50 | |
| 51 | if len(args) > 0 { |
| 52 | opts.SelectorArg = args[0] |
| 53 | } |
| 54 | |
| 55 | if runF != nil { |
| 56 | return runF(opts) |
| 57 | } |
| 58 | return readyRun(opts) |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | cmd.Flags().BoolVar(&opts.Undo, "undo", false, `Convert a pull request to "draft"`) |
| 63 | return cmd |
| 64 | } |
| 65 | |
| 66 | func readyRun(opts *ReadyOptions) error { |
| 67 | cs := opts.IO.ColorScheme() |