MCPcopy
hub / github.com/cli/cli / NewCmdComment

Function NewCmdComment

pkg/cmd/pr/comment/comment.go:11–85  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*shared.CommentableOptions) error)

Source from the content-addressed store, hash-verified

9)
10
11func NewCmdComment(f *cmdutil.Factory, runF func(*shared.CommentableOptions) error) *cobra.Command {
12 opts := &shared.CommentableOptions{
13 IO: f.IOStreams,
14 HttpClient: f.HttpClient,
15 EditSurvey: shared.CommentableEditSurvey(f.Config, f.IOStreams),
16 InteractiveEditSurvey: shared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
17 ConfirmSubmitSurvey: shared.CommentableConfirmSubmitSurvey(f.Prompter),
18 ConfirmCreateIfNoneSurvey: shared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
19 ConfirmDeleteLastComment: shared.CommentableConfirmDeleteLastComment(f.Prompter),
20 OpenInBrowser: f.Browser.Browse,
21 }
22
23 var bodyFile string
24
25 cmd := &cobra.Command{
26 Use: "comment [<number> | <url> | <branch>]",
27 Short: "Add a comment to a pull request",
28 Long: heredoc.Doc(`
29 Add a comment to a GitHub pull request.
30
31 Without the body text supplied through flags, the command will interactively
32 prompt for the comment text.
33 `),
34 Example: heredoc.Doc(`
35 $ gh pr comment 13 --body "Hi from GitHub CLI"
36 `),
37 Args: cobra.MaximumNArgs(1),
38 PreRunE: func(cmd *cobra.Command, args []string) error {
39 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
40 return cmdutil.FlagErrorf("argument required when using the --repo flag")
41 }
42 var selector string
43 if len(args) > 0 {
44 selector = args[0]
45 }
46 fields := []string{"id", "url"}
47 if opts.EditLast || opts.DeleteLast {
48 fields = append(fields, "comments")
49 }
50 finder := shared.NewFinder(f)
51 opts.RetrieveCommentable = func() (shared.Commentable, ghrepo.Interface, error) {
52 return finder.Find(shared.FindOptions{
53 Selector: selector,
54 Fields: fields,
55 })
56 }
57 return shared.CommentablePreRun(cmd, opts)
58 },
59 RunE: func(cmd *cobra.Command, args []string) error {
60 if bodyFile != "" {
61 b, err := cmdutil.ReadFile(bodyFile, opts.IO.In)
62 if err != nil {
63 return err
64 }
65 opts.Body = string(b)
66 }
67
68 if runF != nil {

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 11

CommentableEditSurveyFunction · 0.92
FlagErrorfFunction · 0.92
NewFinderFunction · 0.92
CommentablePreRunFunction · 0.92
ReadFileFunction · 0.92
CommentableRunFunction · 0.92
FindMethod · 0.65

Tested by 1

TestNewCmdCommentFunction · 0.56