From ce50e0fd4b5bedfd3e5a7548e268830923f6bfca Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Sat, 22 Aug 2015 22:55:08 +0300 Subject: [PATCH] Added push tag event support --- pkg/remote/builtin/gitlab/gitlab.go | 2 +- pkg/remote/builtin/gitlab/gitlab_test.go | 18 +++++++++ pkg/remote/builtin/gitlab/testdata/hooks.go | 44 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/pkg/remote/builtin/gitlab/gitlab.go b/pkg/remote/builtin/gitlab/gitlab.go index fc6713163..c6b1bacf3 100644 --- a/pkg/remote/builtin/gitlab/gitlab.go +++ b/pkg/remote/builtin/gitlab/gitlab.go @@ -233,7 +233,7 @@ func (r *Gitlab) Hook(req *http.Request) (*common.Hook, error) { } return mergeRequest(parsed, req) - case "push": + case "tag_push", "push": if len(parsed.After) == 0 || parsed.TotalCommitsCount == 0 { return nil, nil } diff --git a/pkg/remote/builtin/gitlab/gitlab_test.go b/pkg/remote/builtin/gitlab/gitlab_test.go index 832507195..1421f711b 100644 --- a/pkg/remote/builtin/gitlab/gitlab_test.go +++ b/pkg/remote/builtin/gitlab/gitlab_test.go @@ -124,6 +124,24 @@ func Test_Gitlab(t *testing.T) { g.Assert(err == nil).IsTrue() g.Assert(hook.Repo.Owner).Equal("diaspora") g.Assert(hook.Repo.Name).Equal("diaspora-client") + g.Assert(hook.Commit.Ref).Equal("refs/heads/master") + + g.Assert(hook.PullRequest == nil).IsTrue() + }) + + g.It("Should parse tag push hook", func() { + req, _ := http.NewRequest( + "POST", + "http://example.com/api/hook?owner=diaspora&name=diaspora-client", + bytes.NewReader(testdata.TagHook), + ) + + hook, err := gitlab.Hook(req) + + g.Assert(err == nil).IsTrue() + g.Assert(hook.Repo.Owner).Equal("diaspora") + g.Assert(hook.Repo.Name).Equal("diaspora-client") + g.Assert(hook.Commit.Ref).Equal("refs/tags/v1.0.0") g.Assert(hook.PullRequest == nil).IsTrue() }) diff --git a/pkg/remote/builtin/gitlab/testdata/hooks.go b/pkg/remote/builtin/gitlab/testdata/hooks.go index 836d29831..9f4a5cea1 100644 --- a/pkg/remote/builtin/gitlab/testdata/hooks.go +++ b/pkg/remote/builtin/gitlab/testdata/hooks.go @@ -1,5 +1,49 @@ package testdata +var TagHook = []byte(` +{ + "object_kind": "tag_push", + "ref": "refs/tags/v1.0.0", + "before": "0000000000000000000000000000000000000000", + "after": "82b3d5ae55f7080f1e6022629cdb57bfae7cccc7", + "user_id": 1, + "user_name": "John Smith", + "project_id": 1, + "repository": { + "name": "jsmith", + "url": "ssh://git@example.com/jsmith/example.git", + "description": "", + "homepage": "http://example.com/jsmith/example", + "git_http_url":"http://example.com/jsmith/example.git", + "git_ssh_url":"git@example.com:jsmith/example.git", + "visibility_level":0 + }, + "commits": [ + { + "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "message": "Update Catalan translation to e38cb41.", + "timestamp": "2011-12-12T14:27:31+02:00", + "url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "author": { + "name": "Jordi Mallach", + "email": "jordi@softcatala.org" + } + }, + { + "id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "message": "fixed readme", + "timestamp": "2012-01-03T23:36:29+02:00", + "url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "author": { + "name": "GitLab dev user", + "email": "gitlabdev@dv6700.(none)" + } + } + ], + "total_commits_count": 4 +} +`) + var MergeRequestHook = []byte(` { "object_kind": "merge_request",