| 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/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#list-self-hosted-runner-groups-for-an-organization |
| 84 |
// |
| 85 |
//meta:operation GET /orgs/{org}/actions/runner-groups |
| 86 |
func (s *ActionsService) ListOrganizationRunnerGroups(ctx context.Context, org string, opts *ListOrgRunnerGroupOptions) (*RunnerGroups, *Response, error) { |
| 87 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups", org) |
| 88 |
u, err := addOptions(u, opts) |
| 89 |
if err != nil { |
| 90 |
return nil, nil, err |
| 91 |
} |
| 92 |
|
| 93 |
req, err := s.client.NewRequest("GET", u, nil) |
| 94 |
if err != nil { |
| 95 |
return nil, nil, err |
| 96 |
} |
| 97 |
|
| 98 |
groups := &RunnerGroups{} |
| 99 |
resp, err := s.client.Do(ctx, req, &groups) |
| 100 |
if err != nil { |
| 101 |
return nil, resp, err |
| 102 |
} |
| 103 |
|
| 104 |
return groups, resp, nil |
| 105 |
} |
| 106 |
|
| 107 |
// GetOrganizationRunnerGroup gets a specific self-hosted runner group for an organization using its RunnerGroup ID. |
| 108 |
// |
| 109 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#get-a-self-hosted-runner-group-for-an-organization |
| 110 |
// |
| 111 |
//meta:operation GET /orgs/{org}/actions/runner-groups/{runner_group_id} |
| 112 |
func (s *ActionsService) GetOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*RunnerGroup, *Response, error) { |
| 113 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID) |
| 114 |
req, err := s.client.NewRequest("GET", u, nil) |
| 115 |
if err != nil { |
| 116 |
return nil, nil, err |
| 117 |
} |
| 118 |
|
| 119 |
runnerGroup := new(RunnerGroup) |
| 120 |
resp, err := s.client.Do(ctx, req, runnerGroup) |
| 121 |
if err != nil { |
| 122 |
return nil, resp, err |
| 123 |
} |
| 124 |
|
| 125 |
return runnerGroup, resp, nil |
| 126 |
} |
| 127 |
|
| 128 |
// DeleteOrganizationRunnerGroup deletes a self-hosted runner group from an organization. |
| 129 |
// |
| 130 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#delete-a-self-hosted-runner-group-from-an-organization |
| 131 |
// |
| 132 |
//meta:operation DELETE /orgs/{org}/actions/runner-groups/{runner_group_id} |
| 133 |
func (s *ActionsService) DeleteOrganizationRunnerGroup(ctx context.Context, org string, groupID int64) (*Response, error) { |
| 134 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID) |
| 135 |
|
| 136 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 137 |
if err != nil { |
| 138 |
return nil, err |
| 139 |
} |
| 140 |
|
| 141 |
return s.client.Do(ctx, req, nil) |
| 142 |
} |
| 143 |
|
| 144 |
// CreateOrganizationRunnerGroup creates a new self-hosted runner group for an organization. |
| 145 |
// |
| 146 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#create-a-self-hosted-runner-group-for-an-organization |
| 147 |
// |
| 148 |
//meta:operation POST /orgs/{org}/actions/runner-groups |
| 149 |
func (s *ActionsService) CreateOrganizationRunnerGroup(ctx context.Context, org string, createReq CreateRunnerGroupRequest) (*RunnerGroup, *Response, error) { |
| 150 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups", org) |
| 151 |
req, err := s.client.NewRequest("POST", u, createReq) |
| 152 |
if err != nil { |
| 153 |
return nil, nil, err |
| 154 |
} |
| 155 |
|
| 156 |
runnerGroup := new(RunnerGroup) |
| 157 |
resp, err := s.client.Do(ctx, req, runnerGroup) |
| 158 |
if err != nil { |
| 159 |
return nil, resp, err |
| 160 |
} |
| 161 |
|
| 162 |
return runnerGroup, resp, nil |
| 163 |
} |
| 164 |
|
| 165 |
// UpdateOrganizationRunnerGroup updates a self-hosted runner group for an organization. |
| 166 |
// |
| 167 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#update-a-self-hosted-runner-group-for-an-organization |
| 168 |
// |
| 169 |
//meta:operation PATCH /orgs/{org}/actions/runner-groups/{runner_group_id} |
| 170 |
func (s *ActionsService) UpdateOrganizationRunnerGroup(ctx context.Context, org string, groupID int64, updateReq UpdateRunnerGroupRequest) (*RunnerGroup, *Response, error) { |
| 171 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v", org, groupID) |
| 172 |
req, err := s.client.NewRequest("PATCH", u, updateReq) |
| 173 |
if err != nil { |
| 174 |
return nil, nil, err |
| 175 |
} |
| 176 |
|
| 177 |
runnerGroup := new(RunnerGroup) |
| 178 |
resp, err := s.client.Do(ctx, req, runnerGroup) |
| 179 |
if err != nil { |
| 180 |
return nil, resp, err |
| 181 |
} |
| 182 |
|
| 183 |
return runnerGroup, resp, nil |
| 184 |
} |
| 185 |
|
| 186 |
// ListRepositoryAccessRunnerGroup lists the repositories with access to a self-hosted runner group configured in an organization. |
| 187 |
// |
| 188 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#list-repository-access-to-a-self-hosted-runner-group-in-an-organization |
| 189 |
// |
| 190 |
//meta:operation GET /orgs/{org}/actions/runner-groups/{runner_group_id}/repositories |
| 191 |
func (s *ActionsService) ListRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, opts *ListOptions) (*ListRepositories, *Response, error) { |
| 192 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID) |
| 193 |
u, err := addOptions(u, opts) |
| 194 |
if err != nil { |
| 195 |
return nil, nil, err |
| 196 |
} |
| 197 |
|
| 198 |
req, err := s.client.NewRequest("GET", u, nil) |
| 199 |
if err != nil { |
| 200 |
return nil, nil, err |
| 201 |
} |
| 202 |
|
| 203 |
repos := &ListRepositories{} |
| 204 |
resp, err := s.client.Do(ctx, req, &repos) |
| 205 |
if err != nil { |
| 206 |
return nil, resp, err |
| 207 |
} |
| 208 |
|
| 209 |
return repos, resp, nil |
| 210 |
} |
| 211 |
|
| 212 |
// SetRepositoryAccessRunnerGroup replaces the list of repositories that have access to a self-hosted runner group configured in an organization |
| 213 |
// with a new List of repositories. |
| 214 |
// |
| 215 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#set-repository-access-for-a-self-hosted-runner-group-in-an-organization |
| 216 |
// |
| 217 |
//meta:operation PUT /orgs/{org}/actions/runner-groups/{runner_group_id}/repositories |
| 218 |
func (s *ActionsService) SetRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID int64, ids SetRepoAccessRunnerGroupRequest) (*Response, error) { |
| 219 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories", org, groupID) |
| 220 |
|
| 221 |
req, err := s.client.NewRequest("PUT", u, ids) |
| 222 |
if err != nil { |
| 223 |
return nil, err |
| 224 |
} |
| 225 |
|
| 226 |
return s.client.Do(ctx, req, nil) |
| 227 |
} |
| 228 |
|
| 229 |
// AddRepositoryAccessRunnerGroup adds a repository to the list of selected repositories that can access a self-hosted runner group. |
| 230 |
// The runner group must have visibility set to 'selected'. |
| 231 |
// |
| 232 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#add-repository-access-to-a-self-hosted-runner-group-in-an-organization |
| 233 |
// |
| 234 |
//meta:operation PUT /orgs/{org}/actions/runner-groups/{runner_group_id}/repositories/{repository_id} |
| 235 |
func (s *ActionsService) AddRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) { |
| 236 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID) |
| 237 |
|
| 238 |
req, err := s.client.NewRequest("PUT", u, nil) |
| 239 |
if err != nil { |
| 240 |
return nil, err |
| 241 |
} |
| 242 |
|
| 243 |
return s.client.Do(ctx, req, nil) |
| 244 |
} |
| 245 |
|
| 246 |
// RemoveRepositoryAccessRunnerGroup removes a repository from the list of selected repositories that can access a self-hosted runner group. |
| 247 |
// The runner group must have visibility set to 'selected'. |
| 248 |
// |
| 249 |
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups#remove-repository-access-to-a-self-hosted-runner-group-in-an-organization |
| 250 |
// |
| 251 |
//meta:operation DELETE /orgs/{org}/actions/runner-groups/{runner_group_id}/repositories/{repository_id} |
| 252 |
func (s *ActionsService) RemoveRepositoryAccessRunnerGroup(ctx context.Context, org string, groupID, repoID int64) (*Response, error) { |
| 253 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/repositories/%v", org, groupID, repoID) |
| 254 |
|
| 255 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 256 |
if err != nil { |
| 257 |
return nil, err |
| 258 |
} |
| 259 |
|
| 260 |
return s.client.Do(ctx, req, nil) |
| 261 |
} |
| 262 |
|
| 263 |
// ListRunnerGroupRunners lists self-hosted runners that are in a specific organization group. |
| 264 |
// |
| 265 |
// 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-organization |
| 266 |
// |
| 267 |
//meta:operation GET /orgs/{org}/actions/runner-groups/{runner_group_id}/runners |
| 268 |
func (s *ActionsService) ListRunnerGroupRunners(ctx context.Context, org string, groupID int64, opts *ListOptions) (*Runners, *Response, error) { |
| 269 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID) |
| 270 |
u, err := addOptions(u, opts) |
| 271 |
if err != nil { |
| 272 |
return nil, nil, err |
| 273 |
} |
| 274 |
|
| 275 |
req, err := s.client.NewRequest("GET", u, nil) |
| 276 |
if err != nil { |
| 277 |
return nil, nil, err |
| 278 |
} |
| 279 |
|
| 280 |
runners := &Runners{} |
| 281 |
resp, err := s.client.Do(ctx, req, &runners) |
| 282 |
if err != nil { |
| 283 |
return nil, resp, err |
| 284 |
} |
| 285 |
|
| 286 |
return runners, resp, nil |
| 287 |
} |
| 288 |
|
| 289 |
// SetRunnerGroupRunners replaces the list of self-hosted runners that are part of an organization runner group |
| 290 |
// with a new list of runners. |
| 291 |
// |
| 292 |
// 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-organization |
| 293 |
// |
| 294 |
//meta:operation PUT /orgs/{org}/actions/runner-groups/{runner_group_id}/runners |
| 295 |
func (s *ActionsService) SetRunnerGroupRunners(ctx context.Context, org string, groupID int64, ids SetRunnerGroupRunnersRequest) (*Response, error) { |
| 296 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners", org, groupID) |
| 297 |
|
| 298 |
req, err := s.client.NewRequest("PUT", u, ids) |
| 299 |
if err != nil { |
| 300 |
return nil, err |
| 301 |
} |
| 302 |
|
| 303 |
return s.client.Do(ctx, req, nil) |
| 304 |
} |
| 305 |
|
| 306 |
// AddRunnerGroupRunners adds a self-hosted runner to a runner group configured in an organization. |
| 307 |
// |
| 308 |
// 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-organization |
| 309 |
// |
| 310 |
//meta:operation PUT /orgs/{org}/actions/runner-groups/{runner_group_id}/runners/{runner_id} |
| 311 |
func (s *ActionsService) AddRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) { |
| 312 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID) |
| 313 |
|
| 314 |
req, err := s.client.NewRequest("PUT", u, nil) |
| 315 |
if err != nil { |
| 316 |
return nil, err |
| 317 |
} |
| 318 |
|
| 319 |
return s.client.Do(ctx, req, nil) |
| 320 |
} |
| 321 |
|
| 322 |
// RemoveRunnerGroupRunners removes a self-hosted runner from a group configured in an organization. |
| 323 |
// The runner is then returned to the default group. |
| 324 |
// |
| 325 |
// 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-organization |
| 326 |
// |
| 327 |
//meta:operation DELETE /orgs/{org}/actions/runner-groups/{runner_group_id}/runners/{runner_id} |
| 328 |
func (s *ActionsService) RemoveRunnerGroupRunners(ctx context.Context, org string, groupID, runnerID int64) (*Response, error) { |
| 329 |
u := fmt.Sprintf("orgs/%v/actions/runner-groups/%v/runners/%v", org, groupID, runnerID) |
| 330 |
|
| 331 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 332 |
if err != nil { |
| 333 |
return nil, err |
| 334 |
} |
| 335 |
|
| 336 |
return s.client.Do(ctx, req, nil) |
| 337 |
} |