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

Function appendUnreferenced

internal/attachments/attach.go:61–76  ·  view source on GitHub ↗

appendUnreferenced adds a paragraph for every attachment the author never referenced, in the order they were attached. Each one renders itself, since an image appends a markdown embed and a video appends a bare URL so that it plays, which is why this half does not live with the rewriting.

(attachedMD attachedMarkdown, assets []UserAsset)

Source from the content-addressed store, hash-verified

59// an image appends a markdown embed and a video appends a bare URL so that it
60// plays, which is why this half does not live with the rewriting.
61func appendUnreferenced(attachedMD attachedMarkdown, assets []UserAsset) string {
62 urlByPath := make(map[string]string, len(attachedMD.ToAppend))
63 for _, arg := range attachedMD.ToAppend {
64 urlByPath[arg.Path] = arg.URL
65 }
66
67 out := attachedMD.Rewritten
68 for _, a := range assets {
69 url, ok := urlByPath[a.Path()]
70 if !ok {
71 continue
72 }
73 out = appendParagraph(out, a.markdown(url))
74 }
75 return out
76}
77
78// appendParagraph joins two pieces of markdown as separate paragraphs.
79func appendParagraph(md, addition string) string {

Callers 1

UploadAndAttachMethod · 0.85

Calls 3

appendParagraphFunction · 0.85
PathMethod · 0.65
markdownMethod · 0.65

Tested by

no test coverage detected