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

Method ExportData

pkg/cmd/run/shared/shared.go:164–222  ·  view source on GitHub ↗
(fields []string)

Source from the content-addressed store, hash-verified

162}
163
164func (r *Run) ExportData(fields []string) map[string]interface{} {
165 v := reflect.ValueOf(r).Elem()
166 fieldByName := func(v reflect.Value, field string) reflect.Value {
167 return v.FieldByNameFunc(func(s string) bool {
168 return strings.EqualFold(field, s)
169 })
170 }
171 data := map[string]interface{}{}
172
173 for _, f := range fields {
174 switch f {
175 case "databaseId":
176 data[f] = r.ID
177 case "workflowDatabaseId":
178 data[f] = r.WorkflowID
179 case "workflowName":
180 data[f] = r.WorkflowName()
181 case "jobs":
182 jobs := make([]interface{}, 0, len(r.Jobs))
183 for _, j := range r.Jobs {
184 steps := make([]interface{}, 0, len(j.Steps))
185 for _, s := range j.Steps {
186 var stepCompletedAt time.Time
187 if !s.CompletedAt.IsZero() {
188 stepCompletedAt = s.CompletedAt
189 }
190 steps = append(steps, map[string]interface{}{
191 "name": s.Name,
192 "status": s.Status,
193 "conclusion": s.Conclusion,
194 "number": s.Number,
195 "startedAt": s.StartedAt,
196 "completedAt": stepCompletedAt,
197 })
198 }
199 var jobCompletedAt time.Time
200 if !j.CompletedAt.IsZero() {
201 jobCompletedAt = j.CompletedAt
202 }
203 jobs = append(jobs, map[string]interface{}{
204 "databaseId": j.ID,
205 "status": j.Status,
206 "conclusion": j.Conclusion,
207 "name": j.Name,
208 "steps": steps,
209 "startedAt": j.StartedAt,
210 "completedAt": jobCompletedAt,
211 "url": j.URL,
212 })
213 }
214 data[f] = jobs
215 default:
216 sf := fieldByName(v, f)
217 data[f] = sf.Interface()
218 }
219 }
220
221 return data

Callers

nothing calls this directly

Calls 2

WorkflowNameMethod · 0.95
fieldByNameFunction · 0.50

Tested by

no test coverage detected