"Fossies" - the Fresh Open Source Software Archive

Member "cri-o-1.25.1/vendor/github.com/google/go-github/v42/github/actions_runners.go" (7 Oct 2022, 13281 Bytes) of package /linux/misc/cri-o-1.25.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 // ActionsEnabledOnOrgRepos represents all the repositories in an organization for which Actions is enabled.
   24 type ActionsEnabledOnOrgRepos struct {
   25     TotalCount   int           `json:"total_count"`
   26     Repositories []*Repository `json:"repositories"`
   27 }
   28 
   29 // ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
   30 //
   31 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-runner-applications-for-a-repository
   32 func (s *ActionsService) ListRunnerApplicationDownloads(ctx context.Context, owner, repo string) ([]*RunnerApplicationDownload, *Response, error) {
   33     u := fmt.Sprintf("repos/%v/%v/actions/runners/downloads", owner, repo)
   34     req, err := s.client.NewRequest("GET", u, nil)
   35     if err != nil {
   36         return nil, nil, err
   37     }
   38 
   39     var rads []*RunnerApplicationDownload
   40     resp, err := s.client.Do(ctx, req, &rads)
   41     if err != nil {
   42         return nil, resp, err
   43     }
   44 
   45     return rads, resp, nil
   46 }
   47 
   48 // RegistrationToken represents a token that can be used to add a self-hosted runner to a repository.
   49 type RegistrationToken struct {
   50     Token     *string    `json:"token,omitempty"`
   51     ExpiresAt *Timestamp `json:"expires_at,omitempty"`
   52 }
   53 
   54 // CreateRegistrationToken creates a token that can be used to add a self-hosted runner.
   55 //
   56 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-registration-token-for-a-repository
   57 func (s *ActionsService) CreateRegistrationToken(ctx context.Context, owner, repo string) (*RegistrationToken, *Response, error) {
   58     u := fmt.Sprintf("repos/%v/%v/actions/runners/registration-token", owner, repo)
   59 
   60     req, err := s.client.NewRequest("POST", u, nil)
   61     if err != nil {
   62         return nil, nil, err
   63     }
   64 
   65     registrationToken := new(RegistrationToken)
   66     resp, err := s.client.Do(ctx, req, registrationToken)
   67     if err != nil {
   68         return nil, resp, err
   69     }
   70 
   71     return registrationToken, resp, nil
   72 }
   73 
   74 // Runner represents a self-hosted runner registered with a repository.
   75 type Runner struct {
   76     ID     *int64          `json:"id,omitempty"`
   77     Name   *string         `json:"name,omitempty"`
   78     OS     *string         `json:"os,omitempty"`
   79     Status *string         `json:"status,omitempty"`
   80     Busy   *bool           `json:"busy,omitempty"`
   81     Labels []*RunnerLabels `json:"labels,omitempty"`
   82 }
   83 
   84 // RunnerLabels represents a collection of labels attached to each runner.
   85 type RunnerLabels struct {
   86     ID   *int64  `json:"id,omitempty"`
   87     Name *string `json:"name,omitempty"`
   88     Type *string `json:"type,omitempty"`
   89 }
   90 
   91 // Runners represents a collection of self-hosted runners for a repository.
   92 type Runners struct {
   93     TotalCount int       `json:"total_count"`
   94     Runners    []*Runner `json:"runners"`
   95 }
   96 
   97 // ListRunners lists all the self-hosted runners for a repository.
   98 //
   99 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-self-hosted-runners-for-a-repository
  100 func (s *ActionsService) ListRunners(ctx context.Context, owner, repo string, opts *ListOptions) (*Runners, *Response, error) {
  101     u := fmt.Sprintf("repos/%v/%v/actions/runners", owner, repo)
  102     u, err := addOptions(u, opts)
  103     if err != nil {
  104         return nil, nil, err
  105     }
  106 
  107     req, err := s.client.NewRequest("GET", u, nil)
  108     if err != nil {
  109         return nil, nil, err
  110     }
  111 
  112     runners := &Runners{}
  113     resp, err := s.client.Do(ctx, req, &runners)
  114     if err != nil {
  115         return nil, resp, err
  116     }
  117 
  118     return runners, resp, nil
  119 }
  120 
  121 // GetRunner gets a specific self-hosted runner for a repository using its runner ID.
  122 //
  123 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-self-hosted-runner-for-a-repository
  124 func (s *ActionsService) GetRunner(ctx context.Context, owner, repo string, runnerID int64) (*Runner, *Response, error) {
  125     u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
  126     req, err := s.client.NewRequest("GET", u, nil)
  127     if err != nil {
  128         return nil, nil, err
  129     }
  130 
  131     runner := new(Runner)
  132     resp, err := s.client.Do(ctx, req, runner)
  133     if err != nil {
  134         return nil, resp, err
  135     }
  136 
  137     return runner, resp, nil
  138 }
  139 
  140 // RemoveToken represents a token that can be used to remove a self-hosted runner from a repository.
  141 type RemoveToken struct {
  142     Token     *string    `json:"token,omitempty"`
  143     ExpiresAt *Timestamp `json:"expires_at,omitempty"`
  144 }
  145 
  146 // CreateRemoveToken creates a token that can be used to remove a self-hosted runner from a repository.
  147 //
  148 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-remove-token-for-a-repository
  149 func (s *ActionsService) CreateRemoveToken(ctx context.Context, owner, repo string) (*RemoveToken, *Response, error) {
  150     u := fmt.Sprintf("repos/%v/%v/actions/runners/remove-token", owner, repo)
  151 
  152     req, err := s.client.NewRequest("POST", u, nil)
  153     if err != nil {
  154         return nil, nil, err
  155     }
  156 
  157     removeToken := new(RemoveToken)
  158     resp, err := s.client.Do(ctx, req, removeToken)
  159     if err != nil {
  160         return nil, resp, err
  161     }
  162 
  163     return removeToken, resp, nil
  164 }
  165 
  166 // RemoveRunner forces the removal of a self-hosted runner in a repository using the runner id.
  167 //
  168 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-a-self-hosted-runner-from-a-repository
  169 func (s *ActionsService) RemoveRunner(ctx context.Context, owner, repo string, runnerID int64) (*Response, error) {
  170     u := fmt.Sprintf("repos/%v/%v/actions/runners/%v", owner, repo, runnerID)
  171 
  172     req, err := s.client.NewRequest("DELETE", u, nil)
  173     if err != nil {
  174         return nil, err
  175     }
  176 
  177     return s.client.Do(ctx, req, nil)
  178 }
  179 
  180 // ListOrganizationRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.
  181 //
  182 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-runner-applications-for-an-organization
  183 func (s *ActionsService) ListOrganizationRunnerApplicationDownloads(ctx context.Context, owner string) ([]*RunnerApplicationDownload, *Response, error) {
  184     u := fmt.Sprintf("orgs/%v/actions/runners/downloads", owner)
  185     req, err := s.client.NewRequest("GET", u, nil)
  186     if err != nil {
  187         return nil, nil, err
  188     }
  189 
  190     var rads []*RunnerApplicationDownload
  191     resp, err := s.client.Do(ctx, req, &rads)
  192     if err != nil {
  193         return nil, resp, err
  194     }
  195 
  196     return rads, resp, nil
  197 }
  198 
  199 // CreateOrganizationRegistrationToken creates a token that can be used to add a self-hosted runner to an organization.
  200 //
  201 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-registration-token-for-an-organization
  202 func (s *ActionsService) CreateOrganizationRegistrationToken(ctx context.Context, owner string) (*RegistrationToken, *Response, error) {
  203     u := fmt.Sprintf("orgs/%v/actions/runners/registration-token", owner)
  204 
  205     req, err := s.client.NewRequest("POST", u, nil)
  206     if err != nil {
  207         return nil, nil, err
  208     }
  209 
  210     registrationToken := new(RegistrationToken)
  211     resp, err := s.client.Do(ctx, req, registrationToken)
  212     if err != nil {
  213         return nil, resp, err
  214     }
  215 
  216     return registrationToken, resp, nil
  217 }
  218 
  219 // ListOrganizationRunners lists all the self-hosted runners for an organization.
  220 //
  221 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-self-hosted-runners-for-an-organization
  222 func (s *ActionsService) ListOrganizationRunners(ctx context.Context, owner string, opts *ListOptions) (*Runners, *Response, error) {
  223     u := fmt.Sprintf("orgs/%v/actions/runners", owner)
  224     u, err := addOptions(u, opts)
  225     if err != nil {
  226         return nil, nil, err
  227     }
  228 
  229     req, err := s.client.NewRequest("GET", u, nil)
  230     if err != nil {
  231         return nil, nil, err
  232     }
  233 
  234     runners := &Runners{}
  235     resp, err := s.client.Do(ctx, req, &runners)
  236     if err != nil {
  237         return nil, resp, err
  238     }
  239 
  240     return runners, resp, nil
  241 }
  242 
  243 // ListEnabledReposInOrg lists the selected repositories that are enabled for GitHub Actions in an organization.
  244 //
  245 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#list-selected-repositories-enabled-for-github-actions-in-an-organization
  246 func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) {
  247     u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
  248     u, err := addOptions(u, opts)
  249     if err != nil {
  250         return nil, nil, err
  251     }
  252 
  253     req, err := s.client.NewRequest("GET", u, nil)
  254     if err != nil {
  255         return nil, nil, err
  256     }
  257 
  258     repos := &ActionsEnabledOnOrgRepos{}
  259     resp, err := s.client.Do(ctx, req, repos)
  260     if err != nil {
  261         return nil, resp, err
  262     }
  263 
  264     return repos, resp, nil
  265 }
  266 
  267 // SetEnabledReposInOrg replaces the list of selected repositories that are enabled for GitHub Actions in an organization..
  268 //
  269 // GitHub API docs: https://docs.github.com/en/rest/reference/actions#set-selected-repositories-enabled-for-github-actions-in-an-organization
  270 func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) {
  271     u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
  272 
  273     req, err := s.client.NewRequest("PUT", u, struct {
  274         IDs []int64 `json:"selected_repository_ids"`
  275     }{IDs: repositoryIDs})
  276     if err != nil {
  277         return nil, err
  278     }
  279 
  280     resp, err := s.client.Do(ctx, req, nil)
  281     if err != nil {
  282         return resp, err
  283     }
  284 
  285     return resp, nil
  286 }
  287 
  288 // AddEnabledReposInOrg adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization.
  289 //
  290 // GitHub API docs: https://docs.github.com/en/rest/reference/actions#enable-a-selected-repository-for-github-actions-in-an-organization
  291 func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
  292     u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
  293 
  294     req, err := s.client.NewRequest("PUT", u, nil)
  295     if err != nil {
  296         return nil, err
  297     }
  298 
  299     resp, err := s.client.Do(ctx, req, nil)
  300     if err != nil {
  301         return resp, err
  302     }
  303 
  304     return resp, nil
  305 }
  306 
  307 // RemoveEnabledRepoInOrg removes a single repository from the list of enabled repos for GitHub Actions in an organization.
  308 //
  309 // GitHub API docs: https://docs.github.com/en/rest/reference/actions#disable-a-selected-repository-for-github-actions-in-an-organization
  310 func (s *ActionsService) RemoveEnabledRepoInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
  311     u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
  312 
  313     req, err := s.client.NewRequest("DELETE", u, nil)
  314     if err != nil {
  315         return nil, err
  316     }
  317 
  318     resp, err := s.client.Do(ctx, req, nil)
  319     if err != nil {
  320         return resp, err
  321     }
  322 
  323     return resp, nil
  324 }
  325 
  326 // GetOrganizationRunner gets a specific self-hosted runner for an organization using its runner ID.
  327 //
  328 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#get-a-self-hosted-runner-for-an-organization
  329 func (s *ActionsService) GetOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Runner, *Response, error) {
  330     u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, runnerID)
  331     req, err := s.client.NewRequest("GET", u, nil)
  332     if err != nil {
  333         return nil, nil, err
  334     }
  335 
  336     runner := new(Runner)
  337     resp, err := s.client.Do(ctx, req, runner)
  338     if err != nil {
  339         return nil, resp, err
  340     }
  341 
  342     return runner, resp, nil
  343 }
  344 
  345 // CreateOrganizationRemoveToken creates a token that can be used to remove a self-hosted runner from an organization.
  346 //
  347 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#create-a-remove-token-for-an-organization
  348 func (s *ActionsService) CreateOrganizationRemoveToken(ctx context.Context, owner string) (*RemoveToken, *Response, error) {
  349     u := fmt.Sprintf("orgs/%v/actions/runners/remove-token", owner)
  350 
  351     req, err := s.client.NewRequest("POST", u, nil)
  352     if err != nil {
  353         return nil, nil, err
  354     }
  355 
  356     removeToken := new(RemoveToken)
  357     resp, err := s.client.Do(ctx, req, removeToken)
  358     if err != nil {
  359         return nil, resp, err
  360     }
  361 
  362     return removeToken, resp, nil
  363 }
  364 
  365 // RemoveOrganizationRunner forces the removal of a self-hosted runner from an organization using the runner id.
  366 //
  367 // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-a-self-hosted-runner-from-an-organization
  368 func (s *ActionsService) RemoveOrganizationRunner(ctx context.Context, owner string, runnerID int64) (*Response, error) {
  369     u := fmt.Sprintf("orgs/%v/actions/runners/%v", owner, 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 }