From 6bbcd52c40ec47fa2db1786e77a44699d35ba66d Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 14:25:07 +0900 Subject: [PATCH 1/9] feat: self-hosted runner permissions api for enterprises --- github/actions_permissions_enterprise.go | 41 +++++++++++ github/actions_permissions_enterprise_test.go | 72 +++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/github/actions_permissions_enterprise.go b/github/actions_permissions_enterprise.go index faed5116557..45a388e5d16 100644 --- a/github/actions_permissions_enterprise.go +++ b/github/actions_permissions_enterprise.go @@ -37,6 +37,11 @@ type DefaultWorkflowPermissionEnterprise struct { CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"` } +// SelfHostRunnerPermissionsEnterprise represents the settings for whether organizations in the enterprise are allowed to manage self-hosted runners at the repository level +type SelfHostRunnerPermissionsEnterprise struct { + DisableSelfHostedRunnersForAllOrgs *bool `json:"disable_self_hosted_runners_for_all_orgs,omitempty"` +} + // GetActionsPermissionsInEnterprise gets the GitHub Actions permissions policy for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#get-github-actions-permissions-for-an-enterprise @@ -293,3 +298,39 @@ func (s *ActionsService) EditArtifactAndLogRetentionPeriodInEnterprise(ctx conte return s.client.Do(ctx, req, nil) } + +// GetSelfHostedRunnerPermissionsInEnterprise gets the self-hosted runner permissions for an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#get-self-hosted-runners-permissions-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/actions/permissions/self-hosted-runners +func (s *ActionsService) GetSelfHostedRunnerPermissionsInEnterprise(ctx context.Context, enterprise string) (*SelfHostRunnerPermissionsEnterprise, *Response, error) { + u := fmt.Sprintf("enterprises/%v/actions/permissions/self-hosted-runners", enterprise) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + permissions := new(SelfHostRunnerPermissionsEnterprise) + resp, err := s.client.Do(ctx, req, permissions) + if err != nil { + return nil, resp, err + } + + return permissions, resp, nil +} + +// EditSelfHostedRunnerPermissionsInEnterprise gets the self-hosted runner permissions for an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#set-self-hosted-runners-permissions-for-an-enterprise +// +//meta:operation PUT /enterprises/{enterprise}/actions/permissions/self-hosted-runners +func (s *ActionsService) EditSelfHostedRunnerPermissionsInEnterprise(ctx context.Context, enterprise string, permissions SelfHostRunnerPermissionsEnterprise) (*Response, error) { + u := fmt.Sprintf("enterprises/%v/actions/permissions/self-hosted-runners", enterprise) + req, err := s.client.NewRequest("PUT", u, permissions) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/github/actions_permissions_enterprise_test.go b/github/actions_permissions_enterprise_test.go index acd07a6a627..0a5cb22684f 100644 --- a/github/actions_permissions_enterprise_test.go +++ b/github/actions_permissions_enterprise_test.go @@ -451,3 +451,75 @@ func TestActionsService_EditArtifactAndLogRetentionPeriodInEnterprise(t *testing return client.Actions.EditArtifactAndLogRetentionPeriodInEnterprise(ctx, "e", *input) }) } + +func TestActionsService_GetSelfHostedRunnerPermissionsInEnterprise(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"disable_self_hosted_runners_for_all_orgs": true}`) + }) + + ctx := context.Background() + permissions, _, err := client.Actions.GetSelfHostedRunnerPermissionsInEnterprise(ctx, "e") + if err != nil { + t.Errorf("Actions.GetSelfHostedRunnerPermissionsInEnterprise returned error: %v", err) + } + want := &SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs: Ptr(true)} + if !cmp.Equal(permissions, want) { + t.Errorf("Actions.GetSelfHostedRunnerPermissionsInEnterprise returned %+v, want %+v", permissions, want) + } + + const methodName = "GetSelfHostedRunnerPermissionsInEnterprise" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.GetSelfHostedRunnerPermissionsInEnterprise(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.GetSelfHostedRunnerPermissionsInEnterprise(ctx, "e") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestActionsService_EditSelfHostedRunnerPermissionsInEnterprise(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + input := &SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs: Ptr(false)} + + mux.HandleFunc("/enterprises/e/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) { + v := new(SelfHostRunnerPermissionsEnterprise) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + + testMethod(t, r, "PUT") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + resp, err := client.Actions.EditSelfHostedRunnerPermissionsInEnterprise(ctx, "e", *input) + if err != nil { + t.Errorf("Actions.EditSelfHostedRunnerPermissionsInEnterprise returned error: %v", err) + } + + if resp.StatusCode != http.StatusNoContent { + t.Errorf("Actions.EditSelfHostedRunnerPermissionsInEnterprise = %d, want %d", resp.StatusCode, http.StatusNoContent) + } + + const methodName = "EditSelfHostedRunnerPermissionsInEnterprise" + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.EditSelfHostedRunnerPermissionsInEnterprise(ctx, "\n", *input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.EditSelfHostedRunnerPermissionsInEnterprise(ctx, "e", *input) + }) +} From ed6caca07b221337ec8323b35534abdfb3369640 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 14:31:19 +0900 Subject: [PATCH 2/9] chore: add String method for SelfHostRunnerPermissionsEnterprise --- github/actions_permissions_enterprise.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/github/actions_permissions_enterprise.go b/github/actions_permissions_enterprise.go index 45a388e5d16..f73c1a41138 100644 --- a/github/actions_permissions_enterprise.go +++ b/github/actions_permissions_enterprise.go @@ -42,6 +42,10 @@ type SelfHostRunnerPermissionsEnterprise struct { DisableSelfHostedRunnersForAllOrgs *bool `json:"disable_self_hosted_runners_for_all_orgs,omitempty"` } +func (a SelfHostRunnerPermissionsEnterprise) String() string { + return Stringify(a) +} + // GetActionsPermissionsInEnterprise gets the GitHub Actions permissions policy for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#get-github-actions-permissions-for-an-enterprise From 5aea5dce827b17090e38e421a4f36192c33b8c64 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 14:39:02 +0900 Subject: [PATCH 3/9] chore: update comment for SelfHostRunnerPermissionsEnterprise struct --- github/actions_permissions_enterprise.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/actions_permissions_enterprise.go b/github/actions_permissions_enterprise.go index f73c1a41138..2f46c9ac720 100644 --- a/github/actions_permissions_enterprise.go +++ b/github/actions_permissions_enterprise.go @@ -37,7 +37,7 @@ type DefaultWorkflowPermissionEnterprise struct { CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"` } -// SelfHostRunnerPermissionsEnterprise represents the settings for whether organizations in the enterprise are allowed to manage self-hosted runners at the repository level +// SelfHostRunnerPermissionsEnterprise represents the settings for whether organizations in the enterprise are allowed to manage self-hosted runners at the repository level. type SelfHostRunnerPermissionsEnterprise struct { DisableSelfHostedRunnersForAllOrgs *bool `json:"disable_self_hosted_runners_for_all_orgs,omitempty"` } From 719ff2391545c5c71c3cd5aa0f3d74c8ab4952e4 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 15:03:30 +0900 Subject: [PATCH 4/9] chore: add zyfy29 to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index a6104ffa9aa..d79ac6a7c4c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -543,6 +543,7 @@ Yusuke Kuoka Zach Latta Ze Peng zhouhaibing089 +zyfy29 六开箱 缘生 蒋航 From 351890e798c892c25487eba2a124b38aa31f36aa Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 15:26:48 +0900 Subject: [PATCH 5/9] feat: add self-hosted runners overall settings API for organizations --- github/actions_permissions_orgs.go | 53 +++++++++++++++++ github/actions_permissions_orgs_test.go | 75 +++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/github/actions_permissions_orgs.go b/github/actions_permissions_orgs.go index 5684aa233bc..95b85600422 100644 --- a/github/actions_permissions_orgs.go +++ b/github/actions_permissions_orgs.go @@ -50,6 +50,21 @@ type DefaultWorkflowPermissionOrganization struct { CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"` } +// SelfHostedRunnersSettingsOrganization represents the self-hosted runners permissions settings for repositories in an organization. +type SelfHostedRunnersSettingsOrganization struct { + EnabledRepositories *string `json:"enabled_repositories,omitempty"` + SelectedRepositoriesUrl *string `json:"selected_repositories_url,omitempty"` +} + +func (s SelfHostedRunnersSettingsOrganization) String() string { + return Stringify(s) +} + +// SelfHostedRunnersSettingsOrganizationOpt specifies the self-hosted runners permissions settings for repositories in an organization. +type SelfHostedRunnersSettingsOrganizationOpt struct { + EnabledRepositories *string `json:"enabled_repositories,omitempty"` +} + // GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in an organization. // // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-an-organization @@ -306,3 +321,41 @@ func (s *ActionsService) EditArtifactAndLogRetentionPeriodInOrganization(ctx con return s.client.Do(ctx, req, nil) } + +// GetSelfHostedRunnersSettingsInOrganization gets the self-hosted runners permissions settings for repositories in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-self-hosted-runners-settings-for-an-organization +// +//meta:operation GET /orgs/{orgs}/actions/permissions/self-hosted-runners +func (s *ActionsService) GetSelfHostedRunnersSettingsInOrganization(ctx context.Context, org string) (*SelfHostedRunnersSettingsOrganization, *Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners", org) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + settings := new(SelfHostedRunnersSettingsOrganization) + resp, err := s.client.Do(ctx, req, settings) + if err != nil { + return nil, resp, err + } + + return settings, resp, nil +} + +// EditSelfHostedRunnersSettingsInOrganization sets the self-hosted runners permissions settings for repositories in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-self-hosted-runners-settings-for-an-organization +// +//meta:operation PUT /orgs/{org}/actions/permissions/self-hosted-runners +func (s *ActionsService) EditSelfHostedRunnersSettingsInOrganization(ctx context.Context, org string, opt SelfHostedRunnersSettingsOrganizationOpt) (*Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners", org) + + req, err := s.client.NewRequest("PUT", u, opt) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/github/actions_permissions_orgs_test.go b/github/actions_permissions_orgs_test.go index 3f424978b71..b9a30d95a7c 100644 --- a/github/actions_permissions_orgs_test.go +++ b/github/actions_permissions_orgs_test.go @@ -491,3 +491,78 @@ func TestActionsService_EditArtifactAndLogRetentionPeriodInOrganization(t *testi return client.Actions.EditArtifactAndLogRetentionPeriodInOrganization(ctx, "o", *input) }) } + +func TestActionsService_GetSelfHostedRunnersSettingsInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"enabled_repositories": "all", "selected_repositories_url": "https://api.github.com/orgs/octo-org/actions/permissions/self-hosted-runners/repositories"}`) + }) + + ctx := context.Background() + settings, _, err := client.Actions.GetSelfHostedRunnersSettingsInOrganization(ctx, "o") + if err != nil { + t.Errorf("Actions.GetSelfHostedRunnersSettingsInOrganization returned error: %v", err) + } + want := &SelfHostedRunnersSettingsOrganization{ + EnabledRepositories: Ptr("all"), + SelectedRepositoriesUrl: Ptr("https://api.github.com/orgs/octo-org/actions/permissions/self-hosted-runners/repositories"), + } + if !cmp.Equal(settings, want) { + t.Errorf("Actions.GetSelfHostedRunnersSettingsInOrganization returned %+v, want %+v", settings, want) + } + + const methodName = "GetSelfHostedRunnersSettingsInOrganization" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.GetSelfHostedRunnersSettingsInOrganization(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.GetSelfHostedRunnersSettingsInOrganization(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestActionsService_EditSelfHostedRunnersSettingsInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + input := &SelfHostedRunnersSettingsOrganizationOpt{EnabledRepositories: Ptr("selected")} + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) { + v := new(SelfHostedRunnersSettingsOrganizationOpt) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + + testMethod(t, r, "PUT") + if !cmp.Equal(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + resp, err := client.Actions.EditSelfHostedRunnersSettingsInOrganization(ctx, "o", *input) + if err != nil { + t.Errorf("Actions.EditSelfHostedRunnersSettingsInOrganization returned error: %v", err) + } + + if resp.StatusCode != http.StatusNoContent { + t.Errorf("Actions.EditSelfHostedRunnersSettingsInOrganization = %d, want %d", resp.StatusCode, http.StatusNoContent) + } + + const methodName = "EditSelfHostedRunnersSettingsInOrganization" + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.EditSelfHostedRunnersSettingsInOrganization(ctx, "\n", *input) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.EditSelfHostedRunnersSettingsInOrganization(ctx, "o", *input) + }) +} From da970b78d30a6ce13010b840e95fd030552e6092 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 15:44:29 +0900 Subject: [PATCH 6/9] feat: add self-hosted runners for multi repositories settings API for organizations --- github/actions_permissions_orgs.go | 50 +++++++++++++++++ github/actions_permissions_orgs_test.go | 73 +++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/github/actions_permissions_orgs.go b/github/actions_permissions_orgs.go index 95b85600422..8294a0bc5a8 100644 --- a/github/actions_permissions_orgs.go +++ b/github/actions_permissions_orgs.go @@ -359,3 +359,53 @@ func (s *ActionsService) EditSelfHostedRunnersSettingsInOrganization(ctx context return s.client.Do(ctx, req, nil) } + +// SelfHostedRunnersAllowedRepos represents the repositories that are allowed to use self-hosted runners in an organization. +type SelfHostedRunnersAllowedRepos struct { + TotalCount int `json:"total_count"` + Repositories []*Repository `json:"repositories"` +} + +// ListRepositoriesSelfHostedRunnersAllowedInOrganization lists the repositories that are allowed to use self-hosted runners in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#list-repositories-allowed-to-use-self-hosted-runners-in-an-organization +// +//meta:operation GET /orgs/{org}/actions/permissions/self-hosted-runners/repositories +func (s *ActionsService) ListRepositoriesSelfHostedRunnersAllowedInOrganization(ctx context.Context, org string, opts *ListOptions) (*SelfHostedRunnersAllowedRepos, *Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners/repositories", org) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + settings := new(SelfHostedRunnersAllowedRepos) + resp, err := s.client.Do(ctx, req, settings) + if err != nil { + return nil, resp, err + } + + return settings, resp, nil +} + +// SetRepositoriesSelfHostedRunnersAllowedInOrganization allows the list of repositories to use self-hosted runners in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-repositories-allowed-to-use-self-hosted-runners-in-an-organization +// +//meta:operation PUT /orgs/{org}/actions/permissions/self-hosted-runners/repositories +func (s *ActionsService) SetRepositoriesSelfHostedRunnersAllowedInOrganization(ctx context.Context, org string, repositoryIDs []int64) (*Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners/repositories", org) + + req, err := s.client.NewRequest("PUT", u, struct { + IDs []int64 `json:"selected_repository_ids"` + }{IDs: repositoryIDs}) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/github/actions_permissions_orgs_test.go b/github/actions_permissions_orgs_test.go index b9a30d95a7c..b4f8ca25a8d 100644 --- a/github/actions_permissions_orgs_test.go +++ b/github/actions_permissions_orgs_test.go @@ -566,3 +566,76 @@ func TestActionsService_EditSelfHostedRunnersSettingsInOrganization(t *testing.T return client.Actions.EditSelfHostedRunnersSettingsInOrganization(ctx, "o", *input) }) } + +func TestActionsService_ListRepositoriesSelfHostedRunnersAllowedInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners/repositories", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "page": "1", + }) + fmt.Fprint(w, `{"total_count":2,"repositories":[{"id":2}, {"id": 3}]}`) + }) + + ctx := context.Background() + opt := &ListOptions{ + Page: 1, + } + got, _, err := client.Actions.ListRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "o", opt) + if err != nil { + t.Errorf("Actions.ListRepositoriesSelfHostedRunnersAllowedInOrganization returned error: %v", err) + } + + want := &SelfHostedRunnersAllowedRepos{TotalCount: int(2), Repositories: []*Repository{ + {ID: Ptr(int64(2))}, + {ID: Ptr(int64(3))}, + }} + if !cmp.Equal(got, want) { + t.Errorf("Actions.ListRepositoriesSelfHostedRunnersAllowedInOrganization returned %+v, want %+v", got, want) + } + + const methodName = "ListRepositoriesSelfHostedRunnersAllowedInOrganization" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Actions.ListRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "\n", opt) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Actions.ListRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "o", opt) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestActionsService_SetRepositoriesSelfHostedRunnersAllowedInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners/repositories", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Content-Type", "application/json") + testBody(t, r, `{"selected_repository_ids":[123,1234]}`+"\n") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + _, err := client.Actions.SetRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "o", []int64{123, 1234}) + if err != nil { + t.Errorf("Actions.SetRepositoriesSelfHostedRunnersAllowedInOrganization returned error: %v", err) + } + + const methodName = "SetRepositoriesSelfHostedRunnersAllowedInOrganization" + + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.SetRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "\n", []int64{123, 1234}) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.SetRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "o", []int64{123, 1234}) + }) +} From d61693e06e310f8c28fb441a0eaa940cf0046ecd Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 12 Aug 2025 15:56:31 +0900 Subject: [PATCH 7/9] feat: add self-hosted runners for single repository settings API for organizations --- github/actions_permissions_orgs.go | 37 +++++++++++++++++ github/actions_permissions_orgs_test.go | 54 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/github/actions_permissions_orgs.go b/github/actions_permissions_orgs.go index 8294a0bc5a8..0b8942b7e91 100644 --- a/github/actions_permissions_orgs.go +++ b/github/actions_permissions_orgs.go @@ -409,3 +409,40 @@ func (s *ActionsService) SetRepositoriesSelfHostedRunnersAllowedInOrganization(c return s.client.Do(ctx, req, nil) } + +// AddRepositorySelfHostedRunnersAllowedInOrganization adds a repository to the list of repositories that are allowed to use self-hosted runners in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#add-a-repository-to-the-list-of-repositories-allowed-to-use-self-hosted-runners-in-an-organization +// +//meta:operation PUT /orgs/{org}/actions/permissions/self-hosted-runners/repositories/{repository_id} +func (s *ActionsService) AddRepositorySelfHostedRunnersAllowedInOrganization(ctx context.Context, org string, repositoryID int64) (*Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners/repositories/%v", org, repositoryID) + + req, err := s.client.NewRequest("PUT", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// RemoveRepositorySelfHostedRunnersAllowedInOrganization removes a repository from the list of repositories that are allowed to use self-hosted runners in an organization. +// +// GitHub API docs: https://docs.github.com/rest/actions/permissions#remove-a-repository-from-the-list-of-repositories-allowed-to-use-self-hosted-runners-in-an-organization +// +//meta:operation DELETE /orgs/{org}/actions/permissions/self-hosted-runners/repositories/{repository_id} +func (s *ActionsService) RemoveRepositorySelfHostedRunnersAllowedInOrganization(ctx context.Context, org string, repositoryID int64) (*Response, error) { + u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners/repositories/%v", org, repositoryID) + + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} diff --git a/github/actions_permissions_orgs_test.go b/github/actions_permissions_orgs_test.go index b4f8ca25a8d..5a5e31c2bfa 100644 --- a/github/actions_permissions_orgs_test.go +++ b/github/actions_permissions_orgs_test.go @@ -639,3 +639,57 @@ func TestActionsService_SetRepositoriesSelfHostedRunnersAllowedInOrganization(t return client.Actions.SetRepositoriesSelfHostedRunnersAllowedInOrganization(ctx, "o", []int64{123, 1234}) }) } + +func TestActionsService_AddRepositorySelfHostedRunnersAllowedInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners/repositories/123", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + _, err := client.Actions.AddRepositorySelfHostedRunnersAllowedInOrganization(ctx, "o", 123) + if err != nil { + t.Errorf("Actions.AddRepositorySelfHostedRunnersAllowedInOrganization returned error: %v", err) + } + + const methodName = "AddRepositorySelfHostedRunnersAllowedInOrganization" + + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.AddRepositorySelfHostedRunnersAllowedInOrganization(ctx, "\n", 123) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.AddRepositorySelfHostedRunnersAllowedInOrganization(ctx, "o", 123) + }) +} + +func TestActionsService_RemoveRepositorySelfHostedRunnersAllowedInOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners/repositories/123", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + _, err := client.Actions.RemoveRepositorySelfHostedRunnersAllowedInOrganization(ctx, "o", 123) + if err != nil { + t.Errorf("Actions.RemoveRepositorySelfHostedRunnersAllowedInOrganization returned error: %v", err) + } + + const methodName = "RemoveRepositorySelfHostedRunnersAllowedInOrganization" + + testBadOptions(t, methodName, func() (err error) { + _, err = client.Actions.RemoveRepositorySelfHostedRunnersAllowedInOrganization(ctx, "\n", 123) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Actions.RemoveRepositorySelfHostedRunnersAllowedInOrganization(ctx, "o", 123) + }) +} From 3292d569399c1472df59a917eb9c2cd47457ada0 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Wed, 13 Aug 2025 08:55:11 +0900 Subject: [PATCH 8/9] chore: run lint and generate --- github/actions_permissions_orgs.go | 4 +-- github/actions_permissions_orgs_test.go | 2 +- github/github-accessors.go | 32 ++++++++++++++++++ github/github-accessors_test.go | 44 +++++++++++++++++++++++++ github/github-stringify_test.go | 23 +++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) diff --git a/github/actions_permissions_orgs.go b/github/actions_permissions_orgs.go index 27f4b9686e3..f8bd51a08aa 100644 --- a/github/actions_permissions_orgs.go +++ b/github/actions_permissions_orgs.go @@ -53,7 +53,7 @@ type DefaultWorkflowPermissionOrganization struct { // SelfHostedRunnersSettingsOrganization represents the self-hosted runners permissions settings for repositories in an organization. type SelfHostedRunnersSettingsOrganization struct { EnabledRepositories *string `json:"enabled_repositories,omitempty"` - SelectedRepositoriesUrl *string `json:"selected_repositories_url,omitempty"` + SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"` } func (s SelfHostedRunnersSettingsOrganization) String() string { @@ -326,7 +326,7 @@ func (s *ActionsService) EditArtifactAndLogRetentionPeriodInOrganization(ctx con // // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-self-hosted-runners-settings-for-an-organization // -//meta:operation GET /orgs/{orgs}/actions/permissions/self-hosted-runners +//meta:operation GET /orgs/{org}/actions/permissions/self-hosted-runners func (s *ActionsService) GetSelfHostedRunnersSettingsInOrganization(ctx context.Context, org string) (*SelfHostedRunnersSettingsOrganization, *Response, error) { u := fmt.Sprintf("orgs/%v/actions/permissions/self-hosted-runners", org) diff --git a/github/actions_permissions_orgs_test.go b/github/actions_permissions_orgs_test.go index 9217b8c3e82..dbe7eb3a8d7 100644 --- a/github/actions_permissions_orgs_test.go +++ b/github/actions_permissions_orgs_test.go @@ -508,7 +508,7 @@ func TestActionsService_GetSelfHostedRunnersSettingsInOrganization(t *testing.T) } want := &SelfHostedRunnersSettingsOrganization{ EnabledRepositories: Ptr("all"), - SelectedRepositoriesUrl: Ptr("https://api.github.com/orgs/octo-org/actions/permissions/self-hosted-runners/repositories"), + SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/permissions/self-hosted-runners/repositories"), } if !cmp.Equal(settings, want) { t.Errorf("Actions.GetSelfHostedRunnersSettingsInOrganization returned %+v, want %+v", settings, want) diff --git a/github/github-accessors.go b/github/github-accessors.go index 679f7eb7123..b82afb45b81 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -25934,6 +25934,38 @@ func (s *SelectedReposList) GetTotalCount() int { return *s.TotalCount } +// GetEnabledRepositories returns the EnabledRepositories field if it's non-nil, zero value otherwise. +func (s *SelfHostedRunnersSettingsOrganization) GetEnabledRepositories() string { + if s == nil || s.EnabledRepositories == nil { + return "" + } + return *s.EnabledRepositories +} + +// GetSelectedRepositoriesURL returns the SelectedRepositoriesURL field if it's non-nil, zero value otherwise. +func (s *SelfHostedRunnersSettingsOrganization) GetSelectedRepositoriesURL() string { + if s == nil || s.SelectedRepositoriesURL == nil { + return "" + } + return *s.SelectedRepositoriesURL +} + +// GetEnabledRepositories returns the EnabledRepositories field if it's non-nil, zero value otherwise. +func (s *SelfHostedRunnersSettingsOrganizationOpt) GetEnabledRepositories() string { + if s == nil || s.EnabledRepositories == nil { + return "" + } + return *s.EnabledRepositories +} + +// GetDisableSelfHostedRunnersForAllOrgs returns the DisableSelfHostedRunnersForAllOrgs field if it's non-nil, zero value otherwise. +func (s *SelfHostRunnerPermissionsEnterprise) GetDisableSelfHostedRunnersForAllOrgs() bool { + if s == nil || s.DisableSelfHostedRunnersForAllOrgs == nil { + return false + } + return *s.DisableSelfHostedRunnersForAllOrgs +} + // GetFrom returns the From field if it's non-nil, zero value otherwise. func (s *SignatureRequirementEnforcementLevelChanges) GetFrom() string { if s == nil || s.From == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 4a1b298c2af..95870e49ddc 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -33363,6 +33363,50 @@ func TestSelectedReposList_GetTotalCount(tt *testing.T) { s.GetTotalCount() } +func TestSelfHostedRunnersSettingsOrganization_GetEnabledRepositories(tt *testing.T) { + tt.Parallel() + var zeroValue string + s := &SelfHostedRunnersSettingsOrganization{EnabledRepositories: &zeroValue} + s.GetEnabledRepositories() + s = &SelfHostedRunnersSettingsOrganization{} + s.GetEnabledRepositories() + s = nil + s.GetEnabledRepositories() +} + +func TestSelfHostedRunnersSettingsOrganization_GetSelectedRepositoriesURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + s := &SelfHostedRunnersSettingsOrganization{SelectedRepositoriesURL: &zeroValue} + s.GetSelectedRepositoriesURL() + s = &SelfHostedRunnersSettingsOrganization{} + s.GetSelectedRepositoriesURL() + s = nil + s.GetSelectedRepositoriesURL() +} + +func TestSelfHostedRunnersSettingsOrganizationOpt_GetEnabledRepositories(tt *testing.T) { + tt.Parallel() + var zeroValue string + s := &SelfHostedRunnersSettingsOrganizationOpt{EnabledRepositories: &zeroValue} + s.GetEnabledRepositories() + s = &SelfHostedRunnersSettingsOrganizationOpt{} + s.GetEnabledRepositories() + s = nil + s.GetEnabledRepositories() +} + +func TestSelfHostRunnerPermissionsEnterprise_GetDisableSelfHostedRunnersForAllOrgs(tt *testing.T) { + tt.Parallel() + var zeroValue bool + s := &SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs: &zeroValue} + s.GetDisableSelfHostedRunnersForAllOrgs() + s = &SelfHostRunnerPermissionsEnterprise{} + s.GetDisableSelfHostedRunnersForAllOrgs() + s = nil + s.GetDisableSelfHostedRunnersForAllOrgs() +} + func TestSignatureRequirementEnforcementLevelChanges_GetFrom(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index c8fe00a5c1d..abbe7f6b8c0 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -2042,6 +2042,29 @@ func TestSecurityAndAnalysis_String(t *testing.T) { } } +func TestSelfHostRunnerPermissionsEnterprise_String(t *testing.T) { + t.Parallel() + v := SelfHostRunnerPermissionsEnterprise{ + DisableSelfHostedRunnersForAllOrgs: Ptr(false), + } + want := `github.SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs:false}` + if got := v.String(); got != want { + t.Errorf("SelfHostRunnerPermissionsEnterprise.String = %v, want %v", got, want) + } +} + +func TestSelfHostedRunnersSettingsOrganization_String(t *testing.T) { + t.Parallel() + v := SelfHostedRunnersSettingsOrganization{ + EnabledRepositories: Ptr(""), + SelectedRepositoriesURL: Ptr(""), + } + want := `github.SelfHostedRunnersSettingsOrganization{EnabledRepositories:"", SelectedRepositoriesURL:""}` + if got := v.String(); got != want { + t.Errorf("SelfHostedRunnersSettingsOrganization.String = %v, want %v", got, want) + } +} + func TestSourceImportAuthor_String(t *testing.T) { t.Parallel() v := SourceImportAuthor{ From 287224e08a78bde3a13702d076789f7fe5a86e71 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Wed, 13 Aug 2025 09:05:15 +0900 Subject: [PATCH 9/9] docs: fix doc comment --- github/actions_permissions_enterprise.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/actions_permissions_enterprise.go b/github/actions_permissions_enterprise.go index 2f46c9ac720..1334690f474 100644 --- a/github/actions_permissions_enterprise.go +++ b/github/actions_permissions_enterprise.go @@ -324,7 +324,7 @@ func (s *ActionsService) GetSelfHostedRunnerPermissionsInEnterprise(ctx context. return permissions, resp, nil } -// EditSelfHostedRunnerPermissionsInEnterprise gets the self-hosted runner permissions for an enterprise. +// EditSelfHostedRunnerPermissionsInEnterprise sets the self-hosted runner permissions for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#set-self-hosted-runners-permissions-for-an-enterprise //