From b03dc868a034d0442c4cf179ae7d3164e458ef61 Mon Sep 17 00:00:00 2001 From: aritas1 Date: Sun, 31 May 2020 01:37:42 +0200 Subject: [PATCH] update system hooks to handle event_name fields --- gitlab/gitlab.go | 11 ++++++++++- gitlab/gitlab_test.go | 6 +++--- gitlab/payload.go | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gitlab/gitlab.go b/gitlab/gitlab.go index e181817..f94ed23 100644 --- a/gitlab/gitlab.go +++ b/gitlab/gitlab.go @@ -191,7 +191,16 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{ case objectMergeRequest: return eventParsing(MergeRequestEvents, events, payload) default: - return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent) + switch pl.EventName { + case objectPush: + return eventParsing(PushEvents, events, payload) + case objectTag: + return eventParsing(TagEvents, events, payload) + case objectMergeRequest: + return eventParsing(MergeRequestEvents, events, payload) + default: + return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent) + } } default: return nil, fmt.Errorf("unknown event %s", gitLabEvent) diff --git a/gitlab/gitlab_test.go b/gitlab/gitlab_test.go index f13e608..f05ace8 100644 --- a/gitlab/gitlab_test.go +++ b/gitlab/gitlab_test.go @@ -286,19 +286,19 @@ func TestSystemHooks(t *testing.T) { name: "PushEvent", event: PushEvents, typ: PushEventPayload{}, - filename: "../testdata/gitlab/push-event.json", + filename: "../testdata/gitlab/system-push-event.json", }, { name: "TagEvent", event: TagEvents, typ: TagEventPayload{}, - filename: "../testdata/gitlab/tag-event.json", + filename: "../testdata/gitlab/system-tag-event.json", }, { name: "MergeRequestEvent", event: MergeRequestEvents, typ: MergeRequestEventPayload{}, - filename: "../testdata/gitlab/merge-request-event.json", + filename: "../testdata/gitlab/system-merge-request-event.json", }, } for _, tt := range tests { diff --git a/gitlab/payload.go b/gitlab/payload.go index 4291dfd..6c04176 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -176,6 +176,7 @@ type JobEventPayload struct { // SystemHookPayload contains the ObjectKind to match with real hook events type SystemHookPayload struct { ObjectKind string `json:"object_kind"` + EventName string `json:"event_name"` } // Issue contains all of the GitLab issue information