| 32 | } |
| 33 | |
| 34 | func NewCmdReview(f *cmdutil.Factory, runF func(*ReviewOptions) error) *cobra.Command { |
| 35 | opts := &ReviewOptions{ |
| 36 | IO: f.IOStreams, |
| 37 | HttpClient: f.HttpClient, |
| 38 | Config: f.Config, |
| 39 | Prompter: f.Prompter, |
| 40 | } |
| 41 | |
| 42 | var ( |
| 43 | flagApprove bool |
| 44 | flagRequestChanges bool |
| 45 | flagComment bool |
| 46 | ) |
| 47 | |
| 48 | var bodyFile string |
| 49 | |
| 50 | cmd := &cobra.Command{ |
| 51 | Use: "review [<number> | <url> | <branch>]", |
| 52 | Short: "Add a review to a pull request", |
| 53 | Long: heredoc.Doc(` |
| 54 | Add a review to a pull request. |
| 55 | |
| 56 | Without an argument, the pull request that belongs to the current branch is reviewed. |
| 57 | `), |
| 58 | Example: heredoc.Doc(` |
| 59 | # Approve the pull request of the current branch |
| 60 | $ gh pr review --approve |
| 61 | |
| 62 | # Leave a review comment for the current branch |
| 63 | $ gh pr review --comment -b "interesting" |
| 64 | |
| 65 | # Add a review for a specific pull request |
| 66 | $ gh pr review 123 |
| 67 | |
| 68 | # Request changes on a specific pull request |
| 69 | $ gh pr review 123 -r -b "needs more ASCII art" |
| 70 | `), |
| 71 | Args: cobra.MaximumNArgs(1), |
| 72 | RunE: func(cmd *cobra.Command, args []string) error { |
| 73 | opts.Finder = shared.NewFinder(f) |
| 74 | |
| 75 | if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 { |
| 76 | return cmdutil.FlagErrorf("argument required when using the --repo flag") |
| 77 | } |
| 78 | |
| 79 | if len(args) > 0 { |
| 80 | opts.SelectorArg = args[0] |
| 81 | } |
| 82 | |
| 83 | bodyProvided := cmd.Flags().Changed("body") |
| 84 | bodyFileProvided := bodyFile != "" |
| 85 | |
| 86 | if err := cmdutil.MutuallyExclusive( |
| 87 | "specify only one of `--body` or `--body-file`", |
| 88 | bodyProvided, |
| 89 | bodyFileProvided, |
| 90 | ); err != nil { |
| 91 | return err |