Commit 471a8db7 authored by Rodrigo Valentim's avatar Rodrigo Valentim Committed by Sander van Harmelen

Added function to get all users from a specific project (#312)

* Added function to get all users from a specific project

* Added function to get all users from a specific project - Pull Request changes

* Added function to get all users from a specific project
parent 7bcfc037
......@@ -88,6 +88,16 @@ type Project struct {
CIConfigPath *string `json:"ci_config_path"`
}
// ProjectUser represents a GitLab project.
type ProjectUser struct {
ID int `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
State string `json:"state"`
AvatarUrl string `json:"avatar_url"`
WebUrl string `json:"web_url"`
}
// Repository represents a repository.
type Repository struct {
Name string `json:"name"`
......@@ -193,6 +203,14 @@ type ListProjectsOptions struct {
WithMergeRequestsEnabled *bool `url:"with_merge_requests_enabled,omitempty" json:"with_merge_requests_enabled,omitempty"`
}
// ListProjectUserOptions represents the available ListProjects() options.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#get-project-users
type ListProjectUserOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
}
// ListProjects gets a list of projects accessible by the authenticated user.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
......@@ -236,6 +254,31 @@ func (s *ProjectsService) ListUserProjects(uid interface{}, opt *ListProjectsOpt
return p, resp, err
}
// ListProjectsUsers gets a list of users for the given project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/projects.html#get-project-users
func (s *ProjectsService) ListProjectsUsers(pid interface{}, opt *ListProjectUserOptions, options ...OptionFunc) ([]*ProjectUser, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/users", project)
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}
var p []*ProjectUser
resp, err := s.client.Do(req, &p)
if err != nil {
return nil, resp, err
}
return p, resp, err
}
// GetProject gets a specific project, identified by project ID or
// NAMESPACE/PROJECT_NAME, which is owned by the authenticated user.
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment