Added push tag event support

This commit is contained in:
Kirill Zaitsev 2015-08-22 22:55:08 +03:00 committed by Kirilll Zaitsev
parent 00284dd879
commit ce50e0fd4b
3 changed files with 63 additions and 1 deletions

View file

@ -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
}

View file

@ -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()
})

View file

@ -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",