Skip to content

Commit 0d87ac3

Browse files
exileedDean Karn
and
Dean Karn
authored
Gitlab deployment event (#156)
Added Gitlab deployment event Co-authored-by: Dean Karn <[email protected]>
1 parent 659b2a2 commit 0d87ac3

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

gitlab/gitlab.go

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
PipelineEvents Event = "Pipeline Hook"
3636
BuildEvents Event = "Build Hook"
3737
JobEvents Event = "Job Hook"
38+
DeploymentEvents Event = "Deployment Hook"
3839
SystemHookEvents Event = "System Hook"
3940
objectPush string = "push"
4041
objectTag string = "tag_push"
@@ -208,6 +209,14 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
208209
}
209210
return pl, nil
210211

212+
case DeploymentEvents:
213+
var pl DeploymentEventPayload
214+
err := json.Unmarshal([]byte(payload), &pl)
215+
if err != nil {
216+
return nil, err
217+
}
218+
return pl, nil
219+
211220
case SystemHookEvents:
212221
var pl SystemHookPayload
213222
err := json.Unmarshal([]byte(payload), &pl)

gitlab/gitlab_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ func TestWebhooks(t *testing.T) {
231231
"X-Gitlab-Event": []string{"Build Hook"},
232232
},
233233
},
234+
{
235+
name: "DeploymentEvent",
236+
event: DeploymentEvents,
237+
typ: DeploymentEventPayload{},
238+
filename: "../testdata/gitlab/deployment-event.json",
239+
headers: http.Header{
240+
"X-Gitlab-Event": []string{"Deployment Hook"},
241+
},
242+
},
234243
}
235244

236245
for _, tt := range tests {

gitlab/payload.go

+17
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ type JobEventPayload struct {
182182
Runner Runner `json:"runner"`
183183
}
184184

185+
// DeploymentEventPayload contains the information for GitLab's triggered when a deployment
186+
type DeploymentEventPayload struct {
187+
ObjectKind string `json:"object_kind"`
188+
Status string `json:"status"`
189+
StatusChangeAt string `json:"status_changed_at"`
190+
DeploymentId int64 `json:"deployment_id"`
191+
DeployableId int64 `json:"deployable_id"`
192+
DeployableUrl string `json:"deployable_url"`
193+
Environment string `json:"environment"`
194+
Project Project `json:"project"`
195+
ShortSha string `json:"short_sha"`
196+
User User `json:"user"`
197+
UserUrl string `json:"user_url"`
198+
CommitUrl string `json:"commit_url"`
199+
CommitTitle string `json:"commit_title"`
200+
}
201+
185202
// SystemHookPayload contains the ObjectKind to match with real hook events
186203
type SystemHookPayload struct {
187204
ObjectKind string `json:"object_kind"`

testdata/gitlab/deployment-event.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"object_kind": "deployment",
3+
"status": "success",
4+
"status_changed_at":"2021-04-28 21:50:00 +0200",
5+
"deployment_id": 15,
6+
"deployable_id": 796,
7+
"deployable_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/jobs/796",
8+
"environment": "staging",
9+
"project": {
10+
"id": 30,
11+
"name": "test-deployment-webhooks",
12+
"description": "",
13+
"web_url": "http://10.126.0.2:3000/root/test-deployment-webhooks",
14+
"avatar_url": null,
15+
"git_ssh_url": "ssh://[email protected]:2222/root/test-deployment-webhooks.git",
16+
"git_http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git",
17+
"namespace": "Administrator",
18+
"visibility_level": 0,
19+
"path_with_namespace": "root/test-deployment-webhooks",
20+
"default_branch": "master",
21+
"ci_config_path": "",
22+
"homepage": "http://10.126.0.2:3000/root/test-deployment-webhooks",
23+
"url": "ssh://[email protected]:2222/root/test-deployment-webhooks.git",
24+
"ssh_url": "ssh://[email protected]:2222/root/test-deployment-webhooks.git",
25+
"http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git"
26+
},
27+
"short_sha": "279484c0",
28+
"user": {
29+
"id": 1,
30+
"name": "Administrator",
31+
"username": "root",
32+
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
33+
"email": "[email protected]"
34+
},
35+
"user_url": "http://10.126.0.2:3000/root",
36+
"commit_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/commit/279484c09fbe69ededfced8c1bb6e6d24616b468",
37+
"commit_title": "Add new file"
38+
}

0 commit comments

Comments
 (0)