1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type RunnerApplicationDownload struct {
15 OS *string `json:"os,omitempty"`
16 Architecture *string `json:"architecture,omitempty"`
17 DownloadURL *string `json:"download_url,omitempty"`
18 Filename *string `json:"filename,omitempty"`
19 TempDownloadToken *string `json:"temp_download_token,omitempty"`
20 SHA256Checksum *string `json:"sha256_checksum,omitempty"`
21 }
22
23
24 type ActionsEnabledOnOrgRepos struct {
25 TotalCount int `json:"total_count"`
26 Repositories []*Repository `json:"repositories"`
27 }
28
29
30
31
32 func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) {
33 u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo)
34 req, err := s.client.NewRequest("GET", u, nil)
35 if err != nil {
36 return nil, nil, err
37 }
38
39 var rads []*RunnerApplicationDownload
40 resp, err := s.client.Do(ctx, req, &rads)
41 if err != nil {
42 return nil, resp, err
43 }
44
45 return rads, resp, nil
46 }
47
48
49 type GenerateJITConfigRequest struct {
50 Name string `json:"name"`
51 RunnerGroupID int64 `json:"runner_group_id"`
52 WorkFolder *string `json:"work_folder,omitempty"`
53
54
55
56 Labels []string `json:"labels"`
57 }
58
59
60 type JITRunnerConfig struct {
61 Runner *Runner `json:"runner,omitempty"`
62 EncodedJITConfig *string `json:"encoded_jit_config,omitempty"`
63 }
64
65
66
67
68 func (s *ActionsService) GenerateOrgJITConfig(ctx context.Context, owner string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) {
69 u := fmt.Sprintf("orgs/%v/actions/runners/generate-jitconfig", owner)
70 req, err := s.client.NewRequest("POST", u, request)
71 if err != nil {
72 return nil, nil, err
73 }
74
75 jitConfig := new(JITRunnerConfig)
76 resp, err := s.client.Do(ctx, req, jitConfig)
77 if err != nil {
78 return nil, resp, err
79 }
80
81 return jitConfig, resp, nil
82 }
83
84
85
86
87 func (s *ActionsService) GenerateRepoJITConfig(ctx context.Context, owner, repo string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) {
88 u := fmt.Sprintf("repos/%v/%v/actions/runners/generate-jitconfig", owner, repo)
89 req, err := s.client.NewRequest("POST", u, request)
90 if err != nil {
91 return nil, nil, err
92 }
93
94 jitConfig := new(JITRunnerConfig)
95 resp, err := s.client.Do(ctx, req, jitConfig)
96 if err != nil {
97 return nil, resp, err
98 }
99
100 return jitConfig, resp, nil
101 }
102
103
104 type RegistrationToken struct {
105 Token *string `json:"token,omitempty"`
106 ExpiresAt *Timestamp `json:"expires_at,omitempty"`
107 }
108
109
110
111
112 func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) {
113 u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo)
114
115 req, err := s.client.NewRequest("POST", u, nil)
116 if err != nil {
117 return nil, nil, err
118 }
119
120 registrationToken := new(RegistrationToken)
121 resp, err := s.client.Do(ctx, req, registrationToken)
122 if err != nil {
123 return nil, resp, err
124 }
125
126 return registrationToken, resp, nil
127 }
128
129
130 type Runner struct {
131 ID *int64 `json:"id,omitempty"`
132 Name *string `json:"name,omitempty"`
133 OS *string `json:"os,omitempty"`
134 Status *string `json:"status,omitempty"`
135 Busy *bool `json:"busy,omitempty"`
136 Labels []*RunnerLabels `json:"labels,omitempty"`
137 }
138
139
140 type RunnerLabels struct {
141 ID *int64 `json:"id,omitempty"`
142 Name *string `json:"name,omitempty"`
143 Type *string `json:"type,omitempty"`
144 }
145
146
147 type Runners struct {
148 TotalCount int `json:"total_count"`
149 Runners []*Runner `json:"runners"`
150 }
151
152
153
154
155 func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) {
156 u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo)
157 u, err := addOptions(u, opts)
158 if err != nil {
159 return nil, nil, err
160 }
161
162 req, err := s.client.NewRequest("GET", u, nil)
163 if err != nil {
164 return nil, nil, err
165 }
166
167 runners := &Runners{}
168 resp, err := s.client.Do(ctx, req, &runners)
169 if err != nil {
170 return nil, resp, err
171 }
172
173 return runners, resp, nil
174 }
175
176
177
178
179 func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) {
180 u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
181 req, err := s.client.NewRequest("GET", u, nil)
182 if err != nil {
183 return nil, nil, err
184 }
185
186 runner := new(Runner)
187 resp, err := s.client.Do(ctx, req, runner)
188 if err != nil {
189 return nil, resp, err
190 }
191
192 return runner, resp, nil
193 }
194
195
196 type RemoveToken struct {
197 Token *string `json:"token,omitempty"`
198 ExpiresAt *Timestamp `json:"expires_at,omitempty"`
199 }
200
201
202
203
204 func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) {
205 u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo)
206
207 req, err := s.client.NewRequest("POST", u, nil)
208 if err != nil {
209 return nil, nil, err
210 }
211
212 removeToken := new(RemoveToken)
213 resp, err := s.client.Do(ctx, req, removeToken)
214 if err != nil {
215 return nil, resp, err
216 }
217
218 return removeToken, resp, nil
219 }
220
221
222
223
224 func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) {
225 u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
226
227 req, err := s.client.NewRequest("DELETE", u, nil)
228 if err != nil {
229 return nil, err
230 }
231
232 return s.client.Do(ctx, req, nil)
233 }
234
235
236
237
238 func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, owner string) ([]*RunnerApplicationDownload, *Response, error) {
239 u := fmt.Sprintf("orgs/%v/actions/runners/downloads", owner)
240 req, err := s.client.NewRequest("GET", u, nil)
241 if err != nil {
242 return nil, nil, err
243 }
244
245 var rads []*RunnerApplicationDownload
246 resp, err := s.client.Do(ctx, req, &rads)
247 if err != nil {
248 return nil, resp, err
249 }
250
251 return rads, resp, nil
252 }
253
254
255
256
257 func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*RegistrationToken, *Response, error) {
258 u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", owner)
259
260 req, err := s.client.NewRequest("POST", u, nil)
261 if err != nil {
262 return nil, nil, err
263 }
264
265 registrationToken := new(RegistrationToken)
266 resp, err := s.client.Do(ctx, req, registrationToken)
267 if err != nil {
268 return nil, resp, err
269 }
270
271 return registrationToken, resp, nil
272 }
273
274
275
276
277 func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner string, opts *ListOptions) (*Runners, *Response, error) {
278 u := fmt.Sprintf("orgs/%v/actions/runners", owner)
279 u, err := addOptions(u, opts)
280 if err != nil {
281 return nil, nil, err
282 }
283
284 req, err := s.client.NewRequest("GET", u, nil)
285 if err != nil {
286 return nil, nil, err
287 }
288
289 runners := &Runners{}
290 resp, err := s.client.Do(ctx, req, &runners)
291 if err != nil {
292 return nil, resp, err
293 }
294
295 return runners, resp, nil
296 }
297
298
299
300
301 func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) {
302 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
303 u, err := addOptions(u, opts)
304 if err != nil {
305 return nil, nil, err
306 }
307
308 req, err := s.client.NewRequest("GET", u, nil)
309 if err != nil {
310 return nil, nil, err
311 }
312
313 repos := &ActionsEnabledOnOrgRepos{}
314 resp, err := s.client.Do(ctx, req, repos)
315 if err != nil {
316 return nil, resp, err
317 }
318
319 return repos, resp, nil
320 }
321
322
323
324
325 func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) {
326 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
327
328 req, err := s.client.NewRequest("PUT", u, struct {
329 IDs []int64 `json:"selected_repository_ids"`
330 }{IDs: repositoryIDs})
331 if err != nil {
332 return nil, err
333 }
334
335 resp, err := s.client.Do(ctx, req, nil)
336 if err != nil {
337 return resp, err
338 }
339
340 return resp, nil
341 }
342
343
344
345
346 func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
347 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
348
349 req, err := s.client.NewRequest("PUT", u, nil)
350 if err != nil {
351 return nil, err
352 }
353
354 resp, err := s.client.Do(ctx, req, nil)
355 if err != nil {
356 return resp, err
357 }
358
359 return resp, nil
360 }
361
362
363
364
365 func (s *ActionsService) RemoveEnabledRepoInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
366 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
367
368 req, err := s.client.NewRequest("DELETE", u, nil)
369 if err != nil {
370 return nil, err
371 }
372
373 resp, err := s.client.Do(ctx, req, nil)
374 if err != nil {
375 return resp, err
376 }
377
378 return resp, nil
379 }
380
381
382
383
384 func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Runner, *Response, error) {
385 u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)
386 req, err := s.client.NewRequest("GET", u, nil)
387 if err != nil {
388 return nil, nil, err
389 }
390
391 runner := new(Runner)
392 resp, err := s.client.Do(ctx, req, runner)
393 if err != nil {
394 return nil, resp, err
395 }
396
397 return runner, resp, nil
398 }
399
400
401
402
403 func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owner string) (*RemoveToken, *Response, error) {
404 u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", owner)
405
406 req, err := s.client.NewRequest("POST", u, nil)
407 if err != nil {
408 return nil, nil, err
409 }
410
411 removeToken := new(RemoveToken)
412 resp, err := s.client.Do(ctx, req, removeToken)
413 if err != nil {
414 return nil, resp, err
415 }
416
417 return removeToken, resp, nil
418 }
419
420
421
422
423 func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Response, error) {
424 u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)
425
426 req, err := s.client.NewRequest("DELETE", u, nil)
427 if err != nil {
428 return nil, err
429 }
430
431 return s.client.Do(ctx, req, nil)
432 }
433
View as plain text