From afa928af0ca6e0ff45211bfe83fdf1536ec9fef7 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Fri, 5 Sep 2014 21:37:29 +0400 Subject: [PATCH 1/3] Fix gitlab permissions sync #415 --- plugin/remote/gitlab/gitlab.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index b6bd83633..0fa3be4c1 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "net/http" "net/url" + "strconv" "github.com/Bugagazavr/go-gitlab-client" "github.com/drone/drone/shared/model" @@ -81,9 +82,15 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) { repo.CloneURL = repo.SSHURL } + // Fetch current project + project, err := client.Project(strconv.Itoa(item.Id)) + if err != nil { + return nil, err + } + // if no permissions we should skip the repository // entirely, since this should never happen - if repo.Owner != user.Login && item.Permissions == nil { + if repo.Owner != user.Login && project.Permissions == nil { continue } @@ -95,9 +102,9 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) { repo.Role.Write = true repo.Role.Read = true } else { - repo.Role.Admin = IsAdmin(item) - repo.Role.Write = IsWrite(item) - repo.Role.Read = IsRead(item) + repo.Role.Admin = IsAdmin(project) + repo.Role.Write = IsWrite(project) + repo.Role.Read = IsRead(project) } repos = append(repos, &repo) From 49f03cd7e72260e49d344e21b8dafebd8b553b30 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Fri, 5 Sep 2014 22:13:10 +0400 Subject: [PATCH 2/3] Updated mocks --- plugin/remote/gitlab/testdata/testdata.go | 128 ++++++++++++++++++---- 1 file changed, 105 insertions(+), 23 deletions(-) diff --git a/plugin/remote/gitlab/testdata/testdata.go b/plugin/remote/gitlab/testdata/testdata.go index 01d58b0aa..2e1f38539 100644 --- a/plugin/remote/gitlab/testdata/testdata.go +++ b/plugin/remote/gitlab/testdata/testdata.go @@ -18,6 +18,12 @@ func NewServer() *httptest.Server { case "/api/v3/projects": w.Write(projectsPayload) return + case "/api/v3/projects/4": + w.Write(project4Paylod) + return + case "/api/v3/projects/6": + w.Write(project6Paylod) + return case "/api/v3/session": w.Write(sessionPayload) return @@ -68,17 +74,7 @@ var projectsPayload = []byte(` "path": "diaspora", "updated_at": "2013-09-30T13: 46: 02Z" }, - "archived": false, - "permissions": { - "project_access": { - "access_level": 10, - "notification_level": 3 - }, - "group_access": { - "access_level": 50, - "notification_level": 3 - } - } + "archived": false }, { "id": 6, @@ -90,7 +86,7 @@ var projectsPayload = []byte(` "http_url_to_repo": "http://example.com/brightbox/puppet.git", "web_url": "http://example.com/brightbox/puppet", "owner": { - "id": 4, + "id": 4, "name": "Brightbox", "created_at": "2013-09-30T13:46:02Z" }, @@ -113,21 +109,107 @@ var projectsPayload = []byte(` "path": "brightbox", "updated_at": "2013-09-30T13:46:02Z" }, - "archived": false, - "permissions": { - "project_access": { - "access_level": 10, - "notification_level": 3 - }, - "group_access": { - "access_level": 50, - "notification_level": 3 - } - } + "archived": false } ] `) +var project4Paylod = []byte(` +{ + "id": 4, + "description": null, + "default_branch": "master", + "public": false, + "visibility_level": 0, + "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git", + "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git", + "web_url": "http://example.com/diaspora/diaspora-client", + "owner": { + "id": 3, + "name": "Diaspora", + "created_at": "2013-09-30T13: 46: 02Z" + }, + "name": "Diaspora Client", + "name_with_namespace": "Diaspora / Diaspora Client", + "path": "diaspora-client", + "path_with_namespace": "diaspora/diaspora-client", + "issues_enabled": true, + "merge_requests_enabled": true, + "wiki_enabled": true, + "snippets_enabled": false, + "created_at": "2013-09-30T13: 46: 02Z", + "last_activity_at": "2013-09-30T13: 46: 02Z", + "namespace": { + "created_at": "2013-09-30T13: 46: 02Z", + "description": "", + "id": 3, + "name": "Diaspora", + "owner_id": 1, + "path": "diaspora", + "updated_at": "2013-09-30T13: 46: 02Z" + }, + "archived": false, + "permissions": { + "project_access": { + "access_level": 10, + "notification_level": 3 + }, + "group_access": { + "access_level": 50, + "notification_level": 3 + } + } +} +`) + +var project6Paylod = []byte(` +{ + "id": 6, + "description": null, + "default_branch": "master", + "public": false, + "visibility_level": 0, + "ssh_url_to_repo": "git@example.com:brightbox/puppet.git", + "http_url_to_repo": "http://example.com/brightbox/puppet.git", + "web_url": "http://example.com/brightbox/puppet", + "owner": { + "id": 4, + "name": "Brightbox", + "created_at": "2013-09-30T13:46:02Z" + }, + "name": "Puppet", + "name_with_namespace": "Brightbox / Puppet", + "path": "puppet", + "path_with_namespace": "brightbox/puppet", + "issues_enabled": true, + "merge_requests_enabled": true, + "wiki_enabled": true, + "snippets_enabled": false, + "created_at": "2013-09-30T13:46:02Z", + "last_activity_at": "2013-09-30T13:46:02Z", + "namespace": { + "created_at": "2013-09-30T13:46:02Z", + "description": "", + "id": 4, + "name": "Brightbox", + "owner_id": 1, + "path": "brightbox", + "updated_at": "2013-09-30T13:46:02Z" + }, + "archived": false, + "permissions": { + "project_access": { + "access_level": 10, + "notification_level": 3 + }, + "group_access": { + "access_level": 50, + "notification_level": 3 + } + } +} +`) + // sample org list response var sessionPayload = []byte(` { From 068a7583bee1002797d70eb182b871b927b8e12e Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Fri, 5 Sep 2014 22:49:59 +0400 Subject: [PATCH 3/3] Fix timeout --- plugin/remote/gitlab/gitlab.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index 0fa3be4c1..c0e988896 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -76,6 +76,7 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) { GitURL: item.HttpRepoUrl, SSHURL: item.SshRepoUrl, Role: &model.Perm{}, + Timeout: 900, } if repo.Private {