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

Function CommentablePreRun

pkg/cmd/pr/shared/commentable.go:70–152  ·  view source on GitHub ↗
(cmd *cobra.Command, opts *CommentableOptions, telemetry ghtelemetry.InvocationRecorder)

Source from the content-addressed store, hash-verified

68}
69
70func CommentablePreRun(cmd *cobra.Command, opts *CommentableOptions, telemetry ghtelemetry.InvocationRecorder) error {
71 inputFlags := 0
72 if cmd.Flags().Changed("body") {
73 opts.InputType = InputTypeInline
74 opts.BodyProvided = true
75 inputFlags++
76 }
77 if cmd.Flags().Changed("body-file") {
78 opts.InputType = InputTypeInline
79 opts.BodyProvided = true
80 inputFlags++
81 }
82 web, _ := cmd.Flags().GetBool("web")
83 if web {
84 opts.InputType = InputTypeWeb
85 inputFlags++
86 }
87 if editor, _ := cmd.Flags().GetBool("editor"); editor {
88 opts.InputType = InputTypeEditor
89 inputFlags++
90 }
91
92 if err := cmdutil.MutuallyExclusive(
93 "`--attach` is not supported when using `--web`",
94 opts.AttachFlag.Changed(),
95 web,
96 ); err != nil {
97 return err
98 }
99
100 if err := cmdutil.MutuallyExclusive(
101 "`--attach` is not supported when using `--delete-last`",
102 opts.AttachFlag.Changed(),
103 opts.DeleteLast,
104 ); err != nil {
105 return err
106 }
107
108 var err error
109 opts.AttachEvent = attachments.BeginTelemetry(telemetry, cmd.CommandPath(), opts.AttachFlag.Count())
110 opts.Assets, err = opts.AttachFlag.UserAssets()
111 if err != nil {
112 return err
113 }
114
115 // An asset is a body input on its own, so `--attach shot.png` alone
116 // posts an image with no text. It is not part of the mutually exclusive
117 // group above, so it only counts when nothing else has.
118 if len(opts.Assets) > 0 && inputFlags == 0 {
119 opts.InputType = InputTypeInline
120 inputFlags++
121 }
122
123 if opts.CreateIfNone && !opts.EditLast {
124 return cmdutil.FlagErrorf("`--create-if-none` can only be used with `--edit-last`")
125 }
126
127 if opts.DeleteLastConfirmed && !opts.DeleteLast {

Callers 2

NewCmdCommentFunction · 0.92
TestCommentablePreRunFunction · 0.85

Calls 7

MutuallyExclusiveFunction · 0.92
BeginTelemetryFunction · 0.92
FlagErrorfFunction · 0.92
ChangedMethod · 0.80
UserAssetsMethod · 0.80
CanPromptMethod · 0.80
CountMethod · 0.45

Tested by 1

TestCommentablePreRunFunction · 0.68