Added support for new attributes
This commit is contained in:
parent
19a7ae53e6
commit
39dc9f7c76
2 changed files with 45 additions and 21 deletions
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue