Commit 09e3beda authored by Sander van Harmelen's avatar Sander van Harmelen

Update all Group related calls

The groups.go file still needs to be split into a groups.go and members.go file. But I’ll leave that for a later PR.
parent 16529bb9
...@@ -18,6 +18,7 @@ package gitlab ...@@ -18,6 +18,7 @@ package gitlab
import ( import (
"fmt" "fmt"
"net/url"
"time" "time"
) )
...@@ -33,12 +34,19 @@ type GroupsService struct { ...@@ -33,12 +34,19 @@ type GroupsService struct {
// //
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html // GitLab API docs: https://docs.gitlab.com/ce/api/groups.html
type Group struct { type Group struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
Description string `json:"description"` Description string `json:"description"`
Projects []*Project `json:"projects"` AvatarURL string `json:"avatar_url"`
Statistics *StorageStatistics `json:"statistics"` FullName string `json:"full_name"`
FullPath string `json:"full_path"`
LFSEnabled bool `json:"lfs_enabled"`
Projects []*Project `json:"projects"`
Statistics *StorageStatistics `json:"statistics"`
RequestAccessEnabled bool `json:"request_access_enabled"`
Visibility *VisibilityLevelValue `json:"visibility"`
WebURL string `json:"web_url"`
} }
// ListGroupsOptions represents the available ListGroups() options. // ListGroupsOptions represents the available ListGroups() options.
...@@ -46,11 +54,15 @@ type Group struct { ...@@ -46,11 +54,15 @@ type Group struct {
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#list-project-groups // GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#list-project-groups
type ListGroupsOptions struct { type ListGroupsOptions struct {
ListOptions ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"` AllAvailable *bool `url:"all_available,omitempty" json:"all_available,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"` OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
} }
// ListGroups gets a list of groups. (As user: my groups, as admin: all groups) // ListGroups gets a list of groups (as user: my groups, as admin: all groups).
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-project-groups // https://docs.gitlab.com/ce/api/groups.html#list-project-groups
...@@ -77,7 +89,7 @@ func (s *GroupsService) GetGroup(gid interface{}, options ...OptionFunc) (*Group ...@@ -77,7 +89,7 @@ func (s *GroupsService) GetGroup(gid interface{}, options ...OptionFunc) (*Group
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s", group) u := fmt.Sprintf("groups/%s", url.QueryEscape(group))
req, err := s.client.NewRequest("GET", u, nil, options) req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil { if err != nil {
...@@ -97,10 +109,12 @@ func (s *GroupsService) GetGroup(gid interface{}, options ...OptionFunc) (*Group ...@@ -97,10 +109,12 @@ func (s *GroupsService) GetGroup(gid interface{}, options ...OptionFunc) (*Group
// //
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#new-group // GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#new-group
type CreateGroupOptions struct { type CreateGroupOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"` Name *string `url:"name,omitempty" json:"name,omitempty"`
Path *string `url:"path,omitempty" json:"path,omitempty"` Path *string `url:"path,omitempty" json:"path,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"`
VisibilityLevel *VisibilityLevelValue `url:"visibility" json:"visibility,omitempty"` LFSEnabled *bool `url:"lfs_enabled,omitempty" json:"lfs_enabled,omitempty"`
RequestAccessEnabled *bool `url:"request_access_enabled,omitempty" json:"request_access_enabled,omitempty"`
VisibilityLevel *VisibilityLevelValue `url:"visibility,omitempty" json:"visibility,omitempty"`
} }
// CreateGroup creates a new project group. Available only for users who can // CreateGroup creates a new project group. Available only for users who can
...@@ -132,7 +146,7 @@ func (s *GroupsService) TransferGroup(gid interface{}, project int, options ...O ...@@ -132,7 +146,7 @@ func (s *GroupsService) TransferGroup(gid interface{}, project int, options ...O
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s/projects/%d", group, project) u := fmt.Sprintf("groups/%s/projects/%d", url.QueryEscape(group), project)
req, err := s.client.NewRequest("POST", u, nil, options) req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil { if err != nil {
...@@ -148,6 +162,37 @@ func (s *GroupsService) TransferGroup(gid interface{}, project int, options ...O ...@@ -148,6 +162,37 @@ func (s *GroupsService) TransferGroup(gid interface{}, project int, options ...O
return g, resp, err return g, resp, err
} }
// UpdateGroupOptions represents the set of available options to update a Group;
// as of today these are exactly the same available when creating a new Group.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#update-group
type UpdateGroupOptions CreateGroupOptions
// UpdateGroup updates an existing group; only available to group owners and
// administrators.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#update-group
func (s *GroupsService) UpdateGroup(gid interface{}, opt *UpdateGroupOptions, options ...OptionFunc) (*Group, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s", url.QueryEscape(group))
req, err := s.client.NewRequest("PUT", u, opt, options)
if err != nil {
return nil, nil, err
}
g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// DeleteGroup removes group with all projects inside. // DeleteGroup removes group with all projects inside.
// //
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#remove-group // GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#remove-group
...@@ -156,7 +201,7 @@ func (s *GroupsService) DeleteGroup(gid interface{}, options ...OptionFunc) (*Re ...@@ -156,7 +201,7 @@ func (s *GroupsService) DeleteGroup(gid interface{}, options ...OptionFunc) (*Re
if err != nil { if err != nil {
return nil, err return nil, err
} }
u := fmt.Sprintf("groups/%s", group) u := fmt.Sprintf("groups/%s", url.QueryEscape(group))
req, err := s.client.NewRequest("DELETE", u, nil, options) req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil { if err != nil {
...@@ -221,7 +266,7 @@ func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersO ...@@ -221,7 +266,7 @@ func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersO
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s/members", group) u := fmt.Sprintf("groups/%s/members", url.QueryEscape(group))
req, err := s.client.NewRequest("GET", u, opt, options) req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil { if err != nil {
...@@ -255,7 +300,7 @@ func (s *GroupsService) ListGroupProjects(gid interface{}, opt *ListGroupProject ...@@ -255,7 +300,7 @@ func (s *GroupsService) ListGroupProjects(gid interface{}, opt *ListGroupProject
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s/projects", group) u := fmt.Sprintf("groups/%s/projects", url.QueryEscape(group))
req, err := s.client.NewRequest("GET", u, opt, options) req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil { if err != nil {
...@@ -288,7 +333,7 @@ func (s *GroupsService) AddGroupMember(gid interface{}, opt *AddGroupMemberOptio ...@@ -288,7 +333,7 @@ func (s *GroupsService) AddGroupMember(gid interface{}, opt *AddGroupMemberOptio
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s/members", group) u := fmt.Sprintf("groups/%s/members", url.QueryEscape(group))
req, err := s.client.NewRequest("POST", u, opt, options) req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil { if err != nil {
...@@ -322,7 +367,7 @@ func (s *GroupsService) UpdateGroupMember(gid interface{}, user int, opt *Update ...@@ -322,7 +367,7 @@ func (s *GroupsService) UpdateGroupMember(gid interface{}, user int, opt *Update
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("groups/%s/members/%d", group, user) u := fmt.Sprintf("groups/%s/members/%d", url.QueryEscape(group), user)
req, err := s.client.NewRequest("PUT", u, opt, options) req, err := s.client.NewRequest("PUT", u, opt, options)
if err != nil { if err != nil {
...@@ -347,7 +392,7 @@ func (s *GroupsService) RemoveGroupMember(gid interface{}, user int, options ... ...@@ -347,7 +392,7 @@ func (s *GroupsService) RemoveGroupMember(gid interface{}, user int, options ...
if err != nil { if err != nil {
return nil, err return nil, err
} }
u := fmt.Sprintf("groups/%s/members/%d", group, user) u := fmt.Sprintf("groups/%s/members/%d", url.QueryEscape(group), user)
req, err := s.client.NewRequest("DELETE", u, nil, options) req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil { if err != nil {
......
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