MCPcopy Index your code
hub / github.com/cli/cli / updateComment

Function updateComment

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

Source from the content-addressed store, hash-verified

200}
201
202func updateComment(commentable Commentable, opts *CommentableOptions) error {
203 comments := commentable.CurrentUserComments()
204 if len(comments) == 0 {
205 return errNoUserComments
206 }
207
208 lastComment := &comments[len(comments)-1]
209
210 switch opts.InputType {
211 case InputTypeWeb:
212 openURL := lastComment.Link()
213 if opts.IO.IsStdoutTTY() && !opts.Quiet {
214 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL))
215 }
216 return opts.OpenInBrowser(openURL)
217 case InputTypeEditor:
218 var body string
219 var err error
220 initialValue := lastComment.Content()
221 if opts.Interactive {
222 body, err = opts.InteractiveEditSurvey(initialValue)
223 } else {
224 body, err = opts.EditSurvey(initialValue)
225 }
226 if err != nil {
227 return err
228 }
229 opts.Body = body
230 }
231
232 if opts.Interactive {
233 cont, err := opts.ConfirmSubmitSurvey()
234 if err != nil {
235 return err
236 }
237 if !cont {
238 return errors.New("Discarding...")
239 }
240 }
241
242 httpClient, err := opts.HttpClient()
243 if err != nil {
244 return err
245 }
246
247 apiClient := api.NewClientFromHTTP(httpClient)
248 params := api.CommentUpdateInput{Body: opts.Body, CommentId: lastComment.Identifier()}
249 url, err := api.CommentUpdate(apiClient, opts.Host, params)
250 if err != nil {
251 return err
252 }
253
254 if !opts.Quiet {
255 fmt.Fprintln(opts.IO.Out, url)
256 }
257
258 return nil
259}

Callers 1

CommentableRunFunction · 0.85

Calls 8

DisplayURLFunction · 0.92
NewClientFromHTTPFunction · 0.92
CommentUpdateFunction · 0.92
IsStdoutTTYMethod · 0.80
CurrentUserCommentsMethod · 0.65
LinkMethod · 0.65
ContentMethod · 0.65
IdentifierMethod · 0.65

Tested by

no test coverage detected