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

Function NewCmdComment

pkg/cmd/issue/comment/comment.go:13–106  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*prShared.CommentableOptions) error)

Source from the content-addressed store, hash-verified

11)
12
13func NewCmdComment(f *cmdutil.Factory, runF func(*prShared.CommentableOptions) error) *cobra.Command {
14 opts := &prShared.CommentableOptions{
15 IO: f.IOStreams,
16 HttpClient: f.HttpClient,
17 EditSurvey: prShared.CommentableEditSurvey(f.Config, f.IOStreams),
18 InteractiveEditSurvey: prShared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
19 ConfirmSubmitSurvey: prShared.CommentableConfirmSubmitSurvey(f.Prompter),
20 ConfirmCreateIfNoneSurvey: prShared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
21 ConfirmDeleteLastComment: prShared.CommentableConfirmDeleteLastComment(f.Prompter),
22 OpenInBrowser: f.Browser.Browse,
23 }
24
25 var bodyFile string
26
27 cmd := &cobra.Command{
28 Use: "comment {<number> | <url>}",
29 Short: "Add a comment to an issue",
30 Long: heredoc.Doc(`
31 Add a comment to a GitHub issue.
32
33 Without the body text supplied through flags, the command will interactively
34 prompt for the comment text.
35 `),
36 Example: heredoc.Doc(`
37 $ gh issue comment 12 --body "Hi from GitHub CLI"
38 `),
39 Args: cobra.ExactArgs(1),
40 PreRunE: func(cmd *cobra.Command, args []string) error {
41 opts.RetrieveCommentable = func() (prShared.Commentable, ghrepo.Interface, error) {
42 // TODO wm: more testing
43 issueNumber, parsedBaseRepo, err := shared.ParseIssueFromArg(args[0])
44 if err != nil {
45 return nil, nil, err
46 }
47
48 // If the args provided the base repo then use that directly.
49 var baseRepo ghrepo.Interface
50
51 if parsedBaseRepo, present := parsedBaseRepo.Value(); present {
52 baseRepo = parsedBaseRepo
53 } else {
54 // support `-R, --repo` override
55 baseRepo, err = f.BaseRepo()
56 if err != nil {
57 return nil, nil, err
58 }
59 }
60
61 httpClient, err := f.HttpClient()
62 if err != nil {
63 return nil, nil, err
64 }
65
66 fields := []string{"id", "url"}
67 if opts.EditLast || opts.DeleteLast {
68 fields = append(fields, "comments")
69 }
70

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 3

ReadFileFunction · 0.92
ValueMethod · 0.80
BaseRepoMethod · 0.65

Tested by 1

TestNewCmdCommentFunction · 0.56