github.com/google/go-github/v49@v49.1.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/en/rest/actions/self-hosted-runners#list-runner-applications-for-an-enterprise 16 func (s *EnterpriseService) ListRunnerApplicationDownloads(ctx context.Context, enterprise string) ([]*RunnerApplicationDownload, *Response, error) { 17 u := fmt.Sprintf("enterprises/%v/actions/runners/downloads", enterprise) 18 req, err := s.client.NewRequest("GET", u, nil) 19 if err != nil { 20 return nil, nil, err 21 } 22 23 var rads []*RunnerApplicationDownload 24 resp, err := s.client.Do(ctx, req, &rads) 25 if err != nil { 26 return nil, resp, err 27 } 28 29 return rads, resp, nil 30 } 31 32 // CreateRegistrationToken creates a token that can be used to add a self-hosted runner. 33 // 34 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-enterprise 35 func (s *EnterpriseService) CreateRegistrationToken(ctx context.Context, enterprise string) (*RegistrationToken, *Response, error) { 36 u := fmt.Sprintf("enterprises/%v/actions/runners/registration-token", enterprise) 37 38 req, err := s.client.NewRequest("POST", u, nil) 39 if err != nil { 40 return nil, nil, err 41 } 42 43 registrationToken := new(RegistrationToken) 44 resp, err := s.client.Do(ctx, req, registrationToken) 45 if err != nil { 46 return nil, resp, err 47 } 48 49 return registrationToken, resp, nil 50 } 51 52 // ListRunners lists all the self-hosted runners for a enterprise. 53 // 54 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#list-self-hosted-runners-for-an-enterprise 55 func (s *EnterpriseService) ListRunners(ctx context.Context, enterprise string, opts *ListOptions) (*Runners, *Response, error) { 56 u := fmt.Sprintf("enterprises/%v/actions/runners", enterprise) 57 u, err := addOptions(u, opts) 58 if err != nil { 59 return nil, nil, err 60 } 61 62 req, err := s.client.NewRequest("GET", u, nil) 63 if err != nil { 64 return nil, nil, err 65 } 66 67 runners := &Runners{} 68 resp, err := s.client.Do(ctx, req, &runners) 69 if err != nil { 70 return nil, resp, err 71 } 72 73 return runners, resp, nil 74 } 75 76 // RemoveRunner forces the removal of a self-hosted runner from an enterprise using the runner id. 77 // 78 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-an-enterprise 79 func (s *EnterpriseService) RemoveRunner(ctx context.Context, enterprise string, runnerID int64) (*Response, error) { 80 u := fmt.Sprintf("enterprises/%v/actions/runners/%v", enterprise, runnerID) 81 82 req, err := s.client.NewRequest("DELETE", u, nil) 83 if err != nil { 84 return nil, err 85 } 86 87 return s.client.Do(ctx, req, nil) 88 }