MCPcopy
hub / github.com/cli/cli / deleteComment

Function deleteComment

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

Source from the content-addressed store, hash-verified

259}
260
261func deleteComment(commentable Commentable, opts *CommentableOptions) error {
262 comments := commentable.CurrentUserComments()
263 if len(comments) == 0 {
264 return errNoUserComments
265 }
266
267 lastComment := comments[len(comments)-1]
268
269 cs := opts.IO.ColorScheme()
270
271 if opts.Interactive && !opts.DeleteLastConfirmed {
272 // This is not an ideal way of truncating a random string that may
273 // contain emojis or other kind of wide chars.
274 truncated := lastComment.Body
275 if len(lastComment.Body) > 40 {
276 truncated = lastComment.Body[:40] + "..."
277 }
278
279 fmt.Fprintf(opts.IO.Out, "%s Deleted comments cannot be recovered.\n", cs.WarningIcon())
280 ok, err := opts.ConfirmDeleteLastComment(truncated)
281 if err != nil {
282 return err
283 }
284 if !ok {
285 return errDeleteNotConfirmed
286 }
287 }
288
289 httpClient, err := opts.HttpClient()
290 if err != nil {
291 return err
292 }
293
294 apiClient := api.NewClientFromHTTP(httpClient)
295 params := api.CommentDeleteInput{CommentId: lastComment.Identifier()}
296 deletionErr := api.CommentDelete(apiClient, opts.Host, params)
297 if deletionErr != nil {
298 return deletionErr
299 }
300
301 if !opts.Quiet {
302 fmt.Fprintln(opts.IO.ErrOut, "Comment deleted")
303 }
304
305 return nil
306}
307
308func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) {
309 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