Skip to content

Commit c3b1a44

Browse files
authored
chore: the gitlab merge request payload is outdated (#186)
updated the structs based on https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#merge-request-events The reviewer's list needed to be included.
1 parent 58e552d commit c3b1a44

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

Diff for: gitlab/payload.go

+13
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,23 @@ type ConfidentialIssueEventPayload struct {
5252
// MergeRequestEventPayload contains the information for GitLab's merge request event
5353
type MergeRequestEventPayload struct {
5454
ObjectKind string `json:"object_kind"`
55+
EventType string `json:"event_type"`
5556
User User `json:"user"`
5657
ObjectAttributes ObjectAttributes `json:"object_attributes"`
5758
Changes Changes `json:"changes"`
5859
Project Project `json:"project"`
5960
Repository Repository `json:"repository"`
6061
Labels []Label `json:"labels"`
6162
Assignees []Assignee `json:"assignees"`
63+
Reviewers []Reviewers `json:"reviewers"`
64+
}
65+
66+
// Reviewers contains all of the GitLab reviewers information
67+
type Reviewers struct {
68+
ID int `json:"id"`
69+
Name string `json:"name"`
70+
Username string `json:"username"`
71+
AvatarURL string `json:"avatar_url"`
6272
}
6373

6474
// PushEventPayload contains the information for GitLab's push event
@@ -642,6 +652,7 @@ type Project struct {
642652
VisibilityLevel int64 `json:"visibility_level"`
643653
PathWithNamespace string `json:"path_with_namespace"`
644654
DefaultBranch string `json:"default_branch"`
655+
CiConfigPath string `json:"ci_config_path"`
645656
Homepage string `json:"homepage"`
646657
URL string `json:"url"`
647658
SSHURL string `json:"ssh_url"`
@@ -665,6 +676,7 @@ type ObjectAttributes struct {
665676
Title string `json:"title"`
666677
AssigneeIDS []int64 `json:"assignee_ids"`
667678
AssigneeID int64 `json:"assignee_id"`
679+
ReviewerIDs []int64 `json:"reviewer_ids"`
668680
AuthorID int64 `json:"author_id"`
669681
ProjectID int64 `json:"project_id"`
670682
CreatedAt customTime `json:"created_at"`
@@ -853,6 +865,7 @@ type Target struct {
853865
type LastCommit struct {
854866
ID string `json:"id"`
855867
Message string `json:"message"`
868+
Title string `json:"title"`
856869
Timestamp customTime `json:"timestamp"`
857870
URL string `json:"url"`
858871
Author Author `json:"author"`

Diff for: testdata/gitlab/merge-request-event.json

+59-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"object_kind": "merge_request",
3+
"event_type": "merge_request",
34
"user": {
5+
"id": 1,
46
"name": "Administrator",
57
"username": "root",
6-
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
8+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
9+
"email": "[email protected]"
710
},
811
"project": {
912
"id": 1,
@@ -17,6 +20,7 @@
1720
"visibility_level":20,
1821
"path_with_namespace":"gitlabhq/gitlab-test",
1922
"default_branch":"master",
23+
"ci_config_path":"",
2024
"homepage":"http://example.com/gitlabhq/gitlab-test",
2125
"url":"http://example.com/gitlabhq/gitlab-test.git",
2226
"ssh_url":"[email protected]:gitlabhq/gitlab-test.git",
@@ -30,20 +34,34 @@
3034
},
3135
"object_attributes": {
3236
"id": 99,
37+
"iid": 1,
3338
"target_branch": "master",
3439
"source_branch": "ms-viewport",
3540
"source_project_id": 14,
3641
"author_id": 51,
42+
"assignee_ids": [6],
3743
"assignee_id": 6,
44+
"reviewer_ids": [6],
3845
"title": "MS-Viewport",
3946
"created_at": "2013-12-03T17:23:34Z",
4047
"updated_at": "2013-12-03T17:23:34Z",
48+
"last_edited_at": "2013-12-03T17:23:34Z",
49+
"last_edited_by_id": 1,
4150
"milestone_id": null,
51+
"state_id": 1,
4252
"state": "opened",
53+
"blocking_discussions_resolved": true,
54+
"work_in_progress": false,
55+
"first_contribution": true,
4356
"merge_status": "unchecked",
4457
"target_project_id": 14,
45-
"iid": 1,
4658
"description": "",
59+
"total_time_spent": 1800,
60+
"time_change": 30,
61+
"human_total_time_spent": "30m",
62+
"human_time_change": "30s",
63+
"human_time_estimate": "30m",
64+
"url": "http://example.com/diaspora/merge_requests/1",
4765
"source": {
4866
"name":"Awesome Project",
4967
"description":"Aut reprehenderit ut est.",
@@ -79,21 +97,28 @@
7997
"last_commit": {
8098
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
8199
"message": "fixed readme",
100+
"title": "Update file README.md",
82101
"timestamp": "2012-01-03T23:36:29+02:00",
83102
"url": "http://example.com/awesome_space/awesome_project/commits/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
84103
"author": {
85104
"name": "GitLab dev user",
86105
"email": "gitlabdev@dv6700.(none)"
87106
}
88107
},
89-
"work_in_progress": false,
90-
"url": "http://example.com/diaspora/merge_requests/1",
108+
"labels": [{
109+
"id": 206,
110+
"title": "API",
111+
"color": "#ffffff",
112+
"project_id": 14,
113+
"created_at": "2013-12-03T17:15:43Z",
114+
"updated_at": "2013-12-03T17:15:43Z",
115+
"template": false,
116+
"description": "API related issues",
117+
"type": "ProjectLabel",
118+
"group_id": 41
119+
}],
91120
"action": "open",
92-
"assignee": {
93-
"name": "User1",
94-
"username": "user1",
95-
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
96-
}
121+
"detailed_merge_status": "mergeable"
97122
},
98123
"labels": [{
99124
"id": 206,
@@ -108,8 +133,14 @@
108133
"group_id": 41
109134
}],
110135
"changes": {
111-
"updated_by_id": [null, 1],
112-
"updated_at": ["2017-09-15 16:50:55 UTC", "2017-09-15 16:52:00 UTC"],
136+
"updated_by_id": {
137+
"previous": null,
138+
"current": 1
139+
},
140+
"updated_at": {
141+
"previous": "2017-09-15 16:50:55 UTC",
142+
"current":"2017-09-15 16:52:00 UTC"
143+
},
113144
"labels": {
114145
"previous": [{
115146
"id": 206,
@@ -135,15 +166,30 @@
135166
"type": "ProjectLabel",
136167
"group_id": 41
137168
}]
169+
},
170+
"last_edited_at": {
171+
"previous": null,
172+
"current": "2023-03-15 00:00:10 UTC"
173+
},
174+
"last_edited_by_id": {
175+
"previous": null,
176+
"current": 3278533
138177
}
139178
},
140179
"assignees": [
141180
{
142181
"id": 6,
143182
"name": "User1",
144183
"username": "user1",
145-
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
146-
"email": "[email protected]"
184+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
185+
}
186+
],
187+
"reviewers": [
188+
{
189+
"id": 6,
190+
"name": "User1",
191+
"username": "user1",
192+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
147193
}
148194
]
149195
}

0 commit comments

Comments
 (0)