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

Function NewCmdComment

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

Source from the content-addressed store, hash-verified

13)
14
15func NewCmdComment(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*prShared.CommentableOptions) error) *cobra.Command {
16 opts := &prShared.CommentableOptions{
17 IO: f.IOStreams,
18 HttpClient: f.HttpClient,
19 EditSurvey: prShared.CommentableEditSurvey(f.Config, f.IOStreams),
20 InteractiveEditSurvey: prShared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
21 ConfirmSubmitSurvey: prShared.CommentableConfirmSubmitSurvey(f.Prompter),
22 ConfirmCreateIfNoneSurvey: prShared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
23 ConfirmDeleteLastComment: prShared.CommentableConfirmDeleteLastComment(f.Prompter),
24 OpenInBrowser: f.Browser.Browse,
25 }
26
27 var bodyFile string
28
29 cmd := &cobra.Command{
30 Use: "comment {<number> | <url>}",
31 Short: "Add a comment to an issue",
32 Long: heredoc.Docf(`
33 Add a comment to a GitHub issue.
34
35 Without body text or attachments supplied through flags, the command will
36 interactively prompt for the comment text.
37
38 Use %[1]s--attach%[1]s to upload an image or video. If the body already references an
39 attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
40 at the uploaded asset. Paths in a %[1]s--body-file%[1]s are relative to its directory,
41 falling back to the working directory. Any attached file the body does not reference
42 is appended 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.RetrieveCommentable = func() (prShared.Commentable, ghrepo.Interface, error) {
63 // TODO wm: more testing
64 issueNumber, parsedBaseRepo, err := shared.ParseIssueFromArg(args[0])
65 if err != nil {
66 return nil, nil, err
67 }
68
69 // If the args provided the base repo then use that directly.
70 var baseRepo ghrepo.Interface
71
72 if parsedBaseRepo, present := parsedBaseRepo.Value(); present {

Calls 4

ReadMarkdownBodyFileFunction · 0.92
AddFlagFunction · 0.92
ValueMethod · 0.80
BaseRepoMethod · 0.65