+
Skip to content
Merged
45 changes: 45 additions & 0 deletions github/actions_permissions_enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ 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"`
}

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
Expand Down Expand Up @@ -293,3 +302,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 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
//
//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)
}
72 changes: 72 additions & 0 deletions github/actions_permissions_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
140 changes: 140 additions & 0 deletions github/actions_permissions_orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -306,3 +321,128 @@ 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/{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)

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)
}

// 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)
}

// 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
}
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载