Skip to content

Commit c168baf

Browse files
author
Dean Karn
authored
Merge pull request #73 from iladin/master
Add support for Job Events
2 parents 08c3e54 + 21587e1 commit c168baf

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

gitlab/gitlab.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
WikiPageEvents Event = "Wiki Page Hook"
3333
PipelineEvents Event = "Pipeline Hook"
3434
BuildEvents Event = "Build Hook"
35+
JobEvents Event = "Job Hook"
3536
SystemHookEvents Event = "System Hook"
3637

3738
objectPush string = "push"
@@ -171,6 +172,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
171172
var pl BuildEventPayload
172173
err := json.Unmarshal([]byte(payload), &pl)
173174
return pl, err
175+
case JobEvents:
176+
var p1 JobEventPayload
177+
err := json.Unmarshal([]byte(payload), &p1)
178+
return p1, err
174179

175180
case SystemHookEvents:
176181
var pl SystemHookPayload

gitlab/gitlab_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ func TestWebhooks(t *testing.T) {
231231
"X-Gitlab-Event": []string{"Build Hook"},
232232
},
233233
},
234+
{
235+
name: "JobEvent",
236+
event: JobEvents,
237+
typ: JobEventPayload{},
238+
filename: "../testdata/gitlab/job-event.json",
239+
headers: http.Header{
240+
"X-Gitlab-Event": []string{"Job Hook"},
241+
},
242+
},
234243
}
235244

236245
for _, tt := range tests {

gitlab/payload.go

+23
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,29 @@ type BuildEventPayload struct {
148148
Repository Repository `json:"repository"`
149149
}
150150

151+
// JobEventPayload contains the information for GitLab's Job status change
152+
type JobEventPayload struct {
153+
ObjectKind string `json:"object_kind"`
154+
Ref string `json:"ref"`
155+
Tag bool `json:"tag"`
156+
BeforeSHA string `json:"before_sha"`
157+
SHA string `json:"sha"`
158+
JobID int64 `json:"Job_id"`
159+
JobName string `json:"Job_name"`
160+
JobStage string `json:"Job_stage"`
161+
JobStatus string `json:"Job_status"`
162+
JobStartedAt customTime `json:"Job_started_at"`
163+
JobFinishedAt customTime `json:"Job_finished_at"`
164+
JobDuration int64 `json:"Job_duration"`
165+
Job bool `json:"Job"`
166+
JobFailureReason string `json:"job_failure_reason"`
167+
ProjectID int64 `json:"project_id"`
168+
ProjectName string `json:"project_name"`
169+
User User `json:"user"`
170+
Commit BuildCommit `json:"commit"`
171+
Repository Repository `json:"repository"`
172+
}
173+
151174
// SystemHookPayload contains the ObjectKind to match with real hook events
152175
type SystemHookPayload struct {
153176
ObjectKind string `json:"object_kind"`

testdata/gitlab/job-event.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"object_kind": "job",
3+
"ref": "gitlab-script-trigger",
4+
"tag": false,
5+
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
6+
"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+
}
42+
}

0 commit comments

Comments
 (0)