Skip to content

Commit fd79d01

Browse files
silkehDean Karn
and
Dean Karn
authored
Add support for confidential comment events (#154)
Add the required types and hooks for confidential comment events, and update the relevant fixtures with the latest GitLab examples. Note that the types can be differentiated using `event_type`, which is `note` or `confidential_note`. Co-authored-by: Dean Karn <[email protected]>
1 parent 0d87ac3 commit fd79d01

File tree

5 files changed

+150
-3
lines changed

5 files changed

+150
-3
lines changed

gitlab/gitlab.go

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
IssuesEvents Event = "Issue Hook"
3131
ConfidentialIssuesEvents Event = "Confidential Issue Hook"
3232
CommentEvents Event = "Note Hook"
33+
ConfidentialCommentEvents Event = "Confidential Note Hook"
3334
MergeRequestEvents Event = "Merge Request Hook"
3435
WikiPageEvents Event = "Wiki Page Hook"
3536
PipelineEvents Event = "Pipeline Hook"
@@ -173,6 +174,11 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
173174
err := json.Unmarshal([]byte(payload), &pl)
174175
return pl, err
175176

177+
case ConfidentialCommentEvents:
178+
var pl ConfidentialCommentEventPayload
179+
err := json.Unmarshal([]byte(payload), &pl)
180+
return pl, err
181+
176182
case CommentEvents:
177183
var pl CommentEventPayload
178184
err := json.Unmarshal([]byte(payload), &pl)

gitlab/gitlab_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ func TestWebhooks(t *testing.T) {
168168
"X-Gitlab-Event": []string{"Note Hook"},
169169
},
170170
},
171+
{
172+
name: "ConfidentialCommentCommitEvent",
173+
event: ConfidentialCommentEvents,
174+
typ: ConfidentialCommentEventPayload{},
175+
filename: "../testdata/gitlab/confidential-comment-commit-event.json",
176+
headers: http.Header{
177+
"X-Gitlab-Event": []string{"Confidential Note Hook"},
178+
},
179+
},
171180
{
172181
name: "CommentMergeRequestEvent",
173182
event: CommentEvents,

gitlab/payload.go

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type PipelineEventPayload struct {
121121
// CommentEventPayload contains the information for GitLab's comment event
122122
type CommentEventPayload struct {
123123
ObjectKind string `json:"object_kind"`
124+
EventType string `json:"event_type"`
124125
User User `json:"user"`
125126
ProjectID int64 `json:"project_id"`
126127
Project Project `json:"project"`
@@ -132,6 +133,13 @@ type CommentEventPayload struct {
132133
Snippet Snippet `json:"snippet"`
133134
}
134135

136+
// ConfidentialCommentEventPayload contains the information for GitLab's confidential issue event
137+
type ConfidentialCommentEventPayload struct {
138+
// The data for confidential issues is currently the same as normal issues,
139+
// so we can just embed the normal issue payload type here.
140+
CommentEventPayload
141+
}
142+
135143
// BuildEventPayload contains the information for GitLab's build status change event
136144
type BuildEventPayload struct {
137145
ObjectKind string `json:"object_kind"`

testdata/gitlab/comment-issue-event.json

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"object_kind": "note",
3+
"event_type": "note",
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_id": 5,
912
"project":{
13+
"id": 5,
1014
"name":"Gitlab Test",
1115
"description":"Aut reprehenderit ut est.",
1216
"web_url":"http://example.com/gitlab-org/gitlab-test",
@@ -47,6 +51,7 @@
4751
"issue": {
4852
"id": 92,
4953
"title": "test",
54+
"assignee_ids": [],
5055
"assignee_id": null,
5156
"author_id": 1,
5257
"project_id": 5,
@@ -57,6 +62,32 @@
5762
"description": "test",
5863
"milestone_id": null,
5964
"state": "closed",
60-
"iid": 17
65+
"iid": 17,
66+
"labels": [
67+
{
68+
"id": 25,
69+
"title": "Afterpod",
70+
"color": "#3e8068",
71+
"project_id": null,
72+
"created_at": "2019-06-05T14:32:20.211Z",
73+
"updated_at": "2019-06-05T14:32:20.211Z",
74+
"template": false,
75+
"description": null,
76+
"type": "GroupLabel",
77+
"group_id": 4
78+
},
79+
{
80+
"id": 86,
81+
"title": "Element",
82+
"color": "#231afe",
83+
"project_id": 4,
84+
"created_at": "2019-06-05T14:32:20.637Z",
85+
"updated_at": "2019-06-05T14:32:20.637Z",
86+
"template": false,
87+
"description": null,
88+
"type": "ProjectLabel",
89+
"group_id": null
90+
}
91+
]
6192
}
62-
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"object_kind": "note",
3+
"event_type": "confidential_note",
4+
"user": {
5+
"id": 1,
6+
"name": "Administrator",
7+
"username": "root",
8+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon",
9+
"email": "[email protected]"
10+
},
11+
"project_id": 5,
12+
"project":{
13+
"id": 5,
14+
"name":"Gitlab Test",
15+
"description":"Aut reprehenderit ut est.",
16+
"web_url":"http://example.com/gitlab-org/gitlab-test",
17+
"avatar_url":null,
18+
"git_ssh_url":"[email protected]:gitlab-org/gitlab-test.git",
19+
"git_http_url":"http://example.com/gitlab-org/gitlab-test.git",
20+
"namespace":"Gitlab Org",
21+
"visibility_level":10,
22+
"path_with_namespace":"gitlab-org/gitlab-test",
23+
"default_branch":"master",
24+
"homepage":"http://example.com/gitlab-org/gitlab-test",
25+
"url":"http://example.com/gitlab-org/gitlab-test.git",
26+
"ssh_url":"[email protected]:gitlab-org/gitlab-test.git",
27+
"http_url":"http://example.com/gitlab-org/gitlab-test.git"
28+
},
29+
"repository":{
30+
"name":"diaspora",
31+
"url":"[email protected]:mike/diaspora.git",
32+
"description":"",
33+
"homepage":"http://example.com/mike/diaspora"
34+
},
35+
"object_attributes": {
36+
"id": 1241,
37+
"note": "Hello world",
38+
"noteable_type": "Issue",
39+
"author_id": 1,
40+
"created_at": "2015-05-17 17:06:40 UTC",
41+
"updated_at": "2015-05-17 17:06:40 UTC",
42+
"project_id": 5,
43+
"attachment": null,
44+
"line_code": null,
45+
"commit_id": "",
46+
"noteable_id": 92,
47+
"system": false,
48+
"st_diff": null,
49+
"url": "http://example.com/gitlab-org/gitlab-test/issues/17#note_1241"
50+
},
51+
"issue": {
52+
"id": 92,
53+
"title": "test",
54+
"assignee_ids": [],
55+
"assignee_id": null,
56+
"author_id": 1,
57+
"project_id": 5,
58+
"created_at": "2015-04-12 14:53:17 UTC",
59+
"updated_at": "2015-04-26 08:28:42 UTC",
60+
"position": 0,
61+
"branch_name": null,
62+
"description": "test",
63+
"milestone_id": null,
64+
"state": "closed",
65+
"iid": 17,
66+
"labels": [
67+
{
68+
"id": 25,
69+
"title": "Afterpod",
70+
"color": "#3e8068",
71+
"project_id": null,
72+
"created_at": "2019-06-05T14:32:20.211Z",
73+
"updated_at": "2019-06-05T14:32:20.211Z",
74+
"template": false,
75+
"description": null,
76+
"type": "GroupLabel",
77+
"group_id": 4
78+
},
79+
{
80+
"id": 86,
81+
"title": "Element",
82+
"color": "#231afe",
83+
"project_id": 4,
84+
"created_at": "2019-06-05T14:32:20.637Z",
85+
"updated_at": "2019-06-05T14:32:20.637Z",
86+
"template": false,
87+
"description": null,
88+
"type": "ProjectLabel",
89+
"group_id": null
90+
}
91+
]
92+
}
93+
}

0 commit comments

Comments
 (0)