gitsources: list only repo with enough permissions

ListUserRepos will return only repos where the user has enough permissions to
create webhooks and deploy keys
This commit is contained in:
Simone Gotti 2019-05-23 16:58:20 +02:00
parent 4d7605a86b
commit 51945513bf
4 changed files with 13 additions and 1 deletions

View File

@ -377,6 +377,10 @@ func (c *Client) ListUserRepos() ([]*gitsource.RepoInfo, error) {
repos := []*gitsource.RepoInfo{}
for _, rr := range remoteRepos {
// keep only repos with admin permissions
if !rr.Permissions.Admin {
continue
}
repos = append(repos, fromGiteaRepo(rr))
}

View File

@ -371,7 +371,13 @@ func (c *Client) ListUserRepos() ([]*gitsource.RepoInfo, error) {
repos := []*gitsource.RepoInfo{}
for _, rr := range remoteRepos {
repos = append(repos, fromGithubRepo(rr))
// keep only repos with admin permissions
if rr.Permissions != nil {
if !(*rr.Permissions)["admin"] {
continue
}
repos = append(repos, fromGithubRepo(rr))
}
}
return repos, nil

View File

@ -256,6 +256,7 @@ func (c *Client) CreateCommitStatus(repopath, commitSHA string, status gitsource
}
func (c *Client) ListUserRepos() ([]*gitsource.RepoInfo, error) {
// get only repos with permission greater or equal to maintainer
opts := &gitlab.ListProjectsOptions{MinAccessLevel: gitlab.AccessLevel(gitlab.MaintainerPermissions)}
remoteRepos, _, err := c.client.Projects.ListProjects(opts)
if err != nil {

View File

@ -43,6 +43,7 @@ type GitSource interface {
CreateRepoWebhook(repopath, url, secret string) error
ParseWebhook(r *http.Request, secret string) (*types.WebhookData, error)
CreateCommitStatus(repopath, commitSHA string, status CommitStatus, targetURL, description, context string) error
// ListUserRepos report repos where the user has the permission to create deploy keys and webhooks
ListUserRepos() ([]*RepoInfo, error)
}