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

Function updateComment

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

Source from the content-addressed store, hash-verified

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