1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type RunnerGroup struct {
15 ID *int64 `json:"id,omitempty"`
16 Name *string `json:"name,omitempty"`
17 Visibility *string `json:"visibility,omitempty"`
18 Default *bool `json:"default,omitempty"`
19 SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"`
20 RunnersURL *string `json:"runners_url,omitempty"`
21 Inherited *bool `json:"inherited,omitempty"`
22 AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
23 }
24
25
26 type RunnerGroups struct {
27 TotalCount int `json:"total_count"`
28 RunnerGroups []*RunnerGroup `json:"runner_groups"`
29 }
30
31
32 type CreateRunnerGroupRequest struct {
33 Name *string `json:"name,omitempty"`
34 Visibility *string `json:"visibility,omitempty"`
35
36 SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
37
38 Runners []int64 `json:"runners,omitempty"`
39
40 AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
41 }
42
43
44 type UpdateRunnerGroupRequest struct {
45 Name *string `json:"name,omitempty"`
46 Visibility *string `json:"visibility,omitempty"`
47 AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
48 }
49
50
51
52 type SetRepoAccessRunnerGroupRequest struct {
53
54 SelectedRepositoryIDs []int64 `json:"selected_repository_ids"`
55 }
56
57
58
59 type SetRunnerGroupRunnersRequest struct {
60
61 Runners []int64 `json:"runners"`
62 }
63
64
65 type ListOrgRunnerGroupOptions struct {
66 ListOptions
67
68
69 VisibleToRepository string `url:"visible_to_repository,omitempty"`
70 }
71
72
73
74
75 func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOrgRunnerGroupOptions) (*RunnerGroups, *Response, error) {
76 u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
77 u, err := addOptions(u, opts)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 req, err := s.client.NewRequest("GET", u, nil)
83 if err != nil {
84 return nil, nil, err
85 }
86
87 groups := &RunnerGroups{}
88 resp, err := s.client.Do(ctx, req, &groups)
89 if err != nil {
90 return nil, resp, err
91 }
92
93 return groups, resp, nil
94 }
95
96
97
98
99 func (s *ActionsService) GetOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*RunnerGroup, *Response, error) {
100 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
101 req, err := s.client.NewRequest("GET", u, nil)
102 if err != nil {
103 return nil, nil, err
104 }
105
106 runnerGroup := new(RunnerGroup)
107 resp, err := s.client.Do(ctx, req, runnerGroup)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return runnerGroup, resp, nil
113 }
114
115
116
117
118 func (s *ActionsService) DeleteOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*Response, error) {
119 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
120
121 req, err := s.client.NewRequest("DELETE", u, nil)
122 if err != nil {
123 return nil, err
124 }
125
126 return s.client.Do(ctx, req, nil)
127 }
128
129
130
131
132 func (s *ActionsService) CreateOrganizationRunnerGroup(ctx context.Context, org string, createReq CreateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
133 u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
134 req, err := s.client.NewRequest("POST", u, createReq)
135 if err != nil {
136 return nil, nil, err
137 }
138
139 runnerGroup := new(RunnerGroup)
140 resp, err := s.client.Do(ctx, req, runnerGroup)
141 if err != nil {
142 return nil, resp, err
143 }
144
145 return runnerGroup, resp, nil
146 }
147
148
149
150
151 func (s *ActionsService) UpdateOrganizationRunnerGroup(ctx context.Context, org string, groupID int64, updateReq UpdateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
152 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
153 req, err := s.client.NewRequest("PATCH", u, updateReq)
154 if err != nil {
155 return nil, nil, err
156 }
157
158 runnerGroup := new(RunnerGroup)
159 resp, err := s.client.Do(ctx, req, runnerGroup)
160 if err != nil {
161 return nil, resp, err
162 }
163
164 return runnerGroup, resp, nil
165 }
166
167
168
169
170 func (s *ActionsService) ListRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, opts *ListOptions) (*ListRepositories, *Response, error) {
171 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
172 u, err := addOptions(u, opts)
173 if err != nil {
174 return nil, nil, err
175 }
176
177 req, err := s.client.NewRequest("GET", u, nil)
178 if err != nil {
179 return nil, nil, err
180 }
181
182 repos := &ListRepositories{}
183 resp, err := s.client.Do(ctx, req, &repos)
184 if err != nil {
185 return nil, resp, err
186 }
187
188 return repos, resp, nil
189 }
190
191
192
193
194
195 func (s *ActionsService) SetRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, ids SetRepoAccessRunnerGroupRequest) (*Response, error) {
196 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
197
198 req, err := s.client.NewRequest("PUT", u, ids)
199 if err != nil {
200 return nil, err
201 }
202
203 return s.client.Do(ctx, req, nil)
204 }
205
206
207
208
209
210 func (s *ActionsService) AddRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
211 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
212
213 req, err := s.client.NewRequest("PUT", u, nil)
214 if err != nil {
215 return nil, err
216 }
217
218 return s.client.Do(ctx, req, nil)
219 }
220
221
222
223
224
225 func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
226 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
227
228 req, err := s.client.NewRequest("DELETE", u, nil)
229 if err != nil {
230 return nil, err
231 }
232
233 return s.client.Do(ctx, req, nil)
234 }
235
236
237
238
239 func (s *ActionsService) ListRunnerGroupRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*Runners, *Response, error) {
240 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID)
241 u, err := addOptions(u, opts)
242 if err != nil {
243 return nil, nil, err
244 }
245
246 req, err := s.client.NewRequest("GET", u, nil)
247 if err != nil {
248 return nil, nil, err
249 }
250
251 runners := &Runners{}
252 resp, err := s.client.Do(ctx, req, &runners)
253 if err != nil {
254 return nil, resp, err
255 }
256
257 return runners, resp, nil
258 }
259
260
261
262
263
264 func (s *ActionsService) SetRunnerGroupRunners(ctx context.Context, org string, groupID int64, ids SetRunnerGroupRunnersRequest) (*Response, error) {
265 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID)
266
267 req, err := s.client.NewRequest("PUT", u, ids)
268 if err != nil {
269 return nil, err
270 }
271
272 return s.client.Do(ctx, req, nil)
273 }
274
275
276
277
278 func (s *ActionsService) AddRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
279 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
280
281 req, err := s.client.NewRequest("PUT", u, nil)
282 if err != nil {
283 return nil, err
284 }
285
286 return s.client.Do(ctx, req, nil)
287 }
288
289
290
291
292
293 func (s *ActionsService) RemoveRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
294 u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
295
296 req, err := s.client.NewRequest("DELETE", u, nil)
297 if err != nil {
298 return nil, err
299 }
300
301 return s.client.Do(ctx, req, nil)
302 }
303
View as plain text