forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups.go
162 lines (130 loc) · 4.25 KB
/
groups.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package gogitlab
import (
"encoding/json"
"strconv"
)
const (
groups_url = "/groups" // Get a list of groups. (As user: my groups or all available, as admin: all groups)
group_url = "/groups/:id" // Get all details of a group
group_projects_url = "/groups/:id/projects" // Get a list of projects in this group
group_url_members = "/groups/:id/members" // Get a list of members in this group
)
// A gitlab group
type Group struct {
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Description string `json:"description,omitempty"`
Visibility Visibility `json:"visibility,omitempty"`
LfsEnabled bool `json:"lfs_enabled,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
WebURL string `json:"web_url,omitempty"`
RequestAccessEnabled bool `json:"request_access_enabled,omitempty"`
FullName string `json:"full_name,omitempty"`
FullPath string `json:"full_path,omitempty"`
ParentId int `json:"parent_id,omitempty"`
SharedRunnersMinutesLimit int `json:"shared_runners_minutes_limit,omitempty"`
Projects []*Project `json:"projects,omitempty"`
}
/*
Get a list of groups. (As user: my groups or all available, as admin: all groups)
*/
func (g *Gitlab) Groups() ([]*Group, error) {
url := g.ResourceUrl(groups_url, nil)
var groups []*Group
contents, err := g.buildAndExecRequest("GET", url, nil)
if err == nil {
err = json.Unmarshal(contents, &groups)
}
return groups, err
}
/*
Get all details of a group
*/
func (g *Gitlab) Group(id string) (*Group, error) {
url, opaque := g.ResourceUrlRaw(group_url, map[string]string{":id": id})
var group *Group
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &group)
}
return group, err
}
/*
Creates a new project group. Available only for users who can create groups.
Required fields on group:
* Name
* Path
Optional fields on group:
* Description
* Visibility
* LfsEnabled
* RequestAccessEnabled
* ParentId
Other fields on group are not supported by the GitLab API
*/
func (g *Gitlab) AddGroup(group *Group) (*Group, error) {
url := g.ResourceUrl(groups_url, nil)
encodedRequest, err := json.Marshal(group)
if err != nil {
return nil, err
}
var result *Group
contents, err := g.buildAndExecRequest("POST", url, encodedRequest)
if err == nil {
err = json.Unmarshal(contents, &result)
}
return result, err
}
/*
Updates the project group. Only available to group owners and administrators.
*/
func (g *Gitlab) UpdateGroup(id string, group *Group) (*Group, error) {
url := g.ResourceUrl(group_url, map[string]string{":id": id})
encodedRequest, err := json.Marshal(group)
if err != nil {
return nil, err
}
var result *Group
contents, err := g.buildAndExecRequest("PUT", url, encodedRequest)
if err == nil {
err = json.Unmarshal(contents, &result)
}
return result, err
}
/*
Remove a group.
*/
func (g *Gitlab) RemoveGroup(id string) (bool, error) {
url, opaque := g.ResourceUrlRaw(group_url, map[string]string{":id": id})
result := false
contents, err := g.buildAndExecRequestRaw("DELETE", url, opaque, nil)
if err == nil {
result, err = strconv.ParseBool(string(contents[:]))
}
return result, err
}
/*
Get a list of projects in this group.
*/
func (g *Gitlab) GroupProjects(id string) ([]*Project, error) {
url, opaque := g.ResourceUrlRaw(group_projects_url, map[string]string{":id": id})
var projects []*Project
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &projects)
}
return projects, err
}
/*
Gets a list of group or project members viewable by the authenticated user
*/
func (g *Gitlab) GroupMembers(id string) ([]*Member, error) {
url, opaque := g.ResourceUrlRaw(group_url_members, map[string]string{":id": id})
var members []*Member
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &members)
}
return members, err
}