-
Notifications
You must be signed in to change notification settings - Fork 1
/
gha.go
329 lines (306 loc) · 11.6 KB
/
gha.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package dadsgha
import (
"fmt"
"time"
)
// Event - full GHA (GitHub Archive) event structure
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Public bool `json:"public"`
CreatedAt time.Time `json:"created_at"`
Actor Actor `json:"actor"`
Repo Repo `json:"repo"`
Org *Org `json:"org"`
Payload Payload `json:"payload"`
// Extra fields added by dadsgha
GHADt time.Time `json:"gha_hour"`
GHAFxSlug string `json:"gha_fixture_slug"`
GHAProj string `json:"gha_project"`
GHASuffMap map[string]string `json:"gha_suff_map"`
}
// EventOld - full GHA (GitHub Archive) event structure, before 2015
type EventOld struct {
ID string `json:"-"`
Type string `json:"type"`
Public bool `json:"public"`
CreatedAt time.Time `json:"created_at"`
Actor string `json:"actor"`
Repository ForkeeOld `json:"repository"`
Payload *PayloadOld `json:"payload"`
// Extra fields added by dadsgha
GHADt time.Time `json:"gha_hour"`
GHAFxSlug string `json:"gha_fixture_slug"`
GHAProj string `json:"gha_project"`
GHASuffMap map[string]string `json:"gha_suff_map"`
}
// Payload - GHA Payload structure
type Payload struct {
PushID *int `json:"push_id"`
Size *int `json:"size"`
Ref *string `json:"ref"`
Head *string `json:"head"`
Before *string `json:"before"`
Action *string `json:"action"`
RefType *string `json:"ref_type"`
MasterBranch *string `json:"master_branch"`
Description *string `json:"description"`
Number *int `json:"number"`
Forkee *Forkee `json:"forkee"`
Release *Release `json:"release"`
Member *Actor `json:"member"`
Issue *Issue `json:"issue"`
Comment *Comment `json:"comment"`
Commits *[]Commit `json:"commits"`
Pages *[]Page `json:"pages"`
PullRequest *PullRequest `json:"pull_request"`
}
// PayloadOld - GHA Payload structure (from before 2015)
type PayloadOld struct {
Issue *int `json:"issue"`
IssueID *int `json:"issue_id"`
Comment *Comment `json:"comment"`
CommentID *int `json:"comment_id"`
Description *string `json:"description"`
MasterBranch *string `json:"master_branch"`
Ref *string `json:"ref"`
Action *string `json:"action"`
RefType *string `json:"ref_type"`
Head *string `json:"head"`
Size *int `json:"size"`
Number *int `json:"number"`
PullRequest *PullRequest `json:"pull_request"`
Member *Actor `json:"member"`
Release *Release `json:"release"`
Pages *[]Page `json:"pages"`
Commit *string `json:"commit"`
SHAs *[]interface{} `json:"shas"`
Repository *Forkee `json:"repository"`
Team *Team `json:"team"`
}
// ForkeeOld - GHA Forkee structure (from before 2015)
// Handle missing 4 last properties (including two non-nulls!)
type ForkeeOld struct {
ID int `json:"id"`
CreatedAt time.Time `json:"created_at"`
Description *string `json:"description"`
Fork bool `json:"fork"`
Forks int `json:"forks"`
HasDownloads bool `json:"has_downloads"`
HasIssues bool `json:"has_issues"`
HasWiki bool `json:"has_wiki"`
Homepage *string `json:"homepage"`
Language *string `json:"language"`
DefaultBranch string `json:"master_branch"`
Name string `json:"name"`
OpenIssues int `json:"open_issues"`
Organization *string `json:"organization"`
Owner string `json:"owner"`
Private *bool `json:"private"`
PushedAt *time.Time `json:"pushed_at"`
Size int `json:"size"`
Stargazers int `json:"stargazers"`
Watchers int `json:"watchers"`
}
// Repo - GHA Repo structure
type Repo struct {
ID int `json:"id"`
Name string `json:"name"`
}
// Actor - GHA Actor structure
// Name is unexported and not used by JSON load/save
// But is used when importing affiliations from cncf/gitdm:github_users.json
type Actor struct {
ID int `json:"id"`
Login string `json:"login"`
Name string `json:"-"`
}
// Org - GHA Org structure
type Org struct {
ID int `json:"id"`
Login string `json:"login"`
}
// Forkee - GHA Forkee structure
type Forkee struct {
ID int `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Owner Actor `json:"owner"`
Description *string `json:"description"`
Public *bool `json:"public"`
Fork bool `json:"fork"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PushedAt *time.Time `json:"pushed_at"`
Homepage *string `json:"homepage"`
Size int `json:"size"`
StargazersCount int `json:"stargazers_count"`
HasIssues bool `json:"has_issues"`
HasProjects *bool `json:"has_projects"`
HasDownloads bool `json:"has_downloads"`
HasWiki bool `json:"has_wiki"`
HasPages *bool `json:"has_pages"`
Forks int `json:"forks"`
OpenIssues int `json:"open_issues"`
Watchers int `json:"watchers"`
DefaultBranch string `json:"default_branch"`
}
// Release - GHA Release structure
type Release struct {
ID int `json:"id"`
TagName string `json:"tag_name"`
TargetCommitish string `json:"target_commitish"`
Name *string `json:"name"`
Draft bool `json:"draft"`
Author Actor `json:"author"`
Prerelease bool `json:"prerelease"`
CreatedAt time.Time `json:"created_at"`
PublishedAt *time.Time `json:"published_at"`
Body *string `json:"body"`
Assets []Asset `json:"assets"`
}
// Asset - GHA Asset structure
type Asset struct {
ID int `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Name string `json:"name"`
Label *string `json:"label"`
Uploader Actor `json:"uploader"`
ContentType string `json:"content_type"`
State string `json:"state"`
Size int `json:"size"`
DownloadCount int `json:"download_count"`
}
// PullRequest - GHA Pull Request structure
type PullRequest struct {
ID int64 `json:"id"`
Base Branch `json:"base"`
Head Branch `json:"head"`
User Actor `json:"user"`
Number int `json:"number"`
State string `json:"state"`
Locked *bool `json:"locked"`
Title string `json:"title"`
Body *string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
MergedAt *time.Time `json:"merged_at"`
MergeCommitSHA *string `json:"merge_commit_sha"`
Assignee *Actor `json:"assignee"`
Assignees *[]Actor `json:"assignees"`
RequestedReviewers *[]Actor `json:"requested_reviewers"`
Milestone *Milestone `json:"milestone"`
Merged *bool `json:"merged"`
Mergeable *bool `json:"mergeable"`
MergedBy *Actor `json:"merged_by"`
MergeableState *string `json:"mergeable_state"`
Rebaseable *bool `json:"rebaseable"`
Comments *int `json:"comments"`
ReviewComments *int `json:"review_comments"`
MaintainerCanModify *bool `json:"maintainer_can_modify"`
Commits *int `json:"commits"`
Additions *int `json:"additions"`
Deletions *int `json:"deletions"`
ChangedFiles *int `json:"changed_files"`
}
// Branch - GHA Branch structure
type Branch struct {
SHA string `json:"sha"`
User *Actor `json:"user"`
Repo *Forkee `json:"repo"` // This is confusing, but actually GHA has "repo" fields that holds "forkee" structure
Label string `json:"label"`
Ref string `json:"ref"`
}
// Issue - GHA Issue structure
type Issue struct {
ID int `json:"id"`
Number int `json:"number"`
Comments int `json:"comments"`
Title string `json:"title"`
State string `json:"state"`
Locked bool `json:"locked"`
Body *string `json:"body"`
User Actor `json:"user"`
Assignee *Actor `json:"assignee"`
Labels []Label `json:"labels"`
Assignees []Actor `json:"assignees"`
Milestone *Milestone `json:"milestone"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
PullRequest *struct{} `json:"pull_request"`
}
// Label - GHA Label structure
type Label struct {
ID *int `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Default *bool `json:"default"`
}
// Milestone - GHA Milestone structure
type Milestone struct {
ID int `json:"id"`
Name string `json:"name"`
Number int `json:"number"`
Title string `json:"title"`
Description *string `json:"description"`
Creator *Actor `json:"creator"`
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ClosedAt *time.Time `json:"closed_at"`
DueOn *time.Time `json:"due_on"`
}
// Comment - GHA Comment structure
type Comment struct {
ID int `json:"id"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
User Actor `json:"user"`
CommitID *string `json:"commit_id"`
OriginalCommitID *string `json:"original_commit_id"`
DiffHunk *string `json:"diff_hunk"`
Position *int `json:"position"`
OriginalPosition *int `json:"original_position"`
Path *string `json:"path"`
PullRequestReviewID *int `json:"pull_request_review_id"`
Line *int `json:"line"`
}
// Commit - GHA Commit structure
type Commit struct {
SHA string `json:"sha"`
Author Author `json:"author"`
Message string `json:"message"`
Distinct bool `json:"distinct"`
}
// Author - GHA Commit Author structure
type Author struct {
Name string `json:"name"`
Email string `json:"email"`
}
// Page - GHA Page structure
type Page struct {
SHA string `json:"sha"`
Action string `json:"action"`
Title string `json:"title"`
}
// Team - GHA Team structure (only used before 2015)
type Team struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Permission string `json:"permission"`
}
// MakeOldRepoName - before 2015 repository name should be Organization/Name (if Organization present) or just Name
func MakeOldRepoName(repo *ForkeeOld) string {
if repo.Organization == nil || *repo.Organization == "" {
return repo.Name
}
// FIXME: what if repo.NAME == "" --> "kubernetes/"
return fmt.Sprintf("%s/%s", *repo.Organization, repo.Name)
}