Skip to content

Commit

Permalink
GitLab: Remove build events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Philipp Böschen committed Mar 13, 2022
1 parent 9c954e2 commit aac0fc2
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 86 deletions.
9 changes: 0 additions & 9 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ const (
MergeRequestEvents Event = "Merge Request Hook"
WikiPageEvents Event = "Wiki Page Hook"
PipelineEvents Event = "Pipeline Hook"
BuildEvents Event = "Build Hook"
JobEvents Event = "Job Hook"
SystemHookEvents Event = "System Hook"

objectPush string = "push"
objectTag string = "tag_push"
objectMergeRequest string = "merge_request"
objectBuild string = "build"
)

// Option is a configuration option for the webhook
Expand Down Expand Up @@ -169,19 +167,12 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
err := json.Unmarshal([]byte(payload), &pl)
return pl, err

case BuildEvents:
var pl BuildEventPayload
err := json.Unmarshal([]byte(payload), &pl)
return pl, err
case JobEvents:
var pl JobEventPayload
err := json.Unmarshal([]byte(payload), &pl)
if err != nil {
return nil, err
}
if pl.ObjectKind == objectBuild {
return eventParsing(BuildEvents, events, payload)
}
return pl, nil

case SystemHookEvents:
Expand Down
15 changes: 3 additions & 12 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,6 @@ func TestWebhooks(t *testing.T) {
"X-Gitlab-Event": []string{"Pipeline Hook"},
},
},
{
name: "BuildEvent",
event: BuildEvents,
typ: BuildEventPayload{},
filename: "../testdata/gitlab/build-event.json",
headers: http.Header{
"X-Gitlab-Event": []string{"Build Hook"},
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -276,9 +267,9 @@ func TestJobHooks(t *testing.T) {
}{
{
name: "JobEvent",
events: []Event{JobEvents, BuildEvents},
typ: BuildEventPayload{},
filename: "../testdata/gitlab/build-event.json",
events: []Event{JobEvents},
typ: JobEventPayload{},
filename: "../testdata/gitlab/job-event.json",
headers: http.Header{
"X-Gitlab-Event": []string{"Job Hook"},
},
Expand Down
23 changes: 0 additions & 23 deletions gitlab/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,6 @@ type CommentEventPayload struct {
Snippet Snippet `json:"snippet"`
}

// BuildEventPayload contains the information for GitLab's build status change event
type BuildEventPayload 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 float64 `json:"build_duration"`
BuildAllowFailure bool `json:"build_allow_failure"`
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"`
}

// JobEventPayload contains the information for GitLab's Job status change
type JobEventPayload struct {
ObjectKind string `json:"object_kind"`
Expand Down
42 changes: 0 additions & 42 deletions testdata/gitlab/build-event.json

This file was deleted.

0 comments on commit aac0fc2

Please sign in to comment.