feat: Add Gitlab hook.

This commit is contained in:
Nicolas Carlier 2015-03-20 10:57:21 +00:00
parent 82a355554e
commit baf50c9709
5 changed files with 83 additions and 0 deletions

42
assets/gitlab.json Normal file
View File

@ -0,0 +1,42 @@
{
"object_kind": "push",
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"user_id": 4,
"user_name": "John Smith",
"user_email": "john@example.com",
"project_id": 15,
"repository": {
"name": "Diaspora",
"url": "git@example.com:mike/diasporadiaspora.git",
"description": "",
"homepage": "http://example.com/mike/diaspora",
"git_http_url":"http://example.com/mike/diaspora.git",
"git_ssh_url":"git@example.com:mike/diaspora.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
}

4
scripts/gitlab/echo.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
echo "gitlab echo: $@"

30
src/hook/gitlab_hook.go Normal file
View File

@ -0,0 +1,30 @@
package hook
import (
"encoding/json"
"net/http"
)
type GitlabRecord struct {
Repository struct {
Name string `json:"name"`
URL string `json:"git_ssh_url"`
} `json:"repository"`
}
func (r *GitlabRecord) GetURL() string {
return r.Repository.URL
}
func (r *GitlabRecord) GetName() string {
return r.Repository.Name
}
func (r *GitlabRecord) Decode(req *http.Request) error {
decoder := json.NewDecoder(req.Body)
err := decoder.Decode(&r)
if err != nil {
return err
}
return nil
}

View File

@ -17,6 +17,8 @@ func RecordFactory(hookname string) (Record, error) {
return new(BitbucketRecord), nil
case "github":
return new(GithubRecord), nil
case "gitlab":
return new(GitlabRecord), nil
case "docker":
return new(DockerRecord), nil
default:

View File

@ -22,6 +22,11 @@ curl -H "Content-Type: application/json" \
--data @assets/github.json \
http://$IP:8080/github/echo
echo "Test Gitlab hook"
curl -H "Content-Type: application/json" \
--data @assets/gitlab.json \
http://$IP:8080/gitlab/echo
echo "Test Docker hook"
curl -H "Content-Type: application/json" \
--data @assets/docker.json \