-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups_subgroup.go
85 lines (74 loc) · 3.13 KB
/
groups_subgroup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gerrit
import (
"context"
"fmt"
"net/http"
)
// ListSubgroups lists the directly subgroups of a group.
// The entries in the list are sorted by group name and UUID.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#list-subgroups
func (g *Group) ListSubgroups(ctx context.Context) (*[]GroupInfo, *http.Response, error) {
v := new([]GroupInfo)
u := fmt.Sprintf("groups/%s/groups/", g.Base)
resp, err := g.gerrit.Requester.Call(ctx, "GET", u, nil, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// GetSubGroup retrieves a subgroup.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#get-subgroup
func (g *Group) GetSubGroup(ctx context.Context, groupID string) (*GroupInfo, *http.Response, error) {
v := new(GroupInfo)
u := fmt.Sprintf("groups/%s/groups/%s", g.Base, groupID)
resp, err := g.gerrit.Requester.Call(ctx, "GET", u, nil, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// AddSubgroup adds an internal or external group as subgroup to a Gerrit internal group
// External groups must be specified using the UUID.
//
// As response a GroupInfo entity is returned that describes the subgroup.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#add-subgroup
func (g *Group) AddSubgroup(ctx context.Context, groupID string) (*GroupInfo, *http.Response, error) {
v := new(GroupInfo)
u := fmt.Sprintf("groups/%s/groups/%s", g.Base, groupID)
resp, err := g.gerrit.Requester.Call(ctx, "PUT", u, nil, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// AddSubgroups adds one or several groups as subgroups to a Gerrit internal group.
// The subgroups to be added must be provided in the request body as a GroupsInput entity.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#add-subgroups
func (g *Group) AddSubgroups(ctx context.Context, input *GroupsInput) (*[]GroupInfo, *http.Response, error) {
v := new([]GroupInfo)
u := fmt.Sprintf("groups/%s/groups", g.Base)
resp, err := g.gerrit.Requester.Call(ctx, "POST", u, input, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// RemoveSubgroup removes a subgroup from a Gerrit internal group.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#remove-subgroup
func (g *Group) RemoveSubgroup(ctx context.Context, groupID string) (*http.Response, error) {
u := fmt.Sprintf("groups/%s/groups/%s", g.Base, groupID)
return g.gerrit.Requester.Call(ctx, "DELETE", u, nil, nil)
}
// RemoveSubgroups removes one or several subgroups from a Gerrit internal group.
// The groups to be deleted from the group must be provided in the request body as a GroupsInput entity.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-groups.html#remove-subgroup
func (g *Group) RemoveSubgroups(ctx context.Context, groupID string, input *GroupsInput) (*http.Response, error) {
u := fmt.Sprintf("groups/%s/groups.delete", groupID)
return g.gerrit.Requester.Call(ctx, "POST", u, input, nil)
}