github.com/google/go-github/v71@v71.0.0/github/enterprise_actions_runners.go (about) 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 // ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run. 14 // 15 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#list-runner-applications-for-an-enterprise 16 // 17 //meta:operation GET /enterprises/{enterprise}/actions/runners/downloads 18 func (s *EnterpriseService) ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*RunnerApplicationDownload, *Response, error) { 19 u := fmt.Sprintf("enterprises/%v/actions/runners/downloads", enterprise) 20 req, err := s.client.NewRequest("GET", u, nil) 21 if err != nil { 22 return nil, nil, err 23 } 24 25 var rads []*RunnerApplicationDownload 26 resp, err := s.client.Do(ctx, req, &rads) 27 if err != nil { 28 return nil, resp, err 29 } 30 31 return rads, resp, nil 32 } 33 34 // GenerateEnterpriseJITConfig generates a just-in-time configuration for an enterprise. 35 // 36 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#create-configuration-for-a-just-in-time-runner-for-an-enterprise 37 // 38 //meta:operation POST /enterprises/{enterprise}/actions/runners/generate-jitconfig 39 func (s *EnterpriseService) GenerateEnterpriseJITConfig(ctx context.Context, enterprise string, request *GenerateJITConfigRequest) (*JITRunnerConfig, *Response, error) { 40 u := fmt.Sprintf("enterprises/%v/actions/runners/generate-jitconfig", enterprise) 41 42 req, err := s.client.NewRequest("POST", u, request) 43 if err != nil { 44 return nil, nil, err 45 } 46 47 jitConfig := new(JITRunnerConfig) 48 resp, err := s.client.Do(ctx, req, jitConfig) 49 if err != nil { 50 return nil, resp, err 51 } 52 53 return jitConfig, resp, nil 54 } 55 56 // CreateRegistrationToken creates a token that can be used to add a self-hosted runner. 57 // 58 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#create-a-registration-token-for-an-enterprise 59 // 60 //meta:operation POST /enterprises/{enterprise}/actions/runners/registration-token 61 func (s *EnterpriseService) CreateRegistrationToken(ctx context.Context, enterprise string) (*RegistrationToken, *Response, error) { 62 u := fmt.Sprintf("enterprises/%v/actions/runners/registration-token", enterprise) 63 64 req, err := s.client.NewRequest("POST", u, nil) 65 if err != nil { 66 return nil, nil, err 67 } 68 69 registrationToken := new(RegistrationToken) 70 resp, err := s.client.Do(ctx, req, registrationToken) 71 if err != nil { 72 return nil, resp, err 73 } 74 75 return registrationToken, resp, nil 76 } 77 78 // ListRunners lists all the self-hosted runners for a enterprise. 79 // 80 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#list-self-hosted-runners-for-an-enterprise 81 // 82 //meta:operation GET /enterprises/{enterprise}/actions/runners 83 func (s *EnterpriseService) ListRunners(ctx context.Context, enterprise string, opts *ListRunnersOptions) (*Runners, *Response, error) { 84 u := fmt.Sprintf("enterprises/%v/actions/runners", enterprise) 85 u, err := addOptions(u, opts) 86 if err != nil { 87 return nil, nil, err 88 } 89 90 req, err := s.client.NewRequest("GET", u, nil) 91 if err != nil { 92 return nil, nil, err 93 } 94 95 runners := &Runners{} 96 resp, err := s.client.Do(ctx, req, &runners) 97 if err != nil { 98 return nil, resp, err 99 } 100 101 return runners, resp, nil 102 } 103 104 // GetRunner gets a specific self-hosted runner configured in an enterprise. 105 // 106 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-an-enterprise 107 // 108 //meta:operation GET /enterprises/{enterprise}/actions/runners/{runner_id} 109 func (s *EnterpriseService) GetRunner(ctx context.Context, enterprise string, runnerID int64) (*Runner, *Response, error) { 110 u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID) 111 req, err := s.client.NewRequest("GET", u, nil) 112 if err != nil { 113 return nil, nil, err 114 } 115 116 runner := new(Runner) 117 resp, err := s.client.Do(ctx, req, runner) 118 if err != nil { 119 return nil, resp, err 120 } 121 122 return runner, resp, nil 123 } 124 125 // RemoveRunner forces the removal of a self-hosted runner from an enterprise using the runner id. 126 // 127 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-an-enterprise 128 // 129 //meta:operation DELETE /enterprises/{enterprise}/actions/runners/{runner_id} 130 func (s *EnterpriseService) RemoveRunner(ctx context.Context, enterprise string, runnerID int64) (*Response, error) { 131 u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID) 132 133 req, err := s.client.NewRequest("DELETE", u, nil) 134 if err != nil { 135 return nil, err 136 } 137 138 return s.client.Do(ctx, req, nil) 139 }