Skip to content

Commit a12b8d7

Browse files
authored
feat: Add custom image endpoints for GitHub-hosted runners (google#4101)
1 parent acab708 commit a12b8d7

File tree

6 files changed

+1155
-0
lines changed

6 files changed

+1155
-0
lines changed

github/actions_hosted_runners.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,39 @@ func (s *ActionsService) CreateHostedRunner(ctx context.Context, org string, req
160160
return hostedRunner, resp, nil
161161
}
162162

163+
// HostedRunnerCustomImage represents a custom image definition for GitHub-hosted runners.
164+
type HostedRunnerCustomImage struct {
165+
ID int64 `json:"id"`
166+
Platform string `json:"platform"`
167+
Name string `json:"name"`
168+
Source string `json:"source"`
169+
VersionsCount int `json:"versions_count"`
170+
TotalVersionsSize int `json:"total_versions_size"`
171+
LatestVersion string `json:"latest_version"`
172+
State string `json:"state"`
173+
}
174+
175+
// HostedRunnerCustomImages represents a collection of custom images for GitHub-hosted runners.
176+
type HostedRunnerCustomImages struct {
177+
TotalCount int `json:"total_count"`
178+
Images []*HostedRunnerCustomImage `json:"images"`
179+
}
180+
181+
// HostedRunnerCustomImageVersion represents a version of a custom image for GitHub-hosted runners.
182+
type HostedRunnerCustomImageVersion struct {
183+
Version string `json:"version"`
184+
SizeGB int `json:"size_gb"`
185+
State string `json:"state"`
186+
StateDetails string `json:"state_details"`
187+
CreatedOn Timestamp `json:"created_on"`
188+
}
189+
190+
// HostedRunnerCustomImageVersions represents a collection of versions of a custom image.
191+
type HostedRunnerCustomImageVersions struct {
192+
TotalCount int `json:"total_count"`
193+
ImageVersions []*HostedRunnerCustomImageVersion `json:"image_versions"`
194+
}
195+
163196
// HostedRunnerImageSpecs represents the details of a GitHub-hosted runner image.
164197
type HostedRunnerImageSpecs struct {
165198
ID string `json:"id"`
@@ -365,3 +398,117 @@ func (s *ActionsService) DeleteHostedRunner(ctx context.Context, org string, run
365398

366399
return hostedRunner, resp, nil
367400
}
401+
402+
// ListHostedRunnerCustomImages lists custom images for GitHub-hosted runners in an organization.
403+
//
404+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#list-custom-images-for-an-organization
405+
//
406+
//meta:operation GET /orgs/{org}/actions/hosted-runners/images/custom
407+
func (s *ActionsService) ListHostedRunnerCustomImages(ctx context.Context, org string) (*HostedRunnerCustomImages, *Response, error) {
408+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom", org)
409+
req, err := s.client.NewRequest("GET", u, nil)
410+
if err != nil {
411+
return nil, nil, err
412+
}
413+
414+
var images *HostedRunnerCustomImages
415+
resp, err := s.client.Do(ctx, req, &images)
416+
if err != nil {
417+
return nil, resp, err
418+
}
419+
420+
return images, resp, nil
421+
}
422+
423+
// GetHostedRunnerCustomImage gets a custom image definition for GitHub-hosted runners in an organization.
424+
//
425+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#get-a-custom-image-definition-for-github-actions-hosted-runners
426+
//
427+
//meta:operation GET /orgs/{org}/actions/hosted-runners/images/custom/{image_definition_id}
428+
func (s *ActionsService) GetHostedRunnerCustomImage(ctx context.Context, org string, imageDefinitionID int64) (*HostedRunnerCustomImage, *Response, error) {
429+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom/%v", org, imageDefinitionID)
430+
req, err := s.client.NewRequest("GET", u, nil)
431+
if err != nil {
432+
return nil, nil, err
433+
}
434+
435+
var image *HostedRunnerCustomImage
436+
resp, err := s.client.Do(ctx, req, &image)
437+
if err != nil {
438+
return nil, resp, err
439+
}
440+
441+
return image, resp, nil
442+
}
443+
444+
// DeleteHostedRunnerCustomImage deletes a custom image from the organization.
445+
//
446+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#delete-a-custom-image-from-the-organization
447+
//
448+
//meta:operation DELETE /orgs/{org}/actions/hosted-runners/images/custom/{image_definition_id}
449+
func (s *ActionsService) DeleteHostedRunnerCustomImage(ctx context.Context, org string, imageDefinitionID int64) (*Response, error) {
450+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom/%v", org, imageDefinitionID)
451+
req, err := s.client.NewRequest("DELETE", u, nil)
452+
if err != nil {
453+
return nil, err
454+
}
455+
456+
return s.client.Do(ctx, req, nil)
457+
}
458+
459+
// ListHostedRunnerCustomImageVersions lists image versions of a custom image for an organization.
460+
//
461+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#list-image-versions-of-a-custom-image-for-an-organization
462+
//
463+
//meta:operation GET /orgs/{org}/actions/hosted-runners/images/custom/{image_definition_id}/versions
464+
func (s *ActionsService) ListHostedRunnerCustomImageVersions(ctx context.Context, org string, imageDefinitionID int64) (*HostedRunnerCustomImageVersions, *Response, error) {
465+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom/%v/versions", org, imageDefinitionID)
466+
req, err := s.client.NewRequest("GET", u, nil)
467+
if err != nil {
468+
return nil, nil, err
469+
}
470+
471+
var versions *HostedRunnerCustomImageVersions
472+
resp, err := s.client.Do(ctx, req, &versions)
473+
if err != nil {
474+
return nil, resp, err
475+
}
476+
477+
return versions, resp, nil
478+
}
479+
480+
// GetHostedRunnerCustomImageVersion gets an image version of a custom image for GitHub-hosted runners in an organization.
481+
//
482+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#get-an-image-version-of-a-custom-image-for-github-actions-hosted-runners
483+
//
484+
//meta:operation GET /orgs/{org}/actions/hosted-runners/images/custom/{image_definition_id}/versions/{version}
485+
func (s *ActionsService) GetHostedRunnerCustomImageVersion(ctx context.Context, org string, imageDefinitionID int64, version string) (*HostedRunnerCustomImageVersion, *Response, error) {
486+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom/%v/versions/%v", org, imageDefinitionID, version)
487+
req, err := s.client.NewRequest("GET", u, nil)
488+
if err != nil {
489+
return nil, nil, err
490+
}
491+
492+
var imageVersion *HostedRunnerCustomImageVersion
493+
resp, err := s.client.Do(ctx, req, &imageVersion)
494+
if err != nil {
495+
return nil, resp, err
496+
}
497+
498+
return imageVersion, resp, nil
499+
}
500+
501+
// DeleteHostedRunnerCustomImageVersion deletes an image version of a custom image from the organization.
502+
//
503+
// GitHub API docs: https://docs.github.com/rest/actions/hosted-runners#delete-an-image-version-of-custom-image-from-the-organization
504+
//
505+
//meta:operation DELETE /orgs/{org}/actions/hosted-runners/images/custom/{image_definition_id}/versions/{version}
506+
func (s *ActionsService) DeleteHostedRunnerCustomImageVersion(ctx context.Context, org string, imageDefinitionID int64, version string) (*Response, error) {
507+
u := fmt.Sprintf("orgs/%v/actions/hosted-runners/images/custom/%v/versions/%v", org, imageDefinitionID, version)
508+
req, err := s.client.NewRequest("DELETE", u, nil)
509+
if err != nil {
510+
return nil, err
511+
}
512+
513+
return s.client.Do(ctx, req, nil)
514+
}

0 commit comments

Comments
 (0)