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

Method ExportData

pkg/cmd/release/shared/fetch.go:89–131  ·  view source on GitHub ↗
(fields []string)

Source from the content-addressed store, hash-verified

87}
88
89func (rel *Release) ExportData(fields []string) map[string]any {
90 v := reflect.ValueOf(rel).Elem()
91 fieldByName := func(v reflect.Value, field string) reflect.Value {
92 return v.FieldByNameFunc(func(s string) bool {
93 return strings.EqualFold(field, s)
94 })
95 }
96 data := map[string]any{}
97
98 for _, f := range fields {
99 switch f {
100 case "author":
101 data[f] = map[string]any{
102 "id": rel.Author.ID,
103 "login": rel.Author.Login,
104 }
105 case "assets":
106 assets := make([]any, 0, len(rel.Assets))
107 for _, a := range rel.Assets {
108 assets = append(assets, map[string]any{
109 "url": a.BrowserDownloadURL,
110 "apiUrl": a.APIURL,
111 "id": a.ID,
112 "name": a.Name,
113 "label": a.Label,
114 "size": a.Size,
115 "digest": a.Digest,
116 "state": a.State,
117 "createdAt": a.CreatedAt,
118 "updatedAt": a.UpdatedAt,
119 "downloadCount": a.DownloadCount,
120 "contentType": a.ContentType,
121 })
122 }
123 data[f] = assets
124 default:
125 sf := fieldByName(v, f)
126 data[f] = sf.Interface()
127 }
128 }
129
130 return data
131}
132
133var ErrReleaseNotFound = errors.New("release not found")
134

Callers

nothing calls this directly

Calls 1

fieldByNameFunction · 0.50

Tested by

no test coverage detected