Skip to content

Commit

Permalink
Merge pull request #1695 from smit-modi/merge-event
Browse files Browse the repository at this point in the history
Updated MergeEvent
  • Loading branch information
svanharmelen committed Apr 18, 2023
2 parents 9560b5b + de864d8 commit fcf57a4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
33 changes: 25 additions & 8 deletions event_webhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ type MergeCommentEvent struct {
// https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#merge-request-events
type MergeEvent struct {
ObjectKind string `json:"object_kind"`
EventType string `json:"event_type"`
User *EventUser `json:"user"`
Project struct {
ID int `json:"id"`
Expand All @@ -586,6 +587,7 @@ type MergeEvent struct {
Namespace string `json:"namespace"`
PathWithNamespace string `json:"path_with_namespace"`
DefaultBranch string `json:"default_branch"`
CIConfigPath string `json:"ci_config_path"`
Homepage string `json:"homepage"`
URL string `json:"url"`
SSHURL string `json:"ssh_url"`
Expand All @@ -607,7 +609,10 @@ type MergeEvent struct {
UpdatedAt string `json:"updated_at"` // Should be *time.Time (see Gitlab issue #21468)
StCommits []*Commit `json:"st_commits"`
StDiffs []*Diff `json:"st_diffs"`
LastEditedAt string `json:"last_edited_at"`
LastEditedByID int `json:"last_edited_by_id"`
MilestoneID int `json:"milestone_id"`
StateID StateID `json:"state_id"`
State string `json:"state"`
MergeStatus string `json:"merge_status"`
TargetProjectID int `json:"target_project_id"`
Expand All @@ -633,6 +638,7 @@ type MergeEvent struct {
LastCommit struct {
ID string `json:"id"`
Message string `json:"message"`
Title string `json:"title"`
Timestamp *time.Time `json:"timestamp"`
URL string `json:"url"`
Author struct {
Expand All @@ -642,18 +648,19 @@ type MergeEvent struct {
} `json:"last_commit"`
BlockingDiscussionsResolved bool `json:"blocking_discussions_resolved"`
WorkInProgress bool `json:"work_in_progress"`
TotalTimeSpent int `json:"total_time_spent"`
TimeChange int `json:"time_change"`
HumanTotalTimeSpent string `json:"human_total_time_spent"`
HumanTimeChange string `json:"human_time_change"`
HumanTimeEstimate string `json:"human_time_estimate"`
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"`
Assignees []*EventUser `json:"assignees"`
Reviewers []*EventUser `json:"reviewers"`
Labels []*EventLabel `json:"labels"`
Changes struct {
Assignees struct {
Expand All @@ -672,6 +679,18 @@ type MergeEvent struct {
Previous []*EventLabel `json:"previous"`
Current []*EventLabel `json:"current"`
} `json:"labels"`
LastEditedAt struct {
Previous string `json:"previous"`
Current string `json:"current"`
} `json:"last_edited_at"`
LastEditedByID struct {
Previous int `json:"previous"`
Current int `json:"current"`
} `json:"last_edited_by_id"`
MilestoneID struct {
Previous int `json:"previous"`
Current int `json:"current"`
} `json:"milestone_id"`
SourceBranch struct {
Previous string `json:"previous"`
Current string `json:"current"`
Expand Down Expand Up @@ -704,11 +723,9 @@ type MergeEvent struct {
Previous int `json:"previous"`
Current int `json:"current"`
} `json:"updated_by_id"`
MilestoneID struct {
Previous int `json:"previous"`
Current int `json:"current"`
} `json:"milestone_id"`
} `json:"changes"`
Assignees []*EventUser `json:"assignees"`
Reviewers []*EventUser `json:"reviewers"`
}

// EventUser represents a user record in an event and is used as an even initiator or a merge assignee.
Expand Down
33 changes: 29 additions & 4 deletions event_webhook_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,14 @@ func TestMergeEventUnmarshal(t *testing.T) {
t.Errorf("Merge Event is null")
}

if event.EventType != "merge_request" {
t.Errorf("EventType is %v, want %v", event.EventType, "merge_request")
}

if event.Project.CIConfigPath != "" {
t.Errorf("Project.CIConfigPath is %v, want %v", event.Project.CIConfigPath, "")
}

if event.ObjectAttributes.ID != 99 {
t.Errorf("ObjectAttributes.ID is %v, want %v", event.ObjectAttributes.ID, 99)
}
Expand All @@ -627,6 +635,27 @@ func TestMergeEventUnmarshal(t *testing.T) {
if event.ObjectAttributes.LastCommit.ID != "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" {
t.Errorf("ObjectAttributes.LastCommit.ID is %v, want %s", event.ObjectAttributes.LastCommit.ID, "da1560886d4f094c3e6c9ef40349f7d38b5d27d7")
}

if event.ObjectAttributes.TotalTimeSpent != 0 {
t.Errorf("ObjectAttributes.TotalTimeSpent is %v, want %v", event.ObjectAttributes.TotalTimeSpent, 0)
}

if event.ObjectAttributes.TimeChange != 0 {
t.Errorf("ObjectAttributes.TimeChange is %v, want %v", event.ObjectAttributes.TimeChange, 0)
}

if event.ObjectAttributes.HumanTotalTimeSpent != "30m" {
t.Errorf("ObjectAttributes.HumanTotalTimeSpent is %v, want %v", event.ObjectAttributes.HumanTotalTimeSpent, "30m")
}

if event.ObjectAttributes.HumanTimeChange != "30m" {
t.Errorf("ObjectAttributes.HumanTimeChange is %v, want %v", event.ObjectAttributes.HumanTimeChange, "30m")
}

if event.ObjectAttributes.HumanTimeEstimate != "1h" {
t.Errorf("ObjectAttributes.HumanTimeEstimate is %v, want %v", event.ObjectAttributes.HumanTimeEstimate, "1h")
}

if event.Assignees[0].Name != expectedName {
t.Errorf("Assignee.Name is %v, want %v", event.Assignees[0].Name, expectedName)
}
Expand Down Expand Up @@ -876,10 +905,6 @@ func TestMergeEventUnmarshalFromGroup(t *testing.T) {
t.Errorf("Repository.Name is %v, want %v", event.Repository.Name, exampleProjectName)
}

if event.Assignee.Username != expectedUsername {
t.Errorf("Assignee.Username is %v, want %v", event.Assignee, expectedUsername)
}

if event.User.Name != expectedName {
t.Errorf("Username is %s, want %s", event.User.Name, expectedName)
}
Expand Down
9 changes: 9 additions & 0 deletions testdata/webhooks/merge_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,25 @@
"ssh_url":"git@example.com:awesome_space/awesome_project.git",
"http_url":"http://example.com/awesome_space/awesome_project.git"
},
"last_edited_at":"2023-03-27 00:03:05 UTC",
"last_edited_by_id": 51,
"state_id": 1,
"last_commit": {
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"title": "MR Title",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)"
}
},
"total_time_spent": 0,
"time_change": 0,
"human_total_time_spent": "30m",
"human_time_change": "30m",
"human_time_estimate": "1h",
"labels": [{
"id": 206,
"title": "API",
Expand Down

0 comments on commit fcf57a4

Please sign in to comment.