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

Function NewCmdReview

pkg/cmd/pr/review/review.go:34–146  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*ReviewOptions) error)

Source from the content-addressed store, hash-verified

32}
33
34func 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

Callers 2

Test_NewCmdReviewFunction · 0.85
runCommandFunction · 0.85

Calls 6

NewFinderFunction · 0.92
FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
ReadFileFunction · 0.92
reviewRunFunction · 0.85
CanPromptMethod · 0.80

Tested by 2

Test_NewCmdReviewFunction · 0.68
runCommandFunction · 0.68