Skip to content

Commit 58e552d

Browse files
authored
1 parent 2d5aa68 commit 58e552d

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

gitlab/gitlab.go

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const (
3636
BuildEvents Event = "Build Hook"
3737
JobEvents Event = "Job Hook"
3838
DeploymentEvents Event = "Deployment Hook"
39+
ReleaseEvents Event = "Release Hook"
3940
SystemHookEvents Event = "System Hook"
4041
objectPush string = "push"
4142
objectTag string = "tag_push"
@@ -353,6 +354,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
353354
return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent)
354355
}
355356
}
357+
case ReleaseEvents:
358+
var pl ReleaseEventPayload
359+
err := json.Unmarshal([]byte(payload), &pl)
360+
return pl, err
356361
default:
357362
return nil, fmt.Errorf("unknown event %s", gitLabEvent)
358363
}

gitlab/gitlab_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ func TestWebhooks(t *testing.T) {
249249
"X-Gitlab-Event": []string{"Deployment Hook"},
250250
},
251251
},
252+
{
253+
name: "ReleaseEvent",
254+
event: ReleaseEvents,
255+
typ: ReleaseEventPayload{},
256+
filename: "../testdata/gitlab/release-event.json",
257+
headers: http.Header{
258+
"X-Gitlab-Event": []string{"Release Hook"},
259+
},
260+
},
252261
}
253262

254263
for _, tt := range tests {

gitlab/payload.go

+37
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,43 @@ type GroupMemberUpdatedEventPayload struct {
485485
UserID int64 `json:"user_id"`
486486
}
487487

488+
// ReleaseEventPayload contains the information about GitLab's release event
489+
type ReleaseEventPayload struct {
490+
ID int `json:"id"`
491+
CreatedAt customTime `json:"created_at"`
492+
Description string `json:"description"`
493+
Name string `json:"name"`
494+
ReleasedAt customTime `json:"released_at"`
495+
Tag string `json:"tag"`
496+
ObjectKind string `json:"object_kind"`
497+
Project Project `json:"project"`
498+
URL string `json:"url"`
499+
Action string `json:"action"`
500+
Assets Assets `json:"assets"`
501+
}
502+
503+
// Assets represent artefacts and links associated to a release
504+
type Assets struct {
505+
Count int `json:"count"`
506+
Links []Link `json:"links"`
507+
Sources []AssetSource `json:"sources"`
508+
}
509+
510+
// Link represent a generic html link
511+
type Link struct {
512+
ID int `json:"id"`
513+
External bool `json:"external"`
514+
LinkType string `json:"link_type"`
515+
Name string `json:"name"`
516+
URL string `json:"url"`
517+
}
518+
519+
// AssetSource represent the download url for an asset
520+
type AssetSource struct {
521+
Format string `json:"format"`
522+
URL string `json:"url"`
523+
}
524+
488525
// Issue contains all of the GitLab issue information
489526
type Issue struct {
490527
ID int64 `json:"id"`

testdata/gitlab/release-event.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"id": 1,
3+
"created_at": "2020-11-02 12:55:12 UTC",
4+
"description": "v1.1 has been released",
5+
"name": "v1.1",
6+
"released_at": "2020-11-02 12:55:12 UTC",
7+
"tag": "v1.1",
8+
"object_kind": "release",
9+
"project": {
10+
"id": 2,
11+
"name": "release-webhook-example",
12+
"description": "",
13+
"web_url": "https://example.com/gitlab-org/release-webhook-example",
14+
"avatar_url": null,
15+
"git_ssh_url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
16+
"git_http_url": "https://example.com/gitlab-org/release-webhook-example.git",
17+
"namespace": "Gitlab",
18+
"visibility_level": 0,
19+
"path_with_namespace": "gitlab-org/release-webhook-example",
20+
"default_branch": "master",
21+
"ci_config_path": null,
22+
"homepage": "https://example.com/gitlab-org/release-webhook-example",
23+
"url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
24+
"ssh_url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
25+
"http_url": "https://example.com/gitlab-org/release-webhook-example.git"
26+
},
27+
"url": "https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1",
28+
"action": "create",
29+
"assets": {
30+
"count": 5,
31+
"links": [
32+
{
33+
"id": 1,
34+
"external": true,
35+
"link_type": "other",
36+
"name": "Changelog",
37+
"url": "https://example.net/changelog"
38+
}
39+
],
40+
"sources": [
41+
{
42+
"format": "zip",
43+
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.zip"
44+
},
45+
{
46+
"format": "tar.gz",
47+
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar.gz"
48+
},
49+
{
50+
"format": "tar.bz2",
51+
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar.bz2"
52+
},
53+
{
54+
"format": "tar",
55+
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar"
56+
}
57+
]
58+
},
59+
"commit": {
60+
"id": "ee0a3fb31ac16e11b9dbb596ad16d4af654d08f8",
61+
"message": "Release v1.1",
62+
"title": "Release v1.1",
63+
"timestamp": "2020-10-31T14:58:32+11:00",
64+
"url": "https://example.com/gitlab-org/release-webhook-example/-/commit/ee0a3fb31ac16e11b9dbb596ad16d4af654d08f8",
65+
"author": {
66+
"name": "Example User",
67+
"email": "[email protected]"
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)