MCPcopy
hub / github.com/cli/cli / createComment

Function createComment

pkg/cmd/pr/shared/commentable.go:151–200  ·  view source on GitHub ↗
(commentable Commentable, opts *CommentableOptions)

Source from the content-addressed store, hash-verified

149}
150
151func createComment(commentable Commentable, opts *CommentableOptions) error {
152 switch opts.InputType {
153 case InputTypeWeb:
154 openURL := commentable.Link() + "#issuecomment-new"
155 if opts.IO.IsStdoutTTY() && !opts.Quiet {
156 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
157 }
158 return opts.OpenInBrowser(openURL)
159 case InputTypeEditor:
160 var body string
161 var err error
162 if opts.Interactive {
163 body, err = opts.InteractiveEditSurvey("")
164 } else {
165 body, err = opts.EditSurvey("")
166 }
167 if err != nil {
168 return err
169 }
170 opts.Body = body
171 }
172
173 if opts.Interactive {
174 cont, err := opts.ConfirmSubmitSurvey()
175 if err != nil {
176 return err
177 }
178 if !cont {
179 return errors.New("Discarding...")
180 }
181 }
182
183 httpClient, err := opts.HttpClient()
184 if err != nil {
185 return err
186 }
187
188 apiClient := api.NewClientFromHTTP(httpClient)
189 params := api.CommentCreateInput{Body: opts.Body, SubjectId: commentable.Identifier()}
190 url, err := api.CommentCreate(apiClient, opts.Host, params)
191 if err != nil {
192 return err
193 }
194
195 if !opts.Quiet {
196 fmt.Fprintln(opts.IO.Out, url)
197 }
198
199 return nil
200}
201
202func updateComment(commentable Commentable, opts *CommentableOptions) error {
203 comments := commentable.CurrentUserComments()

Callers 1

CommentableRunFunction · 0.85

Calls 6

DisplayURLFunction · 0.92
NewClientFromHTTPFunction · 0.92
CommentCreateFunction · 0.92
IsStdoutTTYMethod · 0.80
LinkMethod · 0.65
IdentifierMethod · 0.65

Tested by

no test coverage detected