Add support for Job Events
Closes go-playground/webhooks#70, closes go-playground/webhooks#71
This commit is contained in:
@@ -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"
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user