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

Function deleteComment

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

Source from the content-addressed store, hash-verified

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