Skip to content

Commit bcfd30d

Browse files
author
Philipp Böschen
committed
GitLab: Remove build events
According to https://docs.gitlab.com/14.8/ee/user/project/integrations/webhook_events.html those event payloads don't exist, the logic to parse a `JobEvent` down into a `BuildEvent` actively removes fields like `PipelineID` from the payload.
1 parent 9c954e2 commit bcfd30d

File tree

4 files changed

+3
-85
lines changed

4 files changed

+3
-85
lines changed

gitlab/gitlab.go

-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const (
3131
MergeRequestEvents Event = "Merge Request Hook"
3232
WikiPageEvents Event = "Wiki Page Hook"
3333
PipelineEvents Event = "Pipeline Hook"
34-
BuildEvents Event = "Build Hook"
3534
JobEvents Event = "Job Hook"
3635
SystemHookEvents Event = "System Hook"
3736

@@ -169,19 +168,12 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
169168
err := json.Unmarshal([]byte(payload), &pl)
170169
return pl, err
171170

172-
case BuildEvents:
173-
var pl BuildEventPayload
174-
err := json.Unmarshal([]byte(payload), &pl)
175-
return pl, err
176171
case JobEvents:
177172
var pl JobEventPayload
178173
err := json.Unmarshal([]byte(payload), &pl)
179174
if err != nil {
180175
return nil, err
181176
}
182-
if pl.ObjectKind == objectBuild {
183-
return eventParsing(BuildEvents, events, payload)
184-
}
185177
return pl, nil
186178

187179
case SystemHookEvents:

gitlab/gitlab_test.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,6 @@ func TestWebhooks(t *testing.T) {
222222
"X-Gitlab-Event": []string{"Pipeline Hook"},
223223
},
224224
},
225-
{
226-
name: "BuildEvent",
227-
event: BuildEvents,
228-
typ: BuildEventPayload{},
229-
filename: "../testdata/gitlab/build-event.json",
230-
headers: http.Header{
231-
"X-Gitlab-Event": []string{"Build Hook"},
232-
},
233-
},
234225
}
235226

236227
for _, tt := range tests {
@@ -276,9 +267,9 @@ func TestJobHooks(t *testing.T) {
276267
}{
277268
{
278269
name: "JobEvent",
279-
events: []Event{JobEvents, BuildEvents},
280-
typ: BuildEventPayload{},
281-
filename: "../testdata/gitlab/build-event.json",
270+
events: []Event{JobEvents},
271+
typ: JobEventPayload{},
272+
filename: "../testdata/gitlab/job-event.json",
282273
headers: http.Header{
283274
"X-Gitlab-Event": []string{"Job Hook"},
284275
},

gitlab/payload.go

-23
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,6 @@ type CommentEventPayload struct {
131131
Snippet Snippet `json:"snippet"`
132132
}
133133

134-
// BuildEventPayload contains the information for GitLab's build status change event
135-
type BuildEventPayload struct {
136-
ObjectKind string `json:"object_kind"`
137-
Ref string `json:"ref"`
138-
Tag bool `json:"tag"`
139-
BeforeSHA string `json:"before_sha"`
140-
SHA string `json:"sha"`
141-
BuildID int64 `json:"build_id"`
142-
BuildName string `json:"build_name"`
143-
BuildStage string `json:"build_stage"`
144-
BuildStatus string `json:"build_status"`
145-
BuildStartedAt customTime `json:"build_started_at"`
146-
BuildFinishedAt customTime `json:"build_finished_at"`
147-
BuildDuration float64 `json:"build_duration"`
148-
BuildAllowFailure bool `json:"build_allow_failure"`
149-
ProjectID int64 `json:"project_id"`
150-
ProjectName string `json:"project_name"`
151-
User User `json:"user"`
152-
Commit BuildCommit `json:"commit"`
153-
Repository Repository `json:"repository"`
154-
Runner Runner `json:"runner"`
155-
}
156-
157134
// JobEventPayload contains the information for GitLab's Job status change
158135
type JobEventPayload struct {
159136
ObjectKind string `json:"object_kind"`

testdata/gitlab/build-event.json

-42
This file was deleted.

0 commit comments

Comments
 (0)