diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index b6bd83633..c0e988896 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" @@ -75,15 +76,22 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) { GitURL: item.HttpRepoUrl, SSHURL: item.SshRepoUrl, Role: &model.Perm{}, + Timeout: 900, } if repo.Private { 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 +103,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) 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(` {