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

Function deleteComment

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

Source from the content-addressed store, hash-verified

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