Skip to content

Commit

Permalink
Merge pull request #1671 from CodingMonk0/master
Browse files Browse the repository at this point in the history
fix: update pipeline & merge request webhook event types
  • Loading branch information
svanharmelen committed Mar 21, 2023
2 parents 9a0201c + 3f7c3f4 commit 93aadd2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
24 changes: 18 additions & 6 deletions event_webhook_types.go
Expand Up @@ -572,12 +572,15 @@ type MergeEvent struct {
Email string `json:"email"`
} `json:"author"`
} `json:"last_commit"`
BlockingDiscussionsResolved bool `json:"blocking_discussions_resolved"`
WorkInProgress bool `json:"work_in_progress"`
URL string `json:"url"`
Action string `json:"action"`
OldRev string `json:"oldrev"`
Assignee *EventUser `json:"assignee"`
BlockingDiscussionsResolved bool `json:"blocking_discussions_resolved"`
WorkInProgress bool `json:"work_in_progress"`
FirstContribution bool `json:"first_contribution"`
URL string `json:"url"`
Labels []*EventLabel `json:"labels"`
Action string `json:"action"`
DetailedMergeStatus string `json:"detailed_merge_status"`
OldRev string `json:"oldrev"`
Assignee *EventUser `json:"assignee"`
} `json:"object_attributes"`
Repository *Repository `json:"repository"`
Assignee *EventUser `json:"assignee"`
Expand Down Expand Up @@ -754,6 +757,15 @@ type PipelineEvent struct {
Email string `json:"email"`
} `json:"author"`
} `json:"commit"`
SourcePipline struct {
Project struct {
ID int `json:"id"`
WebURL string `json:"web_url"`
PathWithNamespace string `json:"path_with_namespace"`
} `json:"project"`
PipelineID int `json:"pipeline_id"`
JobID int `json:"job_id"`
} `json:"source_pipeline"`
Builds []struct {
ID int `json:"id"`
Stage string `json:"stage"`
Expand Down
35 changes: 35 additions & 0 deletions event_webhook_types_test.go
Expand Up @@ -376,6 +376,10 @@ func TestMergeEventUnmarshal(t *testing.T) {
t.Errorf("BlockingDiscussionsResolved isn't true")
}

if event.ObjectAttributes.FirstContribution != true {
t.Errorf("FirstContribution isn't true")
}

if event.Assignees[0].ID != expectedID {
t.Errorf("Assignees[0].ID is %v, want %v", event.Assignees[0].ID, expectedID)
}
Expand Down Expand Up @@ -408,6 +412,10 @@ func TestMergeEventUnmarshal(t *testing.T) {
t.Errorf("Reviewers[0].AvatarURL is %v, want %v", event.Reviewers[0].AvatarURL, excpectedAvatar)
}

if event.ObjectAttributes.DetailedMergeStatus != "mergeable" {
t.Errorf("DetailedMergeStatus is %s, want %s", event.ObjectAttributes.DetailedMergeStatus, "mergeable")
}

assert.Equal(t, []*EventLabel{
{
ID: 206,
Expand All @@ -423,6 +431,21 @@ func TestMergeEventUnmarshal(t *testing.T) {
},
}, event.Labels)

assert.Equal(t, []*EventLabel{
{
ID: 206,
Title: "API",
Color: "#ffffff",
ProjectID: 14,
CreatedAt: "2013-12-03T17:15:43Z",
UpdatedAt: "2013-12-03T17:15:43Z",
Template: false,
Description: "API related issues",
Type: "ProjectLabel",
GroupID: 41,
},
}, event.ObjectAttributes.Labels)

assert.Equal(t, []*EventLabel{
{
ID: 206,
Expand Down Expand Up @@ -659,6 +682,18 @@ func TestPipelineEventUnmarshal(t *testing.T) {
if event.Builds[1].FailureReason != "" {
t.Errorf("Builds[0].Failurereason is %v, want %v", event.Builds[0].FailureReason, "''")
}

if event.SourcePipline.PipelineID != 30 {
t.Errorf("Source Pipline ID is %v, want %v", event.SourcePipline.PipelineID, 30)
}

if event.SourcePipline.JobID != 3401 {
t.Errorf("Source Pipline JobID is %v, want %v", event.SourcePipline.JobID, 3401)
}

if event.SourcePipline.Project.ID != 41 {
t.Errorf("Source Pipline Project ID is %v, want %v", event.SourcePipline.Project.ID, 41)
}
}

func TestPushEventUnmarshal(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion testdata/webhooks/merge_request.json
Expand Up @@ -107,7 +107,8 @@
"type": "ProjectLabel",
"group_id": 41
}],
"action": "open"
"action": "open",
"detailed_merge_status": "mergeable"
},
"labels": [{
"id": 206,
Expand Down
9 changes: 9 additions & 0 deletions testdata/webhooks/pipeline.json
Expand Up @@ -67,6 +67,15 @@
"email": "user@gitlab.com"
}
},
"source_pipeline":{
"project":{
"id": 41,
"web_url": "https://gitlab.example.com/gitlab-org/upstream-project",
"path_with_namespace": "gitlab-org/upstream-project"
},
"pipeline_id": 30,
"job_id": 3401
},
"builds": [
{
"id": 380,
Expand Down

0 comments on commit 93aadd2

Please sign in to comment.