mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-08 15:42:36 +00:00
Merge pull request #444 from Bugagazavr/exp-gitlabfix
Fix gitlab permissions sync #415
This commit is contained in:
commit
73d2f5c1ca
2 changed files with 117 additions and 27 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/Bugagazavr/go-gitlab-client"
|
"github.com/Bugagazavr/go-gitlab-client"
|
||||||
"github.com/drone/drone/shared/model"
|
"github.com/drone/drone/shared/model"
|
||||||
|
@ -75,15 +76,22 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) {
|
||||||
GitURL: item.HttpRepoUrl,
|
GitURL: item.HttpRepoUrl,
|
||||||
SSHURL: item.SshRepoUrl,
|
SSHURL: item.SshRepoUrl,
|
||||||
Role: &model.Perm{},
|
Role: &model.Perm{},
|
||||||
|
Timeout: 900,
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.Private {
|
if repo.Private {
|
||||||
repo.CloneURL = repo.SSHURL
|
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
|
// if no permissions we should skip the repository
|
||||||
// entirely, since this should never happen
|
// entirely, since this should never happen
|
||||||
if repo.Owner != user.Login && item.Permissions == nil {
|
if repo.Owner != user.Login && project.Permissions == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +103,9 @@ func (r *Gitlab) GetRepos(user *model.User) ([]*model.Repo, error) {
|
||||||
repo.Role.Write = true
|
repo.Role.Write = true
|
||||||
repo.Role.Read = true
|
repo.Role.Read = true
|
||||||
} else {
|
} else {
|
||||||
repo.Role.Admin = IsAdmin(item)
|
repo.Role.Admin = IsAdmin(project)
|
||||||
repo.Role.Write = IsWrite(item)
|
repo.Role.Write = IsWrite(project)
|
||||||
repo.Role.Read = IsRead(item)
|
repo.Role.Read = IsRead(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
repos = append(repos, &repo)
|
repos = append(repos, &repo)
|
||||||
|
|
128
plugin/remote/gitlab/testdata/testdata.go
vendored
128
plugin/remote/gitlab/testdata/testdata.go
vendored
|
@ -18,6 +18,12 @@ func NewServer() *httptest.Server {
|
||||||
case "/api/v3/projects":
|
case "/api/v3/projects":
|
||||||
w.Write(projectsPayload)
|
w.Write(projectsPayload)
|
||||||
return
|
return
|
||||||
|
case "/api/v3/projects/4":
|
||||||
|
w.Write(project4Paylod)
|
||||||
|
return
|
||||||
|
case "/api/v3/projects/6":
|
||||||
|
w.Write(project6Paylod)
|
||||||
|
return
|
||||||
case "/api/v3/session":
|
case "/api/v3/session":
|
||||||
w.Write(sessionPayload)
|
w.Write(sessionPayload)
|
||||||
return
|
return
|
||||||
|
@ -68,17 +74,7 @@ var projectsPayload = []byte(`
|
||||||
"path": "diaspora",
|
"path": "diaspora",
|
||||||
"updated_at": "2013-09-30T13: 46: 02Z"
|
"updated_at": "2013-09-30T13: 46: 02Z"
|
||||||
},
|
},
|
||||||
"archived": false,
|
"archived": false
|
||||||
"permissions": {
|
|
||||||
"project_access": {
|
|
||||||
"access_level": 10,
|
|
||||||
"notification_level": 3
|
|
||||||
},
|
|
||||||
"group_access": {
|
|
||||||
"access_level": 50,
|
|
||||||
"notification_level": 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
|
@ -90,7 +86,7 @@ var projectsPayload = []byte(`
|
||||||
"http_url_to_repo": "http://example.com/brightbox/puppet.git",
|
"http_url_to_repo": "http://example.com/brightbox/puppet.git",
|
||||||
"web_url": "http://example.com/brightbox/puppet",
|
"web_url": "http://example.com/brightbox/puppet",
|
||||||
"owner": {
|
"owner": {
|
||||||
"id": 4,
|
"id": 4,
|
||||||
"name": "Brightbox",
|
"name": "Brightbox",
|
||||||
"created_at": "2013-09-30T13:46:02Z"
|
"created_at": "2013-09-30T13:46:02Z"
|
||||||
},
|
},
|
||||||
|
@ -113,21 +109,107 @@ var projectsPayload = []byte(`
|
||||||
"path": "brightbox",
|
"path": "brightbox",
|
||||||
"updated_at": "2013-09-30T13:46:02Z"
|
"updated_at": "2013-09-30T13:46:02Z"
|
||||||
},
|
},
|
||||||
"archived": false,
|
"archived": false
|
||||||
"permissions": {
|
|
||||||
"project_access": {
|
|
||||||
"access_level": 10,
|
|
||||||
"notification_level": 3
|
|
||||||
},
|
|
||||||
"group_access": {
|
|
||||||
"access_level": 50,
|
|
||||||
"notification_level": 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
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
|
// sample org list response
|
||||||
var sessionPayload = []byte(`
|
var sessionPayload = []byte(`
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue