Skip to content

Commit b6a3080

Browse files
authored
Merge pull request #123 from shaheed121/fix_gitlab_payload
Modify Gitlab Job and Pipeline events
2 parents 5fcf4a6 + b79b935 commit b6a3080

File tree

3 files changed

+283
-232
lines changed

3 files changed

+283
-232
lines changed

gitlab/payload.go

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ type PipelineEventPayload struct {
112112
Project Project `json:"project"`
113113
Commit Commit `json:"commit"`
114114
ObjectAttributes PipelineObjectAttributes `json:"object_attributes"`
115-
Jobs []Job `json:"jobs"`
115+
MergeRequest MergeRequest `json:"merge_request"`
116+
Builds []Build `json:"builds"`
116117
}
117118

118119
// CommentEventPayload contains the information for GitLab's comment event
@@ -153,25 +154,27 @@ type BuildEventPayload struct {
153154

154155
// JobEventPayload contains the information for GitLab's Job status change
155156
type JobEventPayload struct {
156-
ObjectKind string `json:"object_kind"`
157-
Ref string `json:"ref"`
158-
Tag bool `json:"tag"`
159-
BeforeSHA string `json:"before_sha"`
160-
SHA string `json:"sha"`
161-
JobID int64 `json:"Job_id"`
162-
JobName string `json:"Job_name"`
163-
JobStage string `json:"Job_stage"`
164-
JobStatus string `json:"Job_status"`
165-
JobStartedAt customTime `json:"Job_started_at"`
166-
JobFinishedAt customTime `json:"Job_finished_at"`
167-
JobDuration int64 `json:"Job_duration"`
168-
Job bool `json:"Job"`
169-
JobFailureReason string `json:"job_failure_reason"`
170-
ProjectID int64 `json:"project_id"`
171-
ProjectName string `json:"project_name"`
172-
User User `json:"user"`
173-
Commit BuildCommit `json:"commit"`
174-
Repository Repository `json:"repository"`
157+
ObjectKind string `json:"object_kind"`
158+
Ref string `json:"ref"`
159+
Tag bool `json:"tag"`
160+
BeforeSHA string `json:"before_sha"`
161+
SHA string `json:"sha"`
162+
BuildID int64 `json:"build_id"`
163+
BuildName string `json:"build_name"`
164+
BuildStage string `json:"build_stage"`
165+
BuildStatus string `json:"build_status"`
166+
BuildStartedAt customTime `json:"build_started_at"`
167+
BuildFinishedAt customTime `json:"build_finished_at"`
168+
BuildDuration int64 `json:"build_duration"`
169+
BuildAllowFailure bool `json:"build_allow_failure"`
170+
BuildFailureReason string `json:"build_failure_reason"`
171+
PipelineID int64 `json:"pipeline_id"`
172+
ProjectID int64 `json:"project_id"`
173+
ProjectName string `json:"project_name"`
174+
User User `json:"user"`
175+
Commit BuildCommit `json:"commit"`
176+
Repository Repository `json:"repository"`
177+
Runner Runner `json:"runner"`
175178
}
176179

177180
// SystemHookPayload contains the ObjectKind to match with real hook events
@@ -197,8 +200,8 @@ type Issue struct {
197200
IID int64 `json:"iid"`
198201
}
199202

200-
// Job contains all of the GitLab job information
201-
type Job struct {
203+
// Build contains all of the GitLab Build information
204+
type Build struct {
202205
ID int64 `json:"id"`
203206
Stage string `json:"stage"`
204207
Name string `json:"name"`
@@ -240,6 +243,7 @@ type Wiki struct {
240243
type Commit struct {
241244
ID string `json:"id"`
242245
Message string `json:"message"`
246+
Title string `json:"title"`
243247
Timestamp customTime `json:"timestamp"`
244248
URL string `json:"url"`
245249
Author Author `json:"author"`
@@ -304,28 +308,40 @@ type Project struct {
304308

305309
// Repository contains all of the GitLab repository information
306310
type Repository struct {
307-
Name string `json:"name"`
308-
URL string `json:"url"`
309-
Description string `json:"description"`
310-
Homepage string `json:"homepage"`
311+
Name string `json:"name"`
312+
URL string `json:"url"`
313+
Description string `json:"description"`
314+
Homepage string `json:"homepage"`
315+
GitSSHURL string `json:"git_ssh_url"`
316+
GitHTTPURL string `json:"git_http_url"`
317+
VisibilityLevel int64 `json:"visibility_level"`
311318
}
312319

313320
// ObjectAttributes contains all of the GitLab object attributes information
314321
type ObjectAttributes struct {
315322
ID int64 `json:"id"`
316323
Title string `json:"title"`
324+
AssigneeIDS []int64 `json:"assignee_ids"`
317325
AssigneeID int64 `json:"assignee_id"`
318326
AuthorID int64 `json:"author_id"`
319327
ProjectID int64 `json:"project_id"`
320328
CreatedAt customTime `json:"created_at"`
321329
UpdatedAt customTime `json:"updated_at"`
322-
ChangePosition Position `json:"change_position"`
323-
OriginalPosition Position `json:"original_position"`
330+
UpdatedByID int64 `json:"updated_by_id"`
331+
LastEditedAt customTime `json:"last_edited_at"`
332+
LastEditedByID int64 `json:"last_edited_by_id"`
333+
RelativePosition int64 `json:"relative_position"`
324334
Position Position `json:"position"`
325335
BranchName string `json:"branch_name"`
326336
Description string `json:"description"`
327337
MilestoneID int64 `json:"milestone_id"`
328338
State string `json:"state"`
339+
StateID int64 `json:"state_id"`
340+
Confidential bool `json:"confidential"`
341+
DiscussionLocked bool `json:"discussion_locked"`
342+
DueDate customTime `json:"due_date"`
343+
TimeEstimate int64 `json:"time_estimate"`
344+
TotalTimeSpent int64 `json:"total_time_spent"`
329345
IID int64 `json:"iid"`
330346
URL string `json:"url"`
331347
Action string `json:"action"`
@@ -374,6 +390,13 @@ type PipelineObjectAttributes struct {
374390
CreatedAt customTime `json:"created_at"`
375391
FinishedAt customTime `json:"finished_at"`
376392
Duration int64 `json:"duration"`
393+
Variables []Variable `json:"variables"`
394+
}
395+
396+
// Variable contains pipeline variables
397+
type Variable struct {
398+
Key string `json:"key"`
399+
Value string `json:"value"`
377400
}
378401

379402
// Position defines a specific location, identified by paths line numbers and
@@ -421,6 +444,7 @@ type MergeRequest struct {
421444
LastCommit LastCommit `json:"last_commit"`
422445
WorkInProgress bool `json:"work_in_progress"`
423446
Assignee Assignee `json:"assignee"`
447+
URL string `json:"url"`
424448
}
425449

426450
// Assignee contains all of the GitLab assignee information

testdata/gitlab/job-event.json

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
{
2-
"object_kind": "job",
3-
"ref": "gitlab-script-trigger",
4-
"tag": false,
5-
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
2+
"object_kind": "build",
3+
"ref": "gitlab-script-trigger",
4+
"tag": false,
5+
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
6+
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
7+
"build_id": 1977,
8+
"build_name": "test",
9+
"build_stage": "test",
10+
"build_status": "created",
11+
"build_started_at": null,
12+
"build_finished_at": null,
13+
"build_duration": null,
14+
"build_allow_failure": false,
15+
"build_failure_reason": "script_failure",
16+
"pipeline_id": 2366,
17+
"project_id": 380,
18+
"project_name": "gitlab-org/gitlab-test",
19+
"user": {
20+
"id": 3,
21+
"name": "User",
22+
"email": "[email protected]",
23+
"avatar_url": "http://www.gravatar.com/avatar/e32bd13e2add097461cb96824b7a829c?s=80\u0026d=identicon"
24+
},
25+
"commit": {
26+
"id": 2366,
627
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
7-
"job_id": 1977,
8-
"job_name": "test",
9-
"job_stage": "test",
10-
"job_status": "created",
11-
"job_started_at": null,
12-
"job_finished_at": null,
13-
"job_duration": null,
14-
"job_allow_failure": false,
15-
"job_failure_reason": "script_failure",
16-
"project_id": 380,
17-
"project_name": "gitlab-org/gitlab-test",
18-
"user": {
19-
"id": 3,
20-
"name": "User",
21-
"email": "[email protected]"
22-
},
23-
"commit": {
24-
"id": 2366,
25-
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
26-
"message": "test\n",
27-
"author_name": "User",
28-
"author_email": "[email protected]",
29-
"status": "created",
30-
"duration": null,
31-
"started_at": null,
32-
"finished_at": null
33-
},
34-
"repository": {
35-
"name": "gitlab_test",
36-
"description": "Atque in sunt eos similique dolores voluptatem.",
37-
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
38-
"git_ssh_url": "[email protected]:gitlab-org/gitlab-test.git",
39-
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
40-
"visibility_level": 20
41-
}
28+
"message": "test\n",
29+
"author_name": "User",
30+
"author_email": "[email protected]",
31+
"status": "created",
32+
"duration": null,
33+
"started_at": null,
34+
"finished_at": null
35+
},
36+
"repository": {
37+
"name": "gitlab_test",
38+
"description": "Atque in sunt eos similique dolores voluptatem.",
39+
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
40+
"git_ssh_url": "[email protected]:gitlab-org/gitlab-test.git",
41+
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
42+
"visibility_level": 20
43+
},
44+
"runner": {
45+
"active": true,
46+
"is_shared": false,
47+
"id": 380987,
48+
"description": "shared-runners-manager-6.gitlab.com"
4249
}
50+
}

0 commit comments

Comments
 (0)