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

Function updateComment

pkg/cmd/pr/shared/commentable.go:274–343  ·  view source on GitHub ↗
(commentable Commentable, opts *CommentableOptions, uploader *attachments.Uploader)

Source from the content-addressed store, hash-verified

272}
273
274func updateComment(commentable Commentable, opts *CommentableOptions, uploader *attachments.Uploader) error {
275 comments := commentable.CurrentUserComments()
276 if len(comments) == 0 {
277 return errNoUserComments
278 }
279
280 lastComment := &comments[len(comments)-1]
281
282 switch opts.InputType {
283 case InputTypeWeb:
284 openURL := lastComment.Link()
285 if opts.IO.IsStdoutTTY() && !opts.Quiet {
286 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
287 }
288 return opts.OpenInBrowser(openURL)
289 case InputTypeEditor:
290 var body string
291 var err error
292 initialValue := lastComment.Content()
293 if opts.Interactive {
294 body, err = opts.InteractiveEditSurvey(initialValue)
295 } else {
296 body, err = opts.EditSurvey(initialValue)
297 }
298 if err != nil {
299 return err
300 }
301 opts.Body = body
302 case InputTypeInline:
303 // An explicit `--body ""` still clears the comment. The editor case
304 // above is seeded with the comment already, so it needs no merge.
305 if opts.KeepExistingBody && !opts.BodyProvided {
306 opts.Body = lastComment.Content()
307 }
308 }
309
310 if opts.Interactive {
311 cont, err := opts.ConfirmSubmitSurvey()
312 if err != nil {
313 return err
314 }
315 if !cont {
316 return errors.New("Discarding...")
317 }
318 }
319
320 httpClient, err := opts.HttpClient()
321 if err != nil {
322 return err
323 }
324
325 body, write, uploadErr := bodyForWrite(opts, uploader)
326 if !write {
327 return fmt.Errorf("%w\nthe comment was not changed", uploadErr)
328 }
329
330 apiClient := api.NewClientFromHTTP(httpClient)
331 params := api.CommentUpdateInput{Body: body, CommentId: lastComment.Identifier()}

Callers 1

CommentableRunFunction · 0.85

Calls 11

DisplayURLFunction · 0.92
NewClientFromHTTPFunction · 0.92
CommentUpdateFunction · 0.92
bodyForWriteFunction · 0.85
IsStdoutTTYMethod · 0.80
JoinMethod · 0.80
CurrentUserCommentsMethod · 0.65
LinkMethod · 0.65
ContentMethod · 0.65
ErrorfMethod · 0.65
IdentifierMethod · 0.65

Tested by

no test coverage detected