1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 )
23
24
25
26
27
28 type NamespacesService struct {
29 client *Client
30 }
31
32
33
34
35 type Namespace struct {
36 ID int `json:"id"`
37 Name string `json:"name"`
38 Path string `json:"path"`
39 Kind string `json:"kind"`
40 FullPath string `json:"full_path"`
41 ParentID int `json:"parent_id"`
42 AvatarURL *string `json:"avatar_url"`
43 WebURL string `json:"web_url"`
44 MembersCountWithDescendants int `json:"members_count_with_descendants"`
45 BillableMembersCount int `json:"billable_members_count"`
46 Plan string `json:"plan"`
47 TrialEndsOn *ISOTime `json:"trial_ends_on"`
48 Trial bool `json:"trial"`
49 MaxSeatsUsed *int `json:"max_seats_used"`
50 SeatsInUse *int `json:"seats_in_use"`
51 }
52
53 func (n Namespace) String() string {
54 return Stringify(n)
55 }
56
57
58
59
60 type ListNamespacesOptions struct {
61 ListOptions
62 Search *string `url:"search,omitempty" json:"search,omitempty"`
63 OwnedOnly *bool `url:"owned_only,omitempty" json:"owned_only,omitempty"`
64 }
65
66
67
68
69 func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions, options ...RequestOptionFunc) ([]*Namespace, *Response, error) {
70 req, err := s.client.NewRequest(http.MethodGet, "namespaces", opt, options)
71 if err != nil {
72 return nil, nil, err
73 }
74
75 var n []*Namespace
76 resp, err := s.client.Do(req, &n)
77 if err != nil {
78 return nil, resp, err
79 }
80
81 return n, resp, nil
82 }
83
84
85
86
87
88
89 func (s *NamespacesService) SearchNamespace(query string, options ...RequestOptionFunc) ([]*Namespace, *Response, error) {
90 var q struct {
91 Search string `url:"search,omitempty" json:"search,omitempty"`
92 }
93 q.Search = query
94
95 req, err := s.client.NewRequest(http.MethodGet, "namespaces", &q, options)
96 if err != nil {
97 return nil, nil, err
98 }
99
100 var n []*Namespace
101 resp, err := s.client.Do(req, &n)
102 if err != nil {
103 return nil, resp, err
104 }
105
106 return n, resp, nil
107 }
108
109
110
111
112
113 func (s *NamespacesService) GetNamespace(id interface{}, options ...RequestOptionFunc) (*Namespace, *Response, error) {
114 namespace, err := parseID(id)
115 if err != nil {
116 return nil, nil, err
117 }
118 u := fmt.Sprintf("namespaces/%s", PathEscape(namespace))
119
120 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
121 if err != nil {
122 return nil, nil, err
123 }
124
125 n := new(Namespace)
126 resp, err := s.client.Do(req, n)
127 if err != nil {
128 return nil, resp, err
129 }
130
131 return n, resp, nil
132 }
133
134
135
136
137
138 type NamespaceExistance struct {
139 Exists bool `json:"exists"`
140 Suggests []string `json:"suggests"`
141 }
142
143
144
145
146
147 type NamespaceExistsOptions struct {
148 ParentID *int `url:"parent_id,omitempty" json:"parent_id,omitempty"`
149 }
150
151
152
153
154
155 func (s *NamespacesService) NamespaceExists(id interface{}, opt *NamespaceExistsOptions, options ...RequestOptionFunc) (*NamespaceExistance, *Response, error) {
156 namespace, err := parseID(id)
157 if err != nil {
158 return nil, nil, err
159 }
160 u := fmt.Sprintf("namespaces/%s/exists", namespace)
161
162 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
163 if err != nil {
164 return nil, nil, err
165 }
166
167 n := new(NamespaceExistance)
168 resp, err := s.client.Do(req, n)
169 if err != nil {
170 return nil, resp, err
171 }
172
173 return n, resp, nil
174 }
175
View as plain text