forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_repo.go
53 lines (48 loc) · 1.13 KB
/
export_repo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package api
import (
"reflect"
)
func (repo *Repository) ExportData(fields []string) map[string]interface{} {
v := reflect.ValueOf(repo).Elem()
data := map[string]interface{}{}
for _, f := range fields {
switch f {
case "parent":
data[f] = miniRepoExport(repo.Parent)
case "templateRepository":
data[f] = miniRepoExport(repo.TemplateRepository)
case "languages":
data[f] = repo.Languages.Edges
case "labels":
data[f] = repo.Labels.Nodes
case "assignableUsers":
data[f] = repo.AssignableUsers.Nodes
case "mentionableUsers":
data[f] = repo.MentionableUsers.Nodes
case "milestones":
data[f] = repo.Milestones.Nodes
case "projects":
data[f] = repo.Projects.Nodes
case "repositoryTopics":
var topics []RepositoryTopic
for _, n := range repo.RepositoryTopics.Nodes {
topics = append(topics, n.Topic)
}
data[f] = topics
default:
sf := fieldByName(v, f)
data[f] = sf.Interface()
}
}
return data
}
func miniRepoExport(r *Repository) map[string]interface{} {
if r == nil {
return nil
}
return map[string]interface{}{
"id": r.ID,
"name": r.Name,
"owner": r.Owner,
}
}