MCPcopy Index your code
hub / github.com/cli/cli / ExportData

Method ExportData

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

fieldByNameFunction · 0.50

Tested by

no test coverage detected