1package gerrit 2 3import ( 4 "fmt" 5) 6 7// ListIncludedGroups lists the directly included groups of a group. 8// The entries in the list are sorted by group name and UUID. 9// 10// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#included-groups 11func (s *GroupsService) ListIncludedGroups(groupID string) (*[]GroupInfo, *Response, error) { 12 u := fmt.Sprintf("groups/%s/groups/", groupID) 13 14 req, err := s.client.NewRequest("GET", u, nil) 15 if err != nil { 16 return nil, nil, err 17 } 18 19 v := new([]GroupInfo) 20 resp, err := s.client.Do(req, v) 21 if err != nil { 22 return nil, resp, err 23 } 24 25 return v, resp, err 26} 27 28// GetIncludedGroup retrieves an included group. 29// 30// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#get-included-group 31func (s *GroupsService) GetIncludedGroup(groupID, includeGroupID string) (*GroupInfo, *Response, error) { 32 u := fmt.Sprintf("groups/%s/groups/%s", groupID, includeGroupID) 33 34 req, err := s.client.NewRequest("GET", u, nil) 35 if err != nil { 36 return nil, nil, err 37 } 38 39 v := new(GroupInfo) 40 resp, err := s.client.Do(req, v) 41 if err != nil { 42 return nil, resp, err 43 } 44 45 return v, resp, err 46} 47 48// IncludeGroup includes an internal or external group into a Gerrit internal group. 49// External groups must be specified using the UUID. 50// 51// As response a GroupInfo entity is returned that describes the included group. 52// The request also succeeds if the group is already included in this group, but then the HTTP response code is 200 OK. 53// 54// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#include-group 55func (s *GroupsService) IncludeGroup(groupID, includeGroupID string) (*GroupInfo, *Response, error) { 56 u := fmt.Sprintf("groups/%s/groups/%s", groupID, includeGroupID) 57 58 req, err := s.client.NewRequest("PUT", u, nil) 59 if err != nil { 60 return nil, nil, err 61 } 62 63 v := new(GroupInfo) 64 resp, err := s.client.Do(req, v) 65 if err != nil { 66 return nil, resp, err 67 } 68 69 return v, resp, err 70} 71 72// IncludeGroups includes one or several groups into a Gerrit internal group. 73// The groups to be included into the group must be provided in the request body as a GroupsInput entity. 74// 75// As response a list of GroupInfo entities is returned that describes the groups that were specified in the GroupsInput. 76// A GroupInfo entity is returned for each group specified in the input, independently of whether the group was newly included into the group or whether the group was already included in the group. 77// 78// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#include-groups 79func (s *GroupsService) IncludeGroups(groupID string, input *GroupsInput) (*[]GroupInfo, *Response, error) { 80 u := fmt.Sprintf("groups/%s/groups", groupID) 81 82 req, err := s.client.NewRequest("POST", u, input) 83 if err != nil { 84 return nil, nil, err 85 } 86 87 v := new([]GroupInfo) 88 resp, err := s.client.Do(req, v) 89 if err != nil { 90 return nil, resp, err 91 } 92 93 return v, resp, err 94} 95 96// DeleteIncludedGroup deletes an included group from a Gerrit internal group. 97// 98// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#include-group 99func (s *GroupsService) DeleteIncludedGroup(groupID, includeGroupID string) (*Response, error) { 100 u := fmt.Sprintf("groups/%s/groups/%s", groupID, includeGroupID) 101 return s.client.DeleteRequest(u, nil) 102} 103 104// DeleteIncludedGroups delete one or several included groups from a Gerrit internal group. 105// The groups to be deleted from the group must be provided in the request body as a GroupsInput entity. 106// 107// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#delete-included-groups 108func (s *GroupsService) DeleteIncludedGroups(groupID string, input *GroupsInput) (*Response, error) { 109 u := fmt.Sprintf("groups/%s/groups.delete", groupID) 110 111 req, err := s.client.NewRequest("POST", u, input) 112 if err != nil { 113 return nil, err 114 } 115 116 return s.client.Do(req, nil) 117} 118