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