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

Function NewCmdComment

pkg/cmd/pr/comment/comment.go:13–118  ·  view source on GitHub ↗
(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*shared.CommentableOptions) error)

Source from the content-addressed store, hash-verified

11)
12
13func NewCmdComment(f *cmdutil.Factory, telemetry ghtelemetry.InvocationRecorder, runF func(*shared.CommentableOptions) error) *cobra.Command {
14 opts := &shared.CommentableOptions{
15 IO: f.IOStreams,
16 HttpClient: f.HttpClient,
17 EditSurvey: shared.CommentableEditSurvey(f.Config, f.IOStreams),
18 InteractiveEditSurvey: shared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
19 ConfirmSubmitSurvey: shared.CommentableConfirmSubmitSurvey(f.Prompter),
20 ConfirmCreateIfNoneSurvey: shared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
21 ConfirmDeleteLastComment: shared.CommentableConfirmDeleteLastComment(f.Prompter),
22 OpenInBrowser: f.Browser.Browse,
23 }
24
25 var bodyFile string
26
27 cmd := &cobra.Command{
28 Use: "comment [<number> | <url> | <branch>]",
29 Short: "Add a comment to a pull request",
30 Long: heredoc.Docf(`
31 Add a comment to a GitHub pull request.
32
33 Without body text or attachments supplied through flags, the command will
34 interactively prompt for the comment text.
35
36 Use %[1]s--attach%[1]s to upload an image or video. If the body already references an
37 attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
38 at the uploaded asset. Paths in a %[1]s--body-file%[1]s are relative to its directory,
39 falling back to the working directory. Any attached file the body does not reference
40 is appended to the end of the comment.
41 You can attach up to 50 files per command.
42
43 Alt text for an image follows the path after %[1]s#%[1]s, as in
44 %[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
45 A reference already in the body keeps the alt text written there. Video renders
46 as a player and has no alt text, so it cannot be given any.
47 `, "`"),
48 Example: heredoc.Doc(`
49 # Add a comment to a pull request
50 $ gh pr comment 13 --body "Hi from GitHub CLI"
51
52 # Attach a screenshot, with alt text after "#"
53 $ gh pr comment 13 --attach './login.png#The login error state'
54
55 # Attach multiple files by repeating the flag
56 $ gh pr comment 13 --attach ./before.png --attach ./after.png
57 `),
58 Args: cobra.MaximumNArgs(1),
59 PreRunE: func(cmd *cobra.Command, args []string) error {
60 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
61 return cmdutil.FlagErrorf("argument required when using the --repo flag")
62 }
63 var selector string
64 if len(args) > 0 {
65 selector = args[0]
66 }
67 fields := []string{"id", "url"}
68 if opts.EditLast || opts.DeleteLast {
69 fields = append(fields, "comments")
70 }

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 12

CommentableEditSurveyFunction · 0.92
FlagErrorfFunction · 0.92
NewFinderFunction · 0.92
CommentablePreRunFunction · 0.92
ReadMarkdownBodyFileFunction · 0.92
CommentableRunFunction · 0.92
AddFlagFunction · 0.92
FindMethod · 0.65

Tested by 1

TestNewCmdCommentFunction · 0.56