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

Function NewCmdComment

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

Source from the content-addressed store, hash-verified

11)
12
13func NewCmdComment(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*shared.CommentableOptions) error) *cobra.Command {
14 opts := &shared.CommentableOptions{
15 IO: f.IOStreams,
16 HttpClient: f.HttpClient,
17 Config: f.Config,
18 EditSurvey: shared.CommentableEditSurvey(f.Config, f.IOStreams),
19 InteractiveEditSurvey: shared.CommentableInteractiveEditSurvey(f.Config, f.IOStreams),
20 ConfirmSubmitSurvey: shared.CommentableConfirmSubmitSurvey(f.Prompter),
21 ConfirmCreateIfNoneSurvey: shared.CommentableInteractiveCreateIfNoneSurvey(f.Prompter),
22 ConfirmDeleteLastComment: shared.CommentableConfirmDeleteLastComment(f.Prompter),
23 OpenInBrowser: f.Browser.Browse,
24 }
25
26 var bodyFile string
27
28 cmd := &cobra.Command{
29 Use: "comment [<number> | <url> | <branch>]",
30 Short: "Add a comment to a pull request",
31 Long: heredoc.Docf(`
32 Add a comment to a GitHub pull request.
33
34 Without body text or attachments supplied through flags, the command will
35 interactively prompt for the comment text.
36
37 Use %[1]s--attach%[1]s to upload an image or video. If the body already references an
38 attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
39 at the uploaded asset. Any attached file the body does not reference is appended
40 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 opts.AttachFlag.RecordTelemetry(cmd.CommandPath(), telemetry)
61
62 if repoOverride, _ := cmd.Flags().GetString("repo"); repoOverride != "" && len(args) == 0 {
63 return cmdutil.FlagErrorf("argument required when using the --repo flag")
64 }
65 var selector string
66 if len(args) > 0 {
67 selector = args[0]
68 }
69 fields := []string{"id", "url"}
70 if opts.EditLast || opts.DeleteLast {

Callers 1

TestNewCmdCommentFunction · 0.70

Calls 13

CommentableEditSurveyFunction · 0.92
FlagErrorfFunction · 0.92
NewFinderFunction · 0.92
CommentablePreRunFunction · 0.92
ReadFileFunction · 0.92
CommentableRunFunction · 0.92
AddFlagFunction · 0.92
RecordTelemetryMethod · 0.80

Tested by 1

TestNewCmdCommentFunction · 0.56