(commentable Commentable, opts *CommentableOptions, uploader *attachments.Uploader)
| 214 | } |
| 215 | |
| 216 | func createComment(commentable Commentable, opts *CommentableOptions, uploader *attachments.Uploader) error { |
| 217 | switch opts.InputType { |
| 218 | case InputTypeWeb: |
| 219 | openURL := commentable.Link() + "#issuecomment-new" |
| 220 | if opts.IO.IsStdoutTTY() && !opts.Quiet { |
| 221 | fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openURL)) |
| 222 | } |
| 223 | return opts.OpenInBrowser(openURL) |
| 224 | case InputTypeEditor: |
| 225 | var body string |
| 226 | var err error |
| 227 | if opts.Interactive { |
| 228 | body, err = opts.InteractiveEditSurvey("") |
| 229 | } else { |
| 230 | body, err = opts.EditSurvey("") |
| 231 | } |
| 232 | if err != nil { |
| 233 | return err |
| 234 | } |
| 235 | opts.Body = body |
| 236 | } |
| 237 | |
| 238 | if opts.Interactive { |
| 239 | cont, err := opts.ConfirmSubmitSurvey() |
| 240 | if err != nil { |
| 241 | return err |
| 242 | } |
| 243 | if !cont { |
| 244 | return errors.New("Discarding...") |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | httpClient, err := opts.HttpClient() |
| 249 | if err != nil { |
| 250 | return err |
| 251 | } |
| 252 | |
| 253 | body, write, uploadErr := bodyForWrite(opts, uploader) |
| 254 | if !write { |
| 255 | return fmt.Errorf("%w\nno comment was posted", uploadErr) |
| 256 | } |
| 257 | |
| 258 | apiClient := api.NewClientFromHTTP(httpClient) |
| 259 | params := api.CommentCreateInput{Body: body, SubjectId: commentable.Identifier()} |
| 260 | url, err := api.CommentCreate(apiClient, opts.Host, params) |
| 261 | if err != nil { |
| 262 | // Upload first: an uploaded asset outlives the failed write, and the |
| 263 | // user needs to know it exists before hearing the comment did not save. |
| 264 | return errors.Join(uploadErr, err) |
| 265 | } |
| 266 | |
| 267 | if !opts.Quiet { |
| 268 | fmt.Fprintln(opts.IO.Out, url) |
| 269 | } |
| 270 | |
| 271 | return uploadErr |
| 272 | } |
| 273 |
no test coverage detected