github.com/google/go-github/v74@v74.0.0/github/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  // 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  // ListRunnersOptions specifies the optional parameters to the ListRunners and ListOrganizationRunners methods.
   155  type ListRunnersOptions struct {
   156  	Name *string `url:"name,omitempty"`
   157  	ListOptions
   158  }
   159  
   160  // ListRunners lists all the self-hosted runners for a repository.
   161  //
   162  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-a-repository
   163  //
   164  //meta:operation GET /repos/{owner}/{repo}/actions/runners
   165  func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListRunnersOptions) (*Runners, *Response, error) {
   166  	u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo)
   167  	u, err := addOptions(u, opts)
   168  	if err != nil {
   169  		return nil, nil, err
   170  	}
   171  
   172  	req, err := s.client.NewRequest("GET", u, nil)
   173  	if err != nil {
   174  		return nil, nil, err
   175  	}
   176  
   177  	runners := &Runners{}
   178  	resp, err := s.client.Do(ctx, req, &runners)
   179  	if err != nil {
   180  		return nil, resp, err
   181  	}
   182  
   183  	return runners, resp, nil
   184  }
   185  
   186  // GetRunner gets a specific self-hosted runner for a repository using its runner ID.
   187  //
   188  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-a-repository
   189  //
   190  //meta:operation GET /repos/{owner}/{repo}/actions/runners/{runner_id}
   191  func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) {
   192  	u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
   193  	req, err := s.client.NewRequest("GET", u, nil)
   194  	if err != nil {
   195  		return nil, nil, err
   196  	}
   197  
   198  	runner := new(Runner)
   199  	resp, err := s.client.Do(ctx, req, runner)
   200  	if err != nil {
   201  		return nil, resp, err
   202  	}
   203  
   204  	return runner, resp, nil
   205  }
   206  
   207  // RemoveToken represents a token that can be used to remove a self-hosted runner from a repository.
   208  type RemoveToken struct {
   209  	Token     *string    `json:"token,omitempty"`
   210  	ExpiresAt *Timestamp `json:"expires_at,omitempty"`
   211  }
   212  
   213  // CreateRemoveToken creates a token that can be used to remove a self-hosted runner from a repository.
   214  //
   215  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-remove-token-for-a-repository
   216  //
   217  //meta:operation POST /repos/{owner}/{repo}/actions/runners/remove-token
   218  func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) {
   219  	u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo)
   220  
   221  	req, err := s.client.NewRequest("POST", u, nil)
   222  	if err != nil {
   223  		return nil, nil, err
   224  	}
   225  
   226  	removeToken := new(RemoveToken)
   227  	resp, err := s.client.Do(ctx, req, removeToken)
   228  	if err != nil {
   229  		return nil, resp, err
   230  	}
   231  
   232  	return removeToken, resp, nil
   233  }
   234  
   235  // RemoveRunner forces the removal of a self-hosted runner in a repository using the runner id.
   236  //
   237  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-a-repository
   238  //
   239  //meta:operation DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}
   240  func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) {
   241  	u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
   242  
   243  	req, err := s.client.NewRequest("DELETE", u, nil)
   244  	if err != nil {
   245  		return nil, err
   246  	}
   247  
   248  	return s.client.Do(ctx, req, nil)
   249  }
   250  
   251  // ListOrganizationRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
   252  //
   253  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-runner-applications-for-an-organization
   254  //
   255  //meta:operation GET /orgs/{org}/actions/runners/downloads
   256  func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, org string) ([]*RunnerApplicationDownload, *Response, error) {
   257  	u := fmt.Sprintf("orgs/%v/actions/runners/downloads", org)
   258  	req, err := s.client.NewRequest("GET", u, nil)
   259  	if err != nil {
   260  		return nil, nil, err
   261  	}
   262  
   263  	var rads []*RunnerApplicationDownload
   264  	resp, err := s.client.Do(ctx, req, &rads)
   265  	if err != nil {
   266  		return nil, resp, err
   267  	}
   268  
   269  	return rads, resp, nil
   270  }
   271  
   272  // CreateOrganizationRegistrationToken creates a token that can be used to add a self-hosted runner to an organization.
   273  //
   274  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-registration-token-for-an-organization
   275  //
   276  //meta:operation POST /orgs/{org}/actions/runners/registration-token
   277  func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, org string) (*RegistrationToken, *Response, error) {
   278  	u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", org)
   279  
   280  	req, err := s.client.NewRequest("POST", u, nil)
   281  	if err != nil {
   282  		return nil, nil, err
   283  	}
   284  
   285  	registrationToken := new(RegistrationToken)
   286  	resp, err := s.client.Do(ctx, req, registrationToken)
   287  	if err != nil {
   288  		return nil, resp, err
   289  	}
   290  
   291  	return registrationToken, resp, nil
   292  }
   293  
   294  // ListOrganizationRunners lists all the self-hosted runners for an organization.
   295  //
   296  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#list-self-hosted-runners-for-an-organization
   297  //
   298  //meta:operation GET /orgs/{org}/actions/runners
   299  func (s *ActionsService) ListOrganizationRunners(ctx context.Context, org string, opts *ListRunnersOptions) (*Runners, *Response, error) {
   300  	u := fmt.Sprintf("orgs/%v/actions/runners", org)
   301  	u, err := addOptions(u, opts)
   302  	if err != nil {
   303  		return nil, nil, err
   304  	}
   305  
   306  	req, err := s.client.NewRequest("GET", u, nil)
   307  	if err != nil {
   308  		return nil, nil, err
   309  	}
   310  
   311  	runners := &Runners{}
   312  	resp, err := s.client.Do(ctx, req, &runners)
   313  	if err != nil {
   314  		return nil, resp, err
   315  	}
   316  
   317  	return runners, resp, nil
   318  }
   319  
   320  // GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID.
   321  //
   322  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-an-organization
   323  //
   324  //meta:operation GET /orgs/{org}/actions/runners/{runner_id}
   325  func (s *ActionsService) GetOrganizationRunner(ctx context.Context, org string, runnerID int64) (*Runner, *Response, error) {
   326  	u := fmt.Sprintf("orgs/%v/actions/runners/%v", org, runnerID)
   327  	req, err := s.client.NewRequest("GET", u, nil)
   328  	if err != nil {
   329  		return nil, nil, err
   330  	}
   331  
   332  	runner := new(Runner)
   333  	resp, err := s.client.Do(ctx, req, runner)
   334  	if err != nil {
   335  		return nil, resp, err
   336  	}
   337  
   338  	return runner, resp, nil
   339  }
   340  
   341  // CreateOrganizationRemoveToken creates a token that can be used to remove a self-hosted runner from an organization.
   342  //
   343  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#create-a-remove-token-for-an-organization
   344  //
   345  //meta:operation POST /orgs/{org}/actions/runners/remove-token
   346  func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, org string) (*RemoveToken, *Response, error) {
   347  	u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", org)
   348  
   349  	req, err := s.client.NewRequest("POST", u, nil)
   350  	if err != nil {
   351  		return nil, nil, err
   352  	}
   353  
   354  	removeToken := new(RemoveToken)
   355  	resp, err := s.client.Do(ctx, req, removeToken)
   356  	if err != nil {
   357  		return nil, resp, err
   358  	}
   359  
   360  	return removeToken, resp, nil
   361  }
   362  
   363  // RemoveOrganizationRunner forces the removal of a self-hosted runner from an organization using the runner id.
   364  //
   365  // GitHub API docs: https://docs.github.com/rest/actions/self-hosted-runners#delete-a-self-hosted-runner-from-an-organization
   366  //
   367  //meta:operation DELETE /orgs/{org}/actions/runners/{runner_id}
   368  func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, org string, runnerID int64) (*Response, error) {
   369  	u := fmt.Sprintf("orgs/%v/actions/runners/%v", org, runnerID)
   370  
   371  	req, err := s.client.NewRequest("DELETE", u, nil)
   372  	if err != nil {
   373  		return nil, err
   374  	}
   375  
   376  	return s.client.Do(ctx, req, nil)
   377  }