github.com/google/go-github/v57@v57.0.0/github/enterprise_actions_runner_groups.go (about)

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