newBody returns the body to save, checked against the artifact's type, or nil to keep the current body. Only a type that supports attachments takes --attach, and links and HTML documents don't. A link's new content must be an http(s) URL: a .url file is read as a shortcut, and anything else must be
(opts *EditOptions, a client.Artifact, content *string)
| 281 | // Markdown or HTML document, which never takes a .url file. With only |
| 282 | // --attach, the files are appended to a Markdown document's current body. |
| 283 | func newBody(opts *EditOptions, a client.Artifact, content *string) (*string, error) { |
| 284 | if len(opts.Assets) > 0 && !shared.SupportsAttachments(a.Type) { |
| 285 | if a.Type == client.TypeEmbeddedHTML { |
| 286 | return nil, errors.New("`--attach` can't be used with HTML artifacts") |
| 287 | } |
| 288 | return nil, fmt.Errorf("artifact %d is a %s; `--attach` can't be used with %s artifacts", a.Number, a.Type, a.Type) |
| 289 | } |
| 290 | if a.Type != client.TypeLink { |
| 291 | if shared.IsShortcutFile(opts.BodyFile) { |
| 292 | return nil, fmt.Errorf("artifact %d is not a link; .url files can only update link artifacts", a.Number) |
| 293 | } |
| 294 | if content == nil && len(opts.Assets) > 0 { |
| 295 | return &a.Body, nil |
| 296 | } |
| 297 | return content, nil |
| 298 | } |
| 299 | |
| 300 | if content == nil { |
| 301 | return nil, nil |
| 302 | } |
| 303 | if shared.IsShortcutFile(opts.BodyFile) { |
| 304 | u, err := shared.ShortcutURL(*content) |
| 305 | if errors.Is(err, shared.ErrNoShortcutSection) { |
| 306 | return nil, fmt.Errorf("%s: %w; pass the URL with `--body` instead", opts.BodyFile, err) |
| 307 | } else if err != nil { |
| 308 | return nil, fmt.Errorf("%s: %w", opts.BodyFile, err) |
| 309 | } |
| 310 | return &u, nil |
| 311 | } |
| 312 | u, ok := shared.HTTPURL(*content) |
| 313 | if !ok { |
| 314 | return nil, fmt.Errorf("artifact %d is a link; pass an http(s) URL with `--body` or a .url file with `--body-file`", a.Number) |
| 315 | } |
| 316 | return &u, nil |
| 317 | } |
no test coverage detected