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

Function updateComment

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

Source from the content-addressed store, hash-verified

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