From 39dc9f7c76ea8bf22823c460ecbf1b5e9f379204 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Mon, 22 Feb 2016 22:35:53 +0300 Subject: [PATCH] Added support for new attributes --- remote/gitlab/client/types.go | 18 ++++++++----- remote/gitlab/gitlab.go | 48 ++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/remote/gitlab/client/types.go b/remote/gitlab/client/types.go index dbd3db977..3aeb2f3ec 100644 --- a/remote/gitlab/client/types.go +++ b/remote/gitlab/client/types.go @@ -63,12 +63,17 @@ type Person struct { } type hProject struct { - Name string `json:"name"` - SshUrl string `json:"ssh_url"` - HttpUrl string `json:"http_url"` - VisibilityLevel int `json:"visibility_level"` - WebUrl string `json:"web_url"` - Namespace string `json:"namespace"` + Name string `json:"name"` + SshUrl string `json:"ssh_url"` + HttpUrl string `json:"http_url"` + GitSshUrl string `json:"git_ssh_url"` + GitHttpUrl string `json:"git_http_url"` + AvatarUrl string `json:"avatar_url"` + VisibilityLevel int `json:"visibility_level"` + WebUrl string `json:"web_url"` + PathWithNamespace string `json:"path_with_namespace"` + DefaultBranch string `json:"default_branch"` + Namespace string `json:"namespace"` } type hRepository struct { @@ -123,6 +128,7 @@ type HookPayload struct { UserId int `json:"user_id,omitempty"` UserName string `json:"user_name,omitempty"` ProjectId int `json:"project_id,omitempty"` + Project *hProject `json:"project,omitempty"` Repository *hRepository `json:"repository,omitempty"` Commits []hCommit `json:"commits,omitempty"` TotalCommitsCount int `json:"total_commits_count,omitempty"` diff --git a/remote/gitlab/gitlab.go b/remote/gitlab/gitlab.go index 01b86e482..4eb3cb14e 100644 --- a/remote/gitlab/gitlab.go +++ b/remote/gitlab/gitlab.go @@ -383,27 +383,45 @@ func mergeRequest(parsed *client.HookPayload, req *http.Request) (*model.Repo, * } func push(parsed *client.HookPayload, req *http.Request) (*model.Repo, *model.Build, error) { - var cloneUrl = parsed.Repository.GitHttpUrl - repo := &model.Repo{} repo.Owner = req.FormValue("owner") repo.Name = req.FormValue("name") - repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name) - repo.Link = parsed.Repository.URL - repo.Clone = cloneUrl - repo.Branch = "master" - switch parsed.Repository.VisibilityLevel { - case 0: - repo.IsPrivate = true - case 10: - repo.IsPrivate = true - case 20: - repo.IsPrivate = false + // Since gitlab 8.5, used project instead repository key + // see https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/web_hooks/web_hooks.md#web-hooks + if project := parsed.Project; project != nil { + repo.Avatar = project.AvatarUrl + repo.Link = project.WebUrl + repo.Clone = project.GitHttpUrl + repo.FullName = project.PathWithNamespace + repo.Branch = project.DefaultBranch + + switch project.VisibilityLevel { + case 0: + repo.IsPrivate = true + case 10: + repo.IsPrivate = true + case 20: + repo.IsPrivate = false + } + } else if repository := parsed.Repository; repository != nil { + repo.Link = repository.URL + repo.Clone = repository.GitHttpUrl + repo.Branch = "master" + repo.FullName = fmt.Sprintf("%s/%s", req.FormValue("owner"), req.FormValue("name")) + + switch repository.VisibilityLevel { + case 0: + repo.IsPrivate = true + case 10: + repo.IsPrivate = true + case 20: + repo.IsPrivate = false + } + } else { + return nil, nil, fmt.Errorf("No project/repository keys given") } - repo.FullName = fmt.Sprintf("%s/%s", req.FormValue("owner"), req.FormValue("name")) - build := &model.Build{} build.Event = model.EventPush build.Commit = parsed.After