From 82defe01bd5681d587cc511bb627b199121930e9 Mon Sep 17 00:00:00 2001 From: Florian Braun Date: Wed, 14 Jul 2021 23:40:03 +0200 Subject: [PATCH 1/2] Add allows_public_repositories to actions_runner_group Adds allows_public_repositories to request bodies of the CreateRunnerGroup as well as UpdateRunnerGroup methods for github actions. This allows us to set the allows_public_repositories flag even if it is not yet properly documented see https://github.com/github/docs/issues/8209 That flag controls if public repos can use runners of this group. If it is disabled(default) even public repos that are added to the selected_repositories list cannot use runners of this group. With this change we can now set this properly and thus use runner groups created by go-github also for public repos. Fixes #1996 --- github/actions_runner_groups.go | 7 +++++-- github/actions_runner_groups_test.go | 30 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/github/actions_runner_groups.go b/github/actions_runner_groups.go index 5772daaa756..e34495a9609 100644 --- a/github/actions_runner_groups.go +++ b/github/actions_runner_groups.go @@ -36,12 +36,15 @@ type CreateRunnerGroupRequest struct { SelectedRepositoryIDs []int64 `json:"selected_repository_ids,omitempty"` // Runners represent a list of runner IDs to add to the runner group. Runners []int64 `json:"runners,omitempty"` + // If set to True, public repos can use this runner group + AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"` } // UpdateRunnerGroupRequest represents a request to update a Runner group for an organization. type UpdateRunnerGroupRequest struct { - Name *string `json:"name,omitempty"` - Visibility *string `json:"visibility,omitempty"` + Name *string `json:"name,omitempty"` + Visibility *string `json:"visibility,omitempty"` + AllowsPublicRepositories *bool `json:"allows_public_repositories,omitempty"` } // SetRepoAccessRunnerGroupRequest represents a request to replace the list of repositories diff --git a/github/actions_runner_groups_test.go b/github/actions_runner_groups_test.go index 27489ad99bd..55de0b938dd 100644 --- a/github/actions_runner_groups_test.go +++ b/github/actions_runner_groups_test.go @@ -139,8 +139,9 @@ func TestActionsService_CreateOrganizationRunnerGroup(t *testing.T) { ctx := context.Background() req := CreateRunnerGroupRequest{ - Name: String("octo-runner-group"), - Visibility: String("selected"), + Name: String("octo-runner-group"), + Visibility: String("selected"), + AllowsPublicRepositories: Bool(true), } group, _, err := client.Actions.CreateOrganizationRunnerGroup(ctx, "o", req) if err != nil { @@ -188,8 +189,9 @@ func TestActionsService_UpdateOrganizationRunnerGroup(t *testing.T) { ctx := context.Background() req := UpdateRunnerGroupRequest{ - Name: String("octo-runner-group"), - Visibility: String("selected"), + Name: String("octo-runner-group"), + Visibility: String("selected"), + AllowsPublicRepositories: Bool(true), } group, _, err := client.Actions.UpdateOrganizationRunnerGroup(ctx, "o", 2, req) if err != nil { @@ -541,17 +543,19 @@ func TestCreateRunnerGroupRequest_Marshal(t *testing.T) { testJSONMarshal(t, &CreateRunnerGroupRequest{}, "{}") u := &CreateRunnerGroupRequest{ - Name: String("n"), - Visibility: String("v"), - SelectedRepositoryIDs: []int64{1}, - Runners: []int64{1}, + Name: String("n"), + Visibility: String("v"), + SelectedRepositoryIDs: []int64{1}, + Runners: []int64{1}, + AllowsPublicRepositories: Bool(true), } want := `{ "name": "n", "visibility": "v", "selected_repository_ids": [1], - "runners": [1] + "runners": [1], + "allows_public_repositories": true }` testJSONMarshal(t, u, want) @@ -561,13 +565,15 @@ func TestUpdateRunnerGroupRequest_Marshal(t *testing.T) { testJSONMarshal(t, &UpdateRunnerGroupRequest{}, "{}") u := &UpdateRunnerGroupRequest{ - Name: String("n"), - Visibility: String("v"), + Name: String("n"), + Visibility: String("v"), + AllowsPublicRepositories: Bool(true), } want := `{ "name": "n", - "visibility": "v" + "visibility": "v", + "allows_public_repositories": true }` testJSONMarshal(t, u, want) From a885e131e11341f2bc1dd2d34a940c7a7845026a Mon Sep 17 00:00:00 2001 From: Florian Braun Date: Thu, 15 Jul 2021 09:24:43 +0200 Subject: [PATCH 2/2] Add go generate changes --- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index fb3e2903654..3dcb9a4e731 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2916,6 +2916,14 @@ func (c *CreateOrgInvitationOptions) GetRole() string { return *c.Role } +// GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. +func (c *CreateRunnerGroupRequest) GetAllowsPublicRepositories() bool { + if c == nil || c.AllowsPublicRepositories == nil { + return false + } + return *c.AllowsPublicRepositories +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (c *CreateRunnerGroupRequest) GetName() string { if c == nil || c.Name == nil { @@ -15924,6 +15932,14 @@ func (u *UpdateCheckRunOptions) GetStatus() string { return *u.Status } +// GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. +func (u *UpdateRunnerGroupRequest) GetAllowsPublicRepositories() bool { + if u == nil || u.AllowsPublicRepositories == nil { + return false + } + return *u.AllowsPublicRepositories +} + // GetName returns the Name field if it's non-nil, zero value otherwise. func (u *UpdateRunnerGroupRequest) GetName() string { if u == nil || u.Name == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 03fd08ea081..e0be06149d7 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -3415,6 +3415,16 @@ func TestCreateOrgInvitationOptions_GetRole(tt *testing.T) { c.GetRole() } +func TestCreateRunnerGroupRequest_GetAllowsPublicRepositories(tt *testing.T) { + var zeroValue bool + c := &CreateRunnerGroupRequest{AllowsPublicRepositories: &zeroValue} + c.GetAllowsPublicRepositories() + c = &CreateRunnerGroupRequest{} + c.GetAllowsPublicRepositories() + c = nil + c.GetAllowsPublicRepositories() +} + func TestCreateRunnerGroupRequest_GetName(tt *testing.T) { var zeroValue string c := &CreateRunnerGroupRequest{Name: &zeroValue} @@ -18619,6 +18629,16 @@ func TestUpdateCheckRunOptions_GetStatus(tt *testing.T) { u.GetStatus() } +func TestUpdateRunnerGroupRequest_GetAllowsPublicRepositories(tt *testing.T) { + var zeroValue bool + u := &UpdateRunnerGroupRequest{AllowsPublicRepositories: &zeroValue} + u.GetAllowsPublicRepositories() + u = &UpdateRunnerGroupRequest{} + u.GetAllowsPublicRepositories() + u = nil + u.GetAllowsPublicRepositories() +} + func TestUpdateRunnerGroupRequest_GetName(tt *testing.T) { var zeroValue string u := &UpdateRunnerGroupRequest{Name: &zeroValue}