"Fossies" - the Fresh Open Source Software Archive

Member "cri-o-1.25.1/vendor/github.com/google/go-github/v45/github/actions_runner_groups.go" (7 Oct 2022, 12134 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 2021 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 // RunnerGroup represents a self-hosted runner group configured in an organization.
   14 type RunnerGroup struct {
   15     ID                       *int64  `json:"id,omitempty"`
   16     Name                     *string `json:"name,omitempty"`
   17     Visibility               *string `json:"visibility,omitempty"`
   18     Default                  *bool   `json:"default,omitempty"`
   19     SelectedRepositoriesURL  *string `json:"selected_repositories_url,omitempty"`
   20     RunnersURL               *string `json:"runners_url,omitempty"`
   21     Inherited                *bool   `json:"inherited,omitempty"`
   22     AllowsPublicRepositories *bool   `json:"allows_public_repositories,omitempty"`
   23 }
   24 
   25 // RunnerGroups represents a collection of self-hosted runner groups configured for an organization.
   26 type RunnerGroups struct {
   27     TotalCount   int            `json:"total_count"`
   28     RunnerGroups []*RunnerGroup `json:"runner_groups"`
   29 }
   30 
   31 // CreateRunnerGroupRequest represents a request to create a Runner group for an organization.
   32 type CreateRunnerGroupRequest struct {
   33     Name       *string `json:"name,omitempty"`
   34     Visibility *string `json:"visibility,omitempty"`
   35     // List of repository IDs that can access the runner group.
   36     SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"`
   37     // Runners represent a list of runner IDs to add to the runner group.
   38     Runners []int64 `json:"runners,omitempty"`
   39     // If set to True, public repos can use this runner group
   40     AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"`
   41 }
   42 
   43 // UpdateRunnerGroupRequest represents a request to update a Runner group for an organization.
   44 type UpdateRunnerGroupRequest struct {
   45     Name                     *string `json:"name,omitempty"`
   46     Visibility               *string `json:"visibility,omitempty"`
   47     AllowsPublicRepositories *bool   `json:"allows_public_repositories,omitempty"`
   48 }
   49 
   50 // SetRepoAccessRunnerGroupRequest represents a request to replace the list of repositories
   51 // that can access a self-hosted runner group configured in an organization.
   52 type SetRepoAccessRunnerGroupRequest struct {
   53     // Updated list of repository IDs that should be given access to the runner group.
   54     SelectedRepositoryIDs []int64 `json:"selected_repository_ids"`
   55 }
   56 
   57 // SetRunnerGroupRunnersRequest represents a request to replace the list of
   58 // self-hosted runners that are part of an organization runner group.
   59 type SetRunnerGroupRunnersRequest struct {
   60     // Updated list of runner IDs that should be given access to the runner group.
   61     Runners []int64 `json:"runners"`
   62 }
   63 
   64 // ListOrgRunnerGroupOptions extend ListOptions to have the optional parameters VisibleToRepository.
   65 type ListOrgRunnerGroupOptions struct {
   66     ListOptions
   67 
   68     // Only return runner groups that are allowed to be used by this repository.
   69     VisibleToRepository string `url:"visible_to_repository,omitempty"`
   70 }
   71 
   72 // ListOrganizationRunnerGroups lists all self-hosted runner groups configured in an organization.
   73 //
   74 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#list-self-hosted-runner-groups-for-an-organization
   75 func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOrgRunnerGroupOptions) (*RunnerGroups, *Response, error) {
   76     u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
   77     u, err := addOptions(u, opts)
   78     if err != nil {
   79         return nil, nil, err
   80     }
   81 
   82     req, err := s.client.NewRequest("GET", u, nil)
   83     if err != nil {
   84         return nil, nil, err
   85     }
   86 
   87     groups := &RunnerGroups{}
   88     resp, err := s.client.Do(ctx, req, &groups)
   89     if err != nil {
   90         return nil, resp, err
   91     }
   92 
   93     return groups, resp, nil
   94 }
   95 
   96 // GetOrganizationRunnerGroup gets a specific self-hosted runner group for an organization using its RunnerGroup ID.
   97 //
   98 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#get-a-self-hosted-runner-group-for-an-organization
   99 func (s *ActionsService) GetOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*RunnerGroup, *Response, error) {
  100     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
  101     req, err := s.client.NewRequest("GET", u, nil)
  102     if err != nil {
  103         return nil, nil, err
  104     }
  105 
  106     runnerGroup := new(RunnerGroup)
  107     resp, err := s.client.Do(ctx, req, runnerGroup)
  108     if err != nil {
  109         return nil, resp, err
  110     }
  111 
  112     return runnerGroup, resp, nil
  113 }
  114 
  115 // DeleteOrganizationRunnerGroup deletes a self-hosted runner group from an organization.
  116 //
  117 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#delete-a-self-hosted-runner-group-from-an-organization
  118 func (s *ActionsService) DeleteOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*Response, error) {
  119     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
  120 
  121     req, err := s.client.NewRequest("DELETE", u, nil)
  122     if err != nil {
  123         return nil, err
  124     }
  125 
  126     return s.client.Do(ctx, req, nil)
  127 }
  128 
  129 // CreateOrganizationRunnerGroup creates a new self-hosted runner group for an organization.
  130 //
  131 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#create-a-self-hosted-runner-group-for-an-organization
  132 func (s *ActionsService) CreateOrganizationRunnerGroup(ctx context.Context, org string, createReq CreateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
  133     u := fmt.Sprintf("orgs/%v/actions/runner-groups", org)
  134     req, err := s.client.NewRequest("POST", u, createReq)
  135     if err != nil {
  136         return nil, nil, err
  137     }
  138 
  139     runnerGroup := new(RunnerGroup)
  140     resp, err := s.client.Do(ctx, req, runnerGroup)
  141     if err != nil {
  142         return nil, resp, err
  143     }
  144 
  145     return runnerGroup, resp, nil
  146 }
  147 
  148 // UpdateOrganizationRunnerGroup updates a self-hosted runner group for an organization.
  149 //
  150 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#update-a-self-hosted-runner-group-for-an-organization
  151 func (s *ActionsService) UpdateOrganizationRunnerGroup(ctx context.Context, org string, groupID int64, updateReq UpdateRunnerGroupRequest) (*RunnerGroup, *Response, error) {
  152     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID)
  153     req, err := s.client.NewRequest("PATCH", u, updateReq)
  154     if err != nil {
  155         return nil, nil, err
  156     }
  157 
  158     runnerGroup := new(RunnerGroup)
  159     resp, err := s.client.Do(ctx, req, runnerGroup)
  160     if err != nil {
  161         return nil, resp, err
  162     }
  163 
  164     return runnerGroup, resp, nil
  165 }
  166 
  167 // ListRepositoryAccessRunnerGroup lists the repositories with access to a self-hosted runner group configured in an organization.
  168 //
  169 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#list-repository-access-to-a-self-hosted-runner-group-in-an-organization
  170 func (s *ActionsService) ListRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, opts *ListOptions) (*ListRepositories, *Response, error) {
  171     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
  172     u, err := addOptions(u, opts)
  173     if err != nil {
  174         return nil, nil, err
  175     }
  176 
  177     req, err := s.client.NewRequest("GET", u, nil)
  178     if err != nil {
  179         return nil, nil, err
  180     }
  181 
  182     repos := &ListRepositories{}
  183     resp, err := s.client.Do(ctx, req, &repos)
  184     if err != nil {
  185         return nil, resp, err
  186     }
  187 
  188     return repos, resp, nil
  189 }
  190 
  191 // SetRepositoryAccessRunnerGroup replaces the list of repositories that have access to a self-hosted runner group configured in an organization
  192 // with a new List of repositories.
  193 //
  194 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#set-repository-access-for-a-self-hosted-runner-group-in-an-organization
  195 func (s *ActionsService) SetRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, ids SetRepoAccessRunnerGroupRequest) (*Response, error) {
  196     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID)
  197 
  198     req, err := s.client.NewRequest("PUT", u, ids)
  199     if err != nil {
  200         return nil, err
  201     }
  202 
  203     return s.client.Do(ctx, req, nil)
  204 }
  205 
  206 // AddRepositoryAccessRunnerGroup adds a repository to the list of selected repositories that can access a self-hosted runner group.
  207 // The runner group must have visibility set to 'selected'.
  208 //
  209 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#add-repository-access-to-a-self-hosted-runner-group-in-an-organization
  210 func (s *ActionsService) AddRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
  211     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
  212 
  213     req, err := s.client.NewRequest("PUT", u, nil)
  214     if err != nil {
  215         return nil, err
  216     }
  217 
  218     return s.client.Do(ctx, req, nil)
  219 }
  220 
  221 // RemoveRepositoryAccessRunnerGroup removes a repository from the list of selected repositories that can access a self-hosted runner group.
  222 // The runner group must have visibility set to 'selected'.
  223 //
  224 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#remove-repository-access-to-a-self-hosted-runner-group-in-an-organization
  225 func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) {
  226     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID)
  227 
  228     req, err := s.client.NewRequest("DELETE", u, nil)
  229     if err != nil {
  230         return nil, err
  231     }
  232 
  233     return s.client.Do(ctx, req, nil)
  234 }
  235 
  236 // ListRunnerGroupRunners lists self-hosted runners that are in a specific organization group.
  237 //
  238 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#list-self-hosted-runners-in-a-group-for-an-organization
  239 func (s *ActionsService) ListRunnerGroupRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*Runners, *Response, error) {
  240     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID)
  241     u, err := addOptions(u, opts)
  242     if err != nil {
  243         return nil, nil, err
  244     }
  245 
  246     req, err := s.client.NewRequest("GET", u, nil)
  247     if err != nil {
  248         return nil, nil, err
  249     }
  250 
  251     runners := &Runners{}
  252     resp, err := s.client.Do(ctx, req, &runners)
  253     if err != nil {
  254         return nil, resp, err
  255     }
  256 
  257     return runners, resp, nil
  258 }
  259 
  260 // SetRunnerGroupRunners replaces the list of self-hosted runners that are part of an organization runner group
  261 // with a new list of runners.
  262 //
  263 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#set-self-hosted-runners-in-a-group-for-an-organization
  264 func (s *ActionsService) SetRunnerGroupRunners(ctx context.Context, org string, groupID int64, ids SetRunnerGroupRunnersRequest) (*Response, error) {
  265     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID)
  266 
  267     req, err := s.client.NewRequest("PUT", u, ids)
  268     if err != nil {
  269         return nil, err
  270     }
  271 
  272     return s.client.Do(ctx, req, nil)
  273 }
  274 
  275 // AddRunnerGroupRunners adds a self-hosted runner to a runner group configured in an organization.
  276 //
  277 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#add-a-self-hosted-runner-to-a-group-for-an-organization
  278 func (s *ActionsService) AddRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
  279     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
  280 
  281     req, err := s.client.NewRequest("PUT", u, nil)
  282     if err != nil {
  283         return nil, err
  284     }
  285 
  286     return s.client.Do(ctx, req, nil)
  287 }
  288 
  289 // RemoveRunnerGroupRunners removes a self-hosted runner from a group configured in an organization.
  290 // The runner is then returned to the default group.
  291 //
  292 // GitHub API docs: https://docs.github.com/en/rest/actions/self-hosted-runner-groups#remove-a-self-hosted-runner-from-a-group-for-an-organization
  293 func (s *ActionsService) RemoveRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) {
  294     u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID)
  295 
  296     req, err := s.client.NewRequest("DELETE", u, nil)
  297     if err != nil {
  298         return nil, err
  299     }
  300 
  301     return s.client.Do(ctx, req, nil)
  302 }