Skip to content

Commit

Permalink
update system hooks to handle event_name fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aritas1 committed May 30, 2020
1 parent 9f0c3ac commit b03dc86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
11 changes: 10 additions & 1 deletion gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions gitlab/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b03dc86

Please sign in to comment.