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

Function NewCmdComment

pkg/cmd/issue/comment/comment.go:15–141  ·  view source on GitHub ↗
(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*prShared.CommentableOptions) error)

Source from the content-addressed store, hash-verified

13)
14
15func NewCmdComment(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*prShared.CommentableOptions) error) *cobra.Command {
16 opts := &prShared.CommentableOptions{
17 IO: f.IOStreams,
18 HttpClient: f.HttpClient,
19 Config: f.Config,
20 EditSurvey: prShared.CommentableEditSurvey(f.Config, f.IOStreams),
21 InteractiveEditSurvey: prShared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
22 ConfirmSubmitSurvey: prShared.CommentableConfirmSubmitSurvey(f.Prompter),
23 ConfirmCreateIfNoneSurvey: prShared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
24 ConfirmDeleteLastComment: prShared.CommentableConfirmDeleteLastComment(f.Prompter),
25 OpenInBrowser: f.Browser.Browse,
26 }
27
28 var bodyFile string
29
30 cmd := &cobra.Command{
31 Use: "comment {<number> | <url>}",
32 Short: "Add a comment to an issue",
33 Long: heredoc.Docf(`
34 Add a comment to a GitHub issue.
35
36 Without body text or attachments supplied through flags, the command will
37 interactively prompt for the comment text.
38
39 Use %[1]s--attach%[1]s to upload an image or video. If the body already references an
40 attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
41 at the uploaded asset. Any attached file the body does not reference is appended
42 to the end of the comment.
43 You can attach up to 50 files per command.
44
45 Alt text for an image follows the path after %[1]s#%[1]s, as in
46 %[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
47 A reference already in the body keeps the alt text written there. Video renders
48 as a player and has no alt text, so it cannot be given any.
49 `, "`"),
50 Example: heredoc.Doc(`
51 # Add a comment to an issue
52 $ gh issue comment 12 --body "Hi from GitHub CLI"
53
54 # Attach a screenshot, with alt text after "#"
55 $ gh issue comment 12 --attach './login.png#The login error state'
56
57 # Attach multiple files by repeating the flag
58 $ gh issue comment 12 --attach ./before.png --attach ./after.png
59 `),
60 Args: cobra.ExactArgs(1),
61 PreRunE: func(cmd *cobra.Command, args []string) error {
62 opts.AttachFlag.RecordTelemetry(cmd.CommandPath(), telemetry)
63
64 opts.RetrieveCommentable = func() (prShared.Commentable, ghrepo.Interface, error) {
65 // TODO wm: more testing
66 issueNumber, parsedBaseRepo, err := shared.ParseIssueFromArg(args[0])
67 if err != nil {
68 return nil, nil, err
69 }
70
71 // If the args provided the base repo then use that directly.
72 var baseRepo ghrepo.Interface

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 5

ReadFileFunction · 0.92
AddFlagFunction · 0.92
RecordTelemetryMethod · 0.80
ValueMethod · 0.80
BaseRepoMethod · 0.65

Tested by 1

TestNewCmdCommentFunction · 0.56