Debian Codegraph @

github/actions_runners.go

raw
1 // Copyright 2020 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13 // RunnerApplicationDownload represents a binary for the self-hosted runner application that can be downloaded.
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 // ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
24 //
25 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-runner-applications-for-a-repository
26 //
27 //meta:operation GET /repos/{owner}/{repo}/actions/runners/downloads
28 func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) {
29 u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo)
30 req, err := s.client.NewRequest("GET", u, nil)
31 if err != nil {
32 return nil, nil, err
33 }
34
35 var rads []*RunnerApplicationDownload
36 resp, err := s.client.Do(ctx, req, &rads)
37 if err != nil {
38 return nil, resp, err
39 }
40
41 return rads, resp, nil
42 }
43
44 // GenerateJITConfigRequest specifies body parameters to GenerateRepoJITConfig.
45 type GenerateJITConfigRequest struct {
46 Name string `json:"name"`
47 RunnerGroupID int64 `json:"runner_group_id"`
48 WorkFolder *string `json:"work_folder,omitempty"`
49
50 // Labels represents the names of the custom labels to add to the runner.
51 // Minimum items: 1. Maximum items: 100.
52 Labels []string `json:"labels"`
53 }
54
55 // JITRunnerConfig represents encoded JIT configuration that can be used to bootstrap a self-hosted runner.
56 type JITRunnerConfig struct {
57 Runner *Runner `json:"runner,omitempty"`
58 EncodedJITConfig *string `json:"encoded_jit_config,omitempty"`
59 }
60
61 // GenerateOrgJITConfig generate a just-in-time configuration for an organization.
62 //
63 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-configuration-for-a-just-in-time-runner-for-an-organization
64 //
65 //meta:operation POST /orgs/{org}/actions/runners/generate-jitconfig
66 func (s *ActionsService) GenerateOrgJITConfig(ctx context.Context, org string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) {
67 u := fmt.Sprintf("orgs/%v/actions/runners/generate-jitconfig", org)
68 req, err := s.client.NewRequest("POST", u, request)
69 if err != nil {
70 return nil, nil, err
71 }
72
73 jitConfig := new(JITRunnerConfig)
74 resp, err := s.client.Do(ctx, req, jitConfig)
75 if err != nil {
76 return nil, resp, err
77 }
78
79 return jitConfig, resp, nil
80 }
81
82 // GenerateRepoJITConfig generates a just-in-time configuration for a repository.
83 //
84 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-configuration-for-a-just-in-time-runner-for-a-repository
85 //
86 //meta:operation POST /repos/{owner}/{repo}/actions/runners/generate-jitconfig
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 // RegistrationToken represents a token that can be used to add a self-hosted runner to a repository.
104 type RegistrationToken struct {
105 Token *string `json:"token,omitempty"`
106 ExpiresAt *Timestamp `json:"expires_at,omitempty"`
107 }
108
109 // CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
110 //
111 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
112 //
113 //meta:operation POST /repos/{owner}/{repo}/actions/runners/registration-token
114 func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) {
115 u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo)
116
117 req, err := s.client.NewRequest("POST", u, nil)
118 if err != nil {
119 return nil, nil, err
120 }
121
122 registrationToken := new(RegistrationToken)
123 resp, err := s.client.Do(ctx, req, registrationToken)
124 if err != nil {
125 return nil, resp, err
126 }
127
128 return registrationToken, resp, nil
129 }
130
131 // Runner represents a self-hosted runner registered with a repository.
132 type Runner struct {
133 ID *int64 `json:"id,omitempty"`
134 Name *string `json:"name,omitempty"`
135 OS *string `json:"os,omitempty"`
136 Status *string `json:"status,omitempty"`
137 Busy *bool `json:"busy,omitempty"`
138 Labels []*RunnerLabels `json:"labels,omitempty"`
139 }
140
141 // RunnerLabels represents a collection of labels attached to each runner.
142 type RunnerLabels struct {
143 ID *int64 `json:"id,omitempty"`
144 Name *string `json:"name,omitempty"`
145 Type *string `json:"type,omitempty"`
146 }
147
148 // Runners represents a collection of self-hosted runners for a repository.
149 type Runners struct {
150 TotalCount int `json:"total_count"`
151 Runners []*Runner `json:"runners"`
152 }
153
154 // ListRunners lists all the self-hosted runners for a repository.
155 //
156 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-a-repository
157 //
158 //meta:operation GET /repos/{owner}/{repo}/actions/runners
159 func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) {
160 u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo)
161 u, err := addOptions(u, opts)
162 if err != nil {
163 return nil, nil, err
164 }
165
166 req, err := s.client.NewRequest("GET", u, nil)
167 if err != nil {
168 return nil, nil, err
169 }
170
171 runners := &Runners{}
172 resp, err := s.client.Do(ctx, req, &runners)
173 if err != nil {
174 return nil, resp, err
175 }
176
177 return runners, resp, nil
178 }
179
180 // GetRunner gets a specific self-hosted runner for a repository using its runner ID.
181 //
182 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-a-repository
183 //
184 //meta:operation GET /repos/{owner}/{repo}/actions/runners/{runner_id}
185 func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) {
186 u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
187 req, err := s.client.NewRequest("GET", u, nil)
188 if err != nil {
189 return nil, nil, err
190 }
191
192 runner := new(Runner)
193 resp, err := s.client.Do(ctx, req, runner)
194 if err != nil {
195 return nil, resp, err
196 }
197
198 return runner, resp, nil
199 }
200
201 // RemoveToken represents a token that can be used to remove a self-hosted runner from a repository.
202 type RemoveToken struct {
203 Token *string `json:"token,omitempty"`
204 ExpiresAt *Timestamp `json:"expires_at,omitempty"`
205 }
206
207 // CreateRemoveToken creates a token that can be used to remove a self-hosted runner from a repository.
208 //
209 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-remove-token-for-a-repository
210 //
211 //meta:operation POST /repos/{owner}/{repo}/actions/runners/remove-token
212 func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) {
213 u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo)
214
215 req, err := s.client.NewRequest("POST", u, nil)
216 if err != nil {
217 return nil, nil, err
218 }
219
220 removeToken := new(RemoveToken)
221 resp, err := s.client.Do(ctx, req, removeToken)
222 if err != nil {
223 return nil, resp, err
224 }
225
226 return removeToken, resp, nil
227 }
228
229 // RemoveRunner forces the removal of a self-hosted runner in a repository using the runner id.
230 //
231 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-a-repository
232 //
233 //meta:operation DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}
234 func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) {
235 u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
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 // ListOrganizationRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
246 //
247 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-runner-applications-for-an-organization
248 //
249 //meta:operation GET /orgs/{org}/actions/runners/downloads
250 func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, org string) ([]*RunnerApplicationDownload, *Response, error) {
251 u := fmt.Sprintf("orgs/%v/actions/runners/downloads", org)
252 req, err := s.client.NewRequest("GET", u, nil)
253 if err != nil {
254 return nil, nil, err
255 }
256
257 var rads []*RunnerApplicationDownload
258 resp, err := s.client.Do(ctx, req, &rads)
259 if err != nil {
260 return nil, resp, err
261 }
262
263 return rads, resp, nil
264 }
265
266 // CreateOrganizationRegistrationToken creates a token that can be used to add a self-hosted runner to an organization.
267 //
268 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-registration-token-for-an-organization
269 //
270 //meta:operation POST /orgs/{org}/actions/runners/registration-token
271 func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, org string) (*RegistrationToken, *Response, error) {
272 u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", org)
273
274 req, err := s.client.NewRequest("POST", u, nil)
275 if err != nil {
276 return nil, nil, err
277 }
278
279 registrationToken := new(RegistrationToken)
280 resp, err := s.client.Do(ctx, req, registrationToken)
281 if err != nil {
282 return nil, resp, err
283 }
284
285 return registrationToken, resp, nil
286 }
287
288 // ListOrganizationRunners lists all the self-hosted runners for an organization.
289 //
290 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-an-organization
291 //
292 //meta:operation GET /orgs/{org}/actions/runners
293 func (s *ActionsService) ListOrganizationRunners(ctx context.Context, org string, opts *ListOptions) (*Runners, *Response, error) {
294 u := fmt.Sprintf("orgs/%v/actions/runners", org)
295 u, err := addOptions(u, opts)
296 if err != nil {
297 return nil, nil, err
298 }
299
300 req, err := s.client.NewRequest("GET", u, nil)
301 if err != nil {
302 return nil, nil, err
303 }
304
305 runners := &Runners{}
306 resp, err := s.client.Do(ctx, req, &runners)
307 if err != nil {
308 return nil, resp, err
309 }
310
311 return runners, resp, nil
312 }
313
314 // GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID.
315 //
316 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-an-organization
317 //
318 //meta:operation GET /orgs/{org}/actions/runners/{runner_id}
319 func (s *ActionsService) GetOrganizationRunner(ctx context.Context, org string, runnerID int64) (*Runner, *Response, error) {
320 u := fmt.Sprintf("orgs/%v/actions/runners/%v", org, runnerID)
321 req, err := s.client.NewRequest("GET", u, nil)
322 if err != nil {
323 return nil, nil, err
324 }
325
326 runner := new(Runner)
327 resp, err := s.client.Do(ctx, req, runner)
328 if err != nil {
329 return nil, resp, err
330 }
331
332 return runner, resp, nil
333 }
334
335 // CreateOrganizationRemoveToken creates a token that can be used to remove a self-hosted runner from an organization.
336 //
337 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-remove-token-for-an-organization
338 //
339 //meta:operation POST /orgs/{org}/actions/runners/remove-token
340 func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, org string) (*RemoveToken, *Response, error) {
341 u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", org)
342
343 req, err := s.client.NewRequest("POST", u, nil)
344 if err != nil {
345 return nil, nil, err
346 }
347
348 removeToken := new(RemoveToken)
349 resp, err := s.client.Do(ctx, req, removeToken)
350 if err != nil {
351 return nil, resp, err
352 }
353
354 return removeToken, resp, nil
355 }
356
357 // RemoveOrganizationRunner forces the removal of a self-hosted runner from an organization using the runner id.
358 //
359 // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-an-organization
360 //
361 //meta:operation DELETE /orgs/{org}/actions/runners/{runner_id}
362 func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, org string, runnerID int64) (*Response, error) {
363 u := fmt.Sprintf("orgs/%v/actions/runners/%v", org, runnerID)
364
365 req, err := s.client.NewRequest("DELETE", u, nil)
366 if err != nil {
367 return nil, err
368 }
369
370 return s.client.Do(ctx, req, nil)
371 }