Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
WikiPageEvents Event = "Wiki Page Hook"
PipelineEvents Event = "Pipeline Hook"
BuildEvents Event = "Build Hook"
JobEvents Event = "Job Hook"
SystemHookEvents Event = "System Hook"

objectPush string = "push"
Expand Down Expand Up @@ -171,6 +172,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
var pl BuildEventPayload
err := json.Unmarshal([]byte(payload), &pl)
return pl, err
case JobEvents:
var p1 JobEventPayload
err := json.Unmarshal([]byte(payload), &p1)
return p1, err

case SystemHookEvents:
var pl SystemHookPayload
Expand Down
9 changes: 9 additions & 0 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ func TestWebhooks(t *testing.T) {
"X-Gitlab-Event": []string{"Build Hook"},
},
},
{
name: "JobEvent",
event: JobEvents,
typ: JobEventPayload{},
filename: "../testdata/gitlab/job-event.json",
headers: http.Header{
"X-Gitlab-Event": []string{"Job Hook"},
},
},
}

for _, tt := range tests {
Expand Down
23 changes: 23 additions & 0 deletions gitlab/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ type BuildEventPayload struct {
Repository Repository `json:"repository"`
}

// JobEventPayload contains the information for GitLab's Job status change
type JobEventPayload struct {
ObjectKind string `json:"object_kind"`
Ref string `json:"ref"`
Tag bool `json:"tag"`
BeforeSHA string `json:"before_sha"`
SHA string `json:"sha"`
JobID int64 `json:"Job_id"`
JobName string `json:"Job_name"`
JobStage string `json:"Job_stage"`
JobStatus string `json:"Job_status"`
JobStartedAt customTime `json:"Job_started_at"`
JobFinishedAt customTime `json:"Job_finished_at"`
JobDuration int64 `json:"Job_duration"`
Job bool `json:"Job"`
JobFailureReason string `json:"job_failure_reason"`
ProjectID int64 `json:"project_id"`
ProjectName string `json:"project_name"`
User User `json:"user"`
Commit BuildCommit `json:"commit"`
Repository Repository `json:"repository"`
}

// SystemHookPayload contains the ObjectKind to match with real hook events
type SystemHookPayload struct {
ObjectKind string `json:"object_kind"`
Expand Down
42 changes: 42 additions & 0 deletions testdata/gitlab/job-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"object_kind": "job",
"ref": "gitlab-script-trigger",
"tag": false,
"before_sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"job_id": 1977,
"job_name": "test",
"job_stage": "test",
"job_status": "created",
"job_started_at": null,
"job_finished_at": null,
"job_duration": null,
"job_allow_failure": false,
"job_failure_reason": "script_failure",
"project_id": 380,
"project_name": "gitlab-org/gitlab-test",
"user": {
"id": 3,
"name": "User",
"email": "[email protected]"
},
"commit": {
"id": 2366,
"sha": "2293ada6b400935a1378653304eaf6221e0fdb8f",
"message": "test\n",
"author_name": "User",
"author_email": "[email protected]",
"status": "created",
"duration": null,
"started_at": null,
"finished_at": null
},
"repository": {
"name": "gitlab_test",
"description": "Atque in sunt eos similique dolores voluptatem.",
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
"git_ssh_url": "[email protected]:gitlab-org/gitlab-test.git",
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
"visibility_level": 20
}
}