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

Function attach

pkg/cmd/issue/artifact/create/create.go:444–478  ·  view source on GitHub ↗

attach uploads the --attach files, each once, and points every Markdown document at the files it references. Artifacts whose type doesn't support attachments, such as links and HTML documents, are left out. With one Markdown document, the files it doesn't reference are appended to it. Uploads can't

(opts *CreateOptions, uploader *attachments.Uploader, artifacts []artifact)

Source from the content-addressed store, hash-verified

442// uploaded, even when another failed, and that failure is the reason on its
443// result line. A document none of whose files uploaded isn't saved.
444func attach(opts *CreateOptions, uploader *attachments.Uploader, artifacts []artifact) error {
445 var docs []attachments.Document
446 var indexes []int
447 for i, a := range artifacts {
448 if !shared.SupportsAttachments(a.artifactType) {
449 continue
450 }
451 docs = append(docs, attachments.Document{Markdown: a.body, Dir: a.dir})
452 indexes = append(indexes, i)
453 }
454
455 results, err := uploader.UploadAndAttachDocuments(context.Background(), docs, opts.Assets)
456 var operations attachments.UploadResult
457 for _, r := range results {
458 operations.AppendOperations += r.AppendOperations
459 operations.ReplaceOperations += r.ReplaceOperations
460 }
461 opts.AttachEvent.RecordOperations(operations)
462
463 // Without results, the files were refused before anything uploaded.
464 if len(results) == 0 {
465 if unreferenced, ok := errors.AsType[*attachments.UnreferencedError](err); ok {
466 return unreferencedError(unreferenced.Paths)
467 }
468 return err
469 }
470
471 for j, r := range results {
472 a := &artifacts[indexes[j]]
473 a.body = r.Markdown
474 a.attachErr = r.Err
475 a.skip = r.Err != nil && len(r.Uploaded) == 0
476 }
477 return nil
478}
479
480// unreferencedError explains attached files that no document references,
481// when there are several documents and none to append them to.

Callers 1

createRunFunction · 0.85

Calls 4

SupportsAttachmentsFunction · 0.92
unreferencedErrorFunction · 0.85
RecordOperationsMethod · 0.80

Tested by

no test coverage detected