diff --git a/gitlab/main.go b/gitlab/main.go index a400e0a..3d1f0ac 100644 --- a/gitlab/main.go +++ b/gitlab/main.go @@ -92,6 +92,11 @@ func init() { err = libHTTP.Read(r, &pl) msg = pl.String() + case JobEvents: + var pl JobEventPayload + err = libHTTP.Read(r, &pl) + msg = pl.String() + case SystemEvents: var data map[string]interface{} var buf bytes.Buffer diff --git a/gitlab/request.go b/gitlab/request.go index df45537..e200a04 100644 --- a/gitlab/request.go +++ b/gitlab/request.go @@ -18,6 +18,7 @@ const ( MergeRequestEvents Event = "Merge Request Hook" WikiPageEvents Event = "Wiki Page Hook" PipelineEvents Event = "Pipeline Hook" + JobEvents Event = "Job Hook" BuildEvents Event = "Build Hook" SystemEvents Event = "System Hook" ) @@ -155,12 +156,12 @@ type PipelineEventPayload struct { User User `json:"user"` Project Project `json:"project"` Commit Commit `json:"commit"` - ObjectAttributes ObjectAttributes `json:"object_attributes"` + ObjectAttributes map[string]interface{} `json:"object_attributes"` Builds []Build `json:"builds"` } func (pl *PipelineEventPayload) String() string { - return fmt.Sprintf("[%s] %s: started %d builds by %s of %s", pl.Project.Name, PipelineEvents, len(pl.Builds), pl.User.Name, pl.Commit.String()) + return fmt.Sprintf("[%s] %s: started %d builds by %s of %s => %s (%s)", pl.Project.Name, PipelineEvents, len(pl.Builds), pl.User.Name, pl.Commit.Ref, pl.Commit.Message, pl.Commit.SHA) } // CommentEventPayload contains the information for GitLab's comment event @@ -181,6 +182,35 @@ func (pl *CommentEventPayload) String() string { return fmt.Sprintf("[%s] %s: comment PR !%d by %s of %s", pl.Project.Name, CommentEvents, pl.MergeRequest.ID, pl.User.Name, pl.Commit.String()) } +// JobEventPayload contains the information for GitLab's build status change event +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"` + BuildID int64 `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 int64 `json:"build_duration"` + BuildAllowFailure bool `json:"build_allow_failure"` + BuildFailureReason string `json:"build_failure_reason"` + PipelineID int64 `json:"pipeline_id"` + ProjectID int64 `json:"project_id"` + ProjectName string `json:"project_name"` + User User `json:"user"` + Commit BuildCommit `json:"commit"` + Repository Repository `json:"repository"` + Runner Runner `json:"runner"` +} + +func (pl *JobEventPayload) String() string { + return fmt.Sprintf("[%s] %s: %s build %d (in pipeline %d) for %s => %s", pl.ProjectName, BuildEvents, pl.BuildStatus, pl.BuildID, pl.PipelineID, pl.Ref, pl.SHA) +} + // BuildEventPayload contains the information for GitLab's build status change event type BuildEventPayload struct { ObjectKind string `json:"object_kind"`