Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Impl gitlab release #4

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
BuildEvents Event = "Build Hook"
JobEvents Event = "Job Hook"
DeploymentEvents Event = "Deployment Hook"
ReleaseEvents Event = "Release Hook"
SystemHookEvents Event = "System Hook"
objectPush string = "push"
objectTag string = "tag_push"
Expand Down Expand Up @@ -353,6 +354,10 @@ func eventParsing(gitLabEvent Event, events []Event, payload []byte) (interface{
return nil, fmt.Errorf("unknown system hook event %s", gitLabEvent)
}
}
case ReleaseEvents:
var pl ReleaseEventPayload
err := json.Unmarshal([]byte(payload), &pl)
return pl, err
default:
return nil, fmt.Errorf("unknown event %s", gitLabEvent)
}
Expand Down
9 changes: 9 additions & 0 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ func TestWebhooks(t *testing.T) {
"X-Gitlab-Event": []string{"Deployment Hook"},
},
},
{
name: "ReleaseEvent",
event: ReleaseEvents,
typ: ReleaseEventPayload{},
filename: "../testdata/gitlab/release-event.json",
headers: http.Header{
"X-Gitlab-Event": []string{"Release Hook"},
},
},
}

for _, tt := range tests {
Expand Down
37 changes: 37 additions & 0 deletions gitlab/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,43 @@ type GroupMemberUpdatedEventPayload struct {
UserID int64 `json:"user_id"`
}

// ReleaseEventPayload contains the information about GitLab's release event
type ReleaseEventPayload struct {
ID int `json:"id"`
CreatedAt customTime `json:"created_at"`
Description string `json:"description"`
Name string `json:"name"`
ReleasedAt customTime `json:"released_at"`
Tag string `json:"tag"`
ObjectKind string `json:"object_kind"`
Project Project `json:"project"`
URL string `json:"url"`
Action string `json:"action"`
Assets Assets `json:"assets"`
}

// Assets represent artefacts and links associated to a release
type Assets struct {
Count int `json:"count"`
Links []Link `json:"links"`
Sources []AssetSource `json:"sources"`
}

// Link represent a generic html link
type Link struct {
ID int `json:"id"`
External bool `json:"external"`
LinkType string `json:"link_type"`
Name string `json:"name"`
URL string `json:"url"`
}

// AssetSource represent the download url for an asset
type AssetSource struct {
Format string `json:"format"`
URL string `json:"url"`
}

// Issue contains all of the GitLab issue information
type Issue struct {
ID int64 `json:"id"`
Expand Down
70 changes: 70 additions & 0 deletions testdata/gitlab/release-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"id": 1,
"created_at": "2020-11-02 12:55:12 UTC",
"description": "v1.1 has been released",
"name": "v1.1",
"released_at": "2020-11-02 12:55:12 UTC",
"tag": "v1.1",
"object_kind": "release",
"project": {
"id": 2,
"name": "release-webhook-example",
"description": "",
"web_url": "https://example.com/gitlab-org/release-webhook-example",
"avatar_url": null,
"git_ssh_url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
"git_http_url": "https://example.com/gitlab-org/release-webhook-example.git",
"namespace": "Gitlab",
"visibility_level": 0,
"path_with_namespace": "gitlab-org/release-webhook-example",
"default_branch": "master",
"ci_config_path": null,
"homepage": "https://example.com/gitlab-org/release-webhook-example",
"url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
"ssh_url": "ssh://[email protected]/gitlab-org/release-webhook-example.git",
"http_url": "https://example.com/gitlab-org/release-webhook-example.git"
},
"url": "https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1",
"action": "create",
"assets": {
"count": 5,
"links": [
{
"id": 1,
"external": true,
"link_type": "other",
"name": "Changelog",
"url": "https://example.net/changelog"
}
],
"sources": [
{
"format": "zip",
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.zip"
},
{
"format": "tar.gz",
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar.gz"
},
{
"format": "tar.bz2",
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar.bz2"
},
{
"format": "tar",
"url": "https://example.com/gitlab-org/release-webhook-example/-/archive/v1.1/release-webhook-example-v1.1.tar"
}
]
},
"commit": {
"id": "ee0a3fb31ac16e11b9dbb596ad16d4af654d08f8",
"message": "Release v1.1",
"title": "Release v1.1",
"timestamp": "2020-10-31T14:58:32+11:00",
"url": "https://example.com/gitlab-org/release-webhook-example/-/commit/ee0a3fb31ac16e11b9dbb596ad16d4af654d08f8",
"author": {
"name": "Example User",
"email": "[email protected]"
}
}
}