This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.go
374 lines (346 loc) · 12.1 KB
/
webhook.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
package gitlab_webhook_parse
import (
"time"
"strings"
)
type customTime struct {
time.Time
}
func (t customTime) UnmarshalJSON(b []byte) (err error) {
layout := []string{
"2006-01-02 15:04:05 MST",
time.RFC3339,
}
s := strings.Trim(string(b), "\"")
if s == "null" {
t.Time = time.Time{}
return
}
for _, l := range (layout) {
t.Time, err = time.Parse(l, s)
if err == nil {
break
}
}
return
}
type IssueEvent struct {
ObjectKind string `json:"object_kind"`
User User `json:"user"`
Project Project `json:"project"`
Repository Repository `json:"repository"`
ObjectAttributes ObjectAttributes `json:"object_attributes"`
Assignee Assignee `json:"assignee"`
}
type MergeRequestEvent struct {
ObjectKind string `json:"object_kind"`
User User `json:"user"`
ObjectAttributes ObjectAttributes `json:"object_attributes"`
}
type PushEvent struct {
ObjectKind string `json:"object_kind"`
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
CheckoutSha string `json:"checkout_sha"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserEmail string `json:"user_email"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project Project `json:"Project"`
Repository Repository `json:"repository"`
Commits []Commit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
type TagEvent struct {
ObjectKind string `json:"object_kind"`
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
CheckoutSha string `json:"checkout_sha"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserAvatar string `json:"user_avatar"`
ProjectID int `json:"project_id"`
Project Project `json:"Project"`
Repository Repository `json:"repository"`
Commits []Commit `json:"commits"`
TotalCommitsCount int `json:"total_commits_count"`
}
type WikiPageEvent struct {
ObjectKind string `json:"object_kind"`
User User `json:"user"`
Project Project `json:"project"`
Wiki Wiki `json:"wiki"`
ObjectAttributes ObjectAttributes `json:"object_attributes"`
}
type PipelineEvent struct {
ObjectKind string `json:"object_kind"`
User User `json:"user"`
Project Project `json:"project"`
Commit Commit `json:"commit"`
ObjectAttributes ObjectAttributes `json:"object_attributes"`
Builds []Build `json:"builds"`
}
type CommentEvent struct {
ObjectKind string `json:"object_kind"`
User User `json:"user"`
ProjectID int `json:"project_id"`
Project Project `json:"project"`
Repository Repository `json:"repository"`
ObjectAttributes ObjectAttributes `json:"object_attributes"`
Commit Commit `json:"commit"`
Issue Issue `json:"issue"`
Snippet Snippet `json:"snippet"`
}
type BuildEvent struct {
ObjectKind string `json:"object_kind"`
Ref string `json:"ref"`
Tag bool `json:"tag"`
BeforeSha string `json:"before_sha"`
Sha string `json:"sha"`
BuildId int `json:"build_id"`
BuildName string `json:"build_name"`
BuildStage string `json:"build_stage"`
BuildStatus string `json:"build_status"`
BuildStartedAt customTime `json:"build_started_at"`
BuildFinishedAt customTime `json:"build_finished_at"`
BuildDuration int `json:"build_duration"`
BuildAllowFailure bool `json:"build_allow_failure"`
ProjectID int `json:"project_id"`
ProjectName string `json:project_name"`
User User `json:"user"`
Commit BuildCommit `json:"commit"`
Repository Repository `json"repository"`
}
type Issue struct {
ID int `json:"id"`
Title string `json:"title"`
AssigneeID int `json:"assignee_id"`
AuthorID int `json:"author_id"`
ProjectID int `json:"project_id"`
CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"`
Position int `json:"position"`
BranchName string `json:"branch_name"`
Description string `json:"description"`
MilestoneID int `json:"milestone_id"`
State string `json:"state"`
IID int `json:"iid"`
}
type Build struct {
ID int `json:"id"`
Stage string `json:"stage"`
Name string `json:"name"`
Status string `json:"status"`
CreatedAt customTime `json:"created_at"`
StartedAt customTime `json:"started_at"`
FinishedAt customTime `json:"finished_at"`
When string `json:"when"`
Manual bool `json:"manual"`
User User `json:"user"`
Runner string `json:"runner"`
ArtifactsFile Artifactsfile `json:"artifactsfile"`
}
type Artifactsfile struct {
Filename string `json:"filename"`
Size string `json:"size"`
}
type Wiki struct {
WebURL string "web_url"
GitSshURL string "git_ssh_url"
GitHttpURL string "git_http_url"
PathWithNamespace string "path_with_namespace"
DefaultBranch string "default_branch"
}
type Commit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp customTime `json:"timestamp"`
URL string `json:"url"`
Author Author `json:"author"`
Added []string `json:"added"`
Modified []string `json:"modified"`
Removed []string `json:"removed"`
}
type BuildCommit struct {
ID int `json:"id"`
Sha string `json:"sha"`
Message string `json:"message"`
AuthorName string `json:"auuthor_name"`
AuthorEmail string `json:"author_email"`
Status string `json:"status"`
Duration int `json:"duration"`
StartedAt customTime `json:"started_at"`
FinishedAt customTime `json:"finished_at"`
}
type Snippet struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
AuthorID int `json:"author_id"`
ProjectID int `json:"project_id"`
CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"`
FileName string `json:"file_name"`
ExpiresAt customTime `json:"expires_at"`
Type string `json:"type"`
VisibilityLevel int "visibility_level"
}
type User struct {
Name string `json:"name"`
UserName string `json:"username"`
AvatarURL string `json:"avatar_url"`
}
type Project struct {
Name string `json"name"`
Description string "description"
WebURL string "web_url"
AvatarURL string "avatar_url"
GitSshURL string "git_ssh_url"
GitHttpURL string "git_http_url"
Namespace string "namespace"
VisibilityLevel int "visibility_level"
PathWithNamespace string "path_with_namespace"
DefaultBranch string "default_branch"
Homepage string "homepage"
URL string "url"
SshURL string "ssh_url"
HttpURL string "http_url"
}
type Repository struct {
Name string `json:"name"`
Url string `json:"url"`
Description string `json:"description"`
Homepage string `json:"homepage"`
}
type ObjectAttributes struct {
ID int `json:"id"`
Title string `json:"title"`
AssigneeID int `json:"assignee_id"`
AuthorID int `json:"author_id"`
ProjectID int `json:"project_id"`
CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"`
Position int `json:"position"`
BranchName string `json:"branch_name"`
Description string `json:"description"`
MilestoneID int `json:"milestone_id"`
State string `json:"state"`
IID int `json:"iid"`
URL string `json:"url"`
Action string `json:"action"`
TargetBranch string `json:"target_branch"`
SourceBranch string `json:"source_branch"`
SourceProjectId int `json:"source_project_id"`
TargetProjectID int `json:"target_project_id"`
StCommits string `json:"st_commits"`
MergeStatus string `json:"merge_status"`
Content string `json:"content"`
Format string `json:"format"`
Message string `json:"message"`
Slug string `json:"slug"`
Ref string `json:"ref"`
Tag bool `json:"tag"`
Sha string `json:"sha"`
BeforeSha string `json:"before_sha"`
Status string `json:"status"`
Stages []string `json:"stages"`
Duration int `json:"duration"`
Note string `json:"note"`
NotebookType string `json:"noteable_type"`
At customTime `json:"attachment"`
LineCode string `json:"line_code"`
CommitID string `json:"commit_id"`
NoteableID int `json:"noteable_id"`
System bool `json:"system"`
WorkInProgress bool `json:"work_in_progress"`
StDiffs []StDiff `json:"st_diffs"`
Source Source `json:"source"`
Target Target `json:"target"`
LastCommit LastCommit `json:"last_commit"`
Assignee Assignee `json:"assignee"`
}
type MergeRequest struct {
ID int `json:"id"`
TargetBranch string `json:"target_branch"`
SourceBranch string `json:"source_branch"`
SourceProjectId string `json:"source_project_id"`
AssigneeID int `json:"assignee_id"`
AuthorID int `json:"author_id"`
Title string `json:"title"`
CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"`
MilestoneID int `json:"milestone_id"`
State string `json:"state"`
MergeStatus string `json:"merge_status"`
TargetProjectID int `json:"target_project_id"`
IID int `json:"iid"`
Description string `json:"description"`
Position int `json:"position"`
LockedAt customTime `"locked_at"`
Source Source `json:"source"`
Target Target `json:"target"`
LastCommit LastCommit `json:"last_commit"`
WorkInProgress bool `json:"work_in_progress"`
Assignee Assignee `json:"assignee"`
}
type Assignee struct {
Name string `json"name"`
Username string `json:"username"`
AvatarURL string `json:"avatar_url"`
}
type StDiff struct {
Diff string `"diff"`
NewPath string `json:"new_path"`
OldPath string `json:"old_path"`
AMode string `json:"a_mode"`
BMode string `json:"b_mode"`
NewFile bool `json:"new_file"`
RenamedFile bool `json:"renamed_file"`
DeletedFile bool `json:"deleted_file"`
}
type Source struct {
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
GitSshURL string `json:"git_ssh_url"`
GitHttpURL string `json:"git_http_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
Homepage string `json:"homepage"`
URL string `json:"url"`
SshURL string `json:"ssh_url"`
HttpURL string `json:"http_url"`
}
type Target struct {
Name string `json:"name"`
Description string `json:"description"`
WebURL string `json:"web_url"`
AvatarURL string `json:"avatar_url"`
GitSshURL string `json:"git_ssh_url"`
GitHttpURL string `json:"git_http_url"`
Namespace string `json:"namespace"`
VisibilityLevel int `json"visibility_level"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
Homepage string `json:"homepage"`
URL string `json:"url"`
SshURL string `json:"ssh_url"`
HttpURL string `json:"http_url"`
}
type LastCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Timestamp customTime `json:"timestamp"`
URL string `json:"url"`
Author Author `json:"author"`
}
type Author struct {
Name string `json:"name"`
Email string `json:"email"`
}