-
Notifications
You must be signed in to change notification settings - Fork 5
/
scheme.go
181 lines (159 loc) · 5.53 KB
/
scheme.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package main
import (
"regexp"
"strings"
"time"
)
// Body is Github GraphQL api response body
type Body struct {
Data *GithubData `json:"data"`
}
// GithubData is Github GraphQL api data
type GithubData struct {
Repository *Repository `json:"repository"`
Viewer *User `json:"user"`
Organization *Organization `json:"organization"`
}
// PageInfo is Github GraphQL api page data info
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
EndCursor string `json:"endCursor"`
HasPrevPage bool `json:"-"`
StartCursor string `json:"-"`
}
// Repository is Github repository scheme
type Repository struct {
Name string `json:"name"`
URL string `json:"url"`
Labels *LabelPage `json:"labels"`
Categories *CategoryPage `json:"discussionCategories"`
Discussions *DiscussionPage `json:"discussions"`
Discussion *Discussion `json:"discussion"`
}
// CategoryPage is Github discussion category page scheme
type CategoryPage struct {
TotalCount int `json:"totalCount"`
Nodes []*Category `json:"nodes"`
}
// Category is Github discussion category scheme
type Category struct {
Emoji string `json:"emoji"`
EmojiHTML string `json:"emojiHTML"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Discussions *DiscussionPage `json:"-"`
}
// InvaildFileNameRegex 无效的文件名字符正则表达式
var InvaildFileNameRegex = regexp.MustCompile(`[<>:"/\\|?*\x00-\x1f]`)
// Slug 返回分类的合法的 url 名称,将其中无效的文件名替换为 '-'
func (c *Category) Slug() string {
return InvaildFileNameRegex.ReplaceAllString(c.Name, "-")
}
// LabelPage is Github discussion label page scheme
type LabelPage struct {
TotalCount int `json:"totalCount"`
Nodes []*Label `json:"nodes"`
}
// Label is Github label(discussion and issue) scheme
type Label struct {
Color string `json:"color"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Discussions *DiscussionPage `json:"-"`
}
// Slug 返回标签的合法的 url 名称,将其中无效的文件名替换为 '-'
func (l *Label) Slug() string {
return InvaildFileNameRegex.ReplaceAllString(l.Name, "-")
}
// String 返回标签的名称列表
func (p LabelPage) String() string {
var labels []string
for _, label := range p.Nodes {
labels = append(labels, label.Name)
}
return "[" + strings.Join(labels, ", ") + "]"
}
// DiscussionPage is Github Discussion page scheme
type DiscussionPage struct {
TotalCount int `json:"totalCount"`
Nodes []*Discussion `json:"nodes"`
PageInfo *PageInfo `json:"pageInfo"`
}
// Discussion is Github Discussion scheme
type Discussion struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
BodyHTML string `json:"bodyHTML"`
Locked bool `json:"locked"`
UpvoteCount int `json:"upvoteCount"`
GitHubURL string `json:"url"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Author *User `json:"author"`
Category *Category `json:"category"`
Labels *LabelPage `json:"labels"`
Comments *CommentPage `json:"comments"`
ReactionGroups []*ReactionGroup `json:"reactionGroups"`
}
// CommentPage is Github Discussion Comment page scheme
type CommentPage struct {
TotalCount int `json:"totalCount"`
Nodes []*Comment `json:"nodes"`
PageInfo *PageInfo `json:"pageInfo"`
}
// Comment is Github Discussion comment scheme
type Comment struct {
Body string `json:"body"`
BodyHTML string `json:"bodyHTML"`
UpvoteCount int `json:"upvoteCount"`
GitHubURL string `json:"url"`
AuthorAssociation string `json:"authorAssociation"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Author *User `json:"author"`
ReactionGroups []*ReactionGroup `json:"reactionGroups"`
}
// ReactionGroup is Github Discussion Reaction group scheme
type ReactionGroup struct {
Content string `json:"content"`
Reactors *ReactionPage `json:"reactors"`
}
// ReactionPage is Github Discussion Reaction page scheme
type ReactionPage struct {
TotalCount int `json:"totalCount"`
}
// User is Github user scheme
type User struct {
Login string `json:"login"`
AvatarURL string `json:"avatarUrl"`
GitHubURL string `json:"url"`
Bio string `json:"bio"`
Email string `json:"email"`
Company string `json:"company"`
Location string `json:"location"`
Name string `json:"name"`
Twitter string `json:"twitterUsername"`
}
// ShowName 返回该用户的对外显示的名字
func (u *User) ShowName() string {
if u.Name != "" {
return u.Name
}
return u.Login
}
// Organization is Github organization scheme
type Organization struct {
Login string `json:"login"`
AvatarURL string `json:"avatarUrl"`
GitHubURL string `json:"url"`
Bio string `json:"description"`
Email string `json:"email"`
Location string `json:"location"`
Name string `json:"name"`
Twitter string `json:"twitterUsername"`
}