...

Source file src/github.com/google/go-github/v55/github/actions_runner_groups.go

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

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

View as plain text