...

Source file src/github.com/google/go-github/v45/github/enterprise_actions_runners.go

Documentation: github.com/google/go-github/v45/github

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

View as plain text