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

Function deleteComment

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

Source from the content-addressed store, hash-verified

361}
362
363func deleteComment(commentable Commentable, opts *CommentableOptions) error {
364 comments := commentable.CurrentUserComments()
365 if len(comments) == 0 {
366 return errNoUserComments
367 }
368
369 lastComment := comments[len(comments)-1]
370
371 cs := opts.IO.ColorScheme()
372
373 if opts.Interactive && !opts.DeleteLastConfirmed {
374 // This is not an ideal way of truncating a random string that may
375 // contain emojis or other kind of wide chars.
376 truncated := lastComment.Body
377 if len(lastComment.Body) > 40 {
378 truncated = lastComment.Body[:40] + "..."
379 }
380
381 fmt.Fprintf(opts.IO.Out, "%s Deleted comments cannot be recovered.\n", cs.WarningIcon())
382 ok, err := opts.ConfirmDeleteLastComment(truncated)
383 if err != nil {
384 return err
385 }
386 if !ok {
387 return errDeleteNotConfirmed
388 }
389 }
390
391 httpClient, err := opts.HttpClient()
392 if err != nil {
393 return err
394 }
395
396 apiClient := api.NewClientFromHTTP(httpClient)
397 params := api.CommentDeleteInput{CommentId: lastComment.Identifier()}
398 deletionErr := api.CommentDelete(apiClient, opts.Host, params)
399 if deletionErr != nil {
400 return deletionErr
401 }
402
403 if !opts.Quiet {
404 fmt.Fprintln(opts.IO.ErrOut, "Comment deleted")
405 }
406
407 return nil
408}
409
410func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) {
411 return func() (bool, error) {

Callers 1

CommentableRunFunction · 0.85

Calls 6

NewClientFromHTTPFunction · 0.92
CommentDeleteFunction · 0.92
ColorSchemeMethod · 0.80
WarningIconMethod · 0.80
CurrentUserCommentsMethod · 0.65
IdentifierMethod · 0.65

Tested by

no test coverage detected