forked from muesli/markscribe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
195 lines (173 loc) · 4.06 KB
/
types.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package main
import (
"time"
"github.com/shurcooL/githubv4"
)
// Contribution represents a contribution to a repo.
type Contribution struct {
OccurredAt time.Time
Repo Repo
}
// Gist represents a gist.
type Gist struct {
Name string
Description string
URL string
CreatedAt time.Time
}
// Star represents a star/favorite event.
type Star struct {
StarredAt time.Time
Repo Repo
}
// PullRequest represents a pull request.
type PullRequest struct {
Title string
URL string
State string
CreatedAt time.Time
Repo Repo
}
// Release represents a release.
type Release struct {
Name string
TagName string
PublishedAt time.Time
CreatedAt time.Time
URL string
IsLatest bool
IsPreRelease bool
IsDraft bool
}
// Repo represents a git repo.
type Repo struct {
Owner string
Name string
NameWithOwner string
URL string
Description string
IsPrivate bool
Stargazers int
LastRelease Release
}
// Sponsor represents a sponsor.
type Sponsor struct {
User User
CreatedAt time.Time
}
// User represents a SCM user.
type User struct {
Login string
Name string
AvatarURL string
URL string
}
type qlGist struct {
Name githubv4.String
Description githubv4.String
URL githubv4.String
CreatedAt githubv4.DateTime
}
type qlPullRequest struct {
URL githubv4.String
Title githubv4.String
State githubv4.PullRequestState
CreatedAt githubv4.DateTime
Repository qlRepository
}
type qlRelease struct {
Name githubv4.String
TagName githubv4.String
PublishedAt githubv4.DateTime
CreatedAt githubv4.DateTime
URL githubv4.String
IsPrerelease githubv4.Boolean
IsLatest githubv4.Boolean
IsDraft githubv4.Boolean
}
type qlReleases struct {
Nodes []struct {
Name githubv4.String
TagName githubv4.String
PublishedAt githubv4.DateTime
CreatedAt githubv4.DateTime
URL githubv4.String
IsPrerelease githubv4.Boolean
IsLatest githubv4.Boolean
IsDraft githubv4.Boolean
}
}
type qlRepository struct {
Owner struct {
Login githubv4.String
}
Name githubv4.String
NameWithOwner githubv4.String
URL githubv4.String
Description githubv4.String
IsPrivate githubv4.Boolean
Stargazers struct {
TotalCount githubv4.Int
}
}
type qlUser struct {
Login githubv4.String
Name githubv4.String
AvatarURL githubv4.String
URL githubv4.String
}
func gistFromQL(gist qlGist) Gist {
return Gist{
Name: string(gist.Name),
Description: string(gist.Description),
URL: string(gist.URL),
CreatedAt: gist.CreatedAt.Time,
}
}
func pullRequestFromQL(pullRequest qlPullRequest) PullRequest {
return PullRequest{
Title: string(pullRequest.Title),
URL: string(pullRequest.URL),
State: string(pullRequest.State),
CreatedAt: pullRequest.CreatedAt.Time,
Repo: repoFromQL(pullRequest.Repository),
}
}
func releaseFromQL(release qlRelease) Release {
return Release{
Name: string(release.Name),
TagName: string(release.TagName),
PublishedAt: release.PublishedAt.Time,
URL: string(release.URL),
}
}
func releasesFromQL(release qlReleases) Release {
if len(release.Nodes) != 0 {
return Release{
Name: string(release.Nodes[0].Name),
TagName: string(release.Nodes[0].TagName),
PublishedAt: release.Nodes[0].PublishedAt.Time,
URL: string(release.Nodes[0].URL),
}
}
return Release{}
}
func repoFromQL(repo qlRepository) Repo {
return Repo{
Owner: string(repo.Owner.Login),
Name: string(repo.Name),
NameWithOwner: string(repo.NameWithOwner),
URL: string(repo.URL),
Description: string(repo.Description),
Stargazers: int(repo.Stargazers.TotalCount),
IsPrivate: bool(repo.IsPrivate),
}
}
func userFromQL(user qlUser) User {
return User{
Login: string(user.Login),
Name: string(user.Name),
AvatarURL: string(user.AvatarURL),
URL: string(user.URL),
}
}