Skip to content
37 changes: 37 additions & 0 deletions github/actions_permissions_enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,40 @@ func (s *ActionsService) EditSelfHostedRunnerPermissionsInEnterprise(ctx context

return s.client.Do(ctx, req, nil)
}

// GetPrivateRepoForkPRWorkflowSettingsInEnterprise gets the settings for whether workflows from fork pull requests can run on private repositories in an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#get-private-repo-fork-pr-workflow-settings-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/actions/permissions/fork-pr-workflows-private-repos
func (s *ActionsService) GetPrivateRepoForkPRWorkflowSettingsInEnterprise(ctx context.Context, enterprise string) (*WorkflowsPermissions, *Response, error) {
u := fmt.Sprintf("enterprises/%v/actions/permissions/fork-pr-workflows-private-repos", enterprise)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

permissions := new(WorkflowsPermissions)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}

return permissions, resp, nil
}

// UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise sets the settings for whether workflows from fork pull requests can run on private repositories in an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/actions/permissions#set-private-repo-fork-pr-workflow-settings-for-an-enterprise
//
//meta:operation PUT /enterprises/{enterprise}/actions/permissions/fork-pr-workflows-private-repos
func (s *ActionsService) UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(ctx context.Context, enterprise string, permissions *WorkflowsPermissionsOpt) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/actions/permissions/fork-pr-workflows-private-repos", enterprise)
req, err := s.client.NewRequest("PUT", u, permissions)
if err != nil {
return nil, err
}

return s.client.Do(ctx, req, nil)
}
81 changes: 81 additions & 0 deletions github/actions_permissions_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,84 @@ func TestActionsService_EditSelfHostedRunnerPermissionsInEnterprise(t *testing.T
return client.Actions.EditSelfHostedRunnerPermissionsInEnterprise(ctx, "e", *input)
})
}

func TestActionsService_GetPrivateRepoForkPRWorkflowSettingsInEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"run_workflows_from_fork_pull_requests": true, "send_write_tokens_to_workflows": false, "send_secrets_and_variables": true, "require_approval_for_fork_pr_workflows": false}`)
})

ctx := context.Background()
permissions, _, err := client.Actions.GetPrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "e")
if err != nil {
t.Errorf("Actions.GetPrivateRepoForkPRWorkflowSettingsInEnterprise returned error: %v", err)
}
want := &WorkflowsPermissions{
RunWorkflowsFromForkPullRequests: Ptr(true),
SendWriteTokensToWorkflows: Ptr(false),
SendSecretsAndVariables: Ptr(true),
RequireApprovalForForkPRWorkflows: Ptr(false),
}
if !cmp.Equal(permissions, want) {
t.Errorf("Actions.GetPrivateRepoForkPRWorkflowSettingsInEnterprise returned %+v, want %+v", permissions, want)
}

const methodName = "GetPrivateRepoForkPRWorkflowSettingsInEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetPrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetPrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "e")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &WorkflowsPermissionsOpt{
RunWorkflowsFromForkPullRequests: true,
SendWriteTokensToWorkflows: Ptr(false),
SendSecretsAndVariables: Ptr(true),
}

mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
v := new(WorkflowsPermissionsOpt)
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.UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "e", input)
if err != nil {
t.Errorf("Actions.UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise returned error: %v", err)
}

if resp.StatusCode != http.StatusNoContent {
t.Errorf("Actions.UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise = %d, want %d", resp.StatusCode, http.StatusNoContent)
}

const methodName = "UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "\n", input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(ctx, "e", input)
})
}
37 changes: 37 additions & 0 deletions github/actions_permissions_orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,40 @@ func (s *ActionsService) RemoveRepositorySelfHostedRunnersAllowedInOrganization(

return resp, nil
}

// GetPrivateRepoForkPRWorkflowSettingsInOrganization gets the settings for whether workflows from fork pull requests can run on private repositories in an organization.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-private-repo-fork-pr-workflow-settings-for-an-organization
//
//meta:operation GET /orgs/{org}/actions/permissions/fork-pr-workflows-private-repos
func (s *ActionsService) GetPrivateRepoForkPRWorkflowSettingsInOrganization(ctx context.Context, org string) (*WorkflowsPermissions, *Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/fork-pr-workflows-private-repos", org)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

permissions := new(WorkflowsPermissions)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}

return permissions, resp, nil
}

// UpdatePrivateRepoForkPRWorkflowSettingsInOrganization sets the settings for whether workflows from fork pull requests can run on private repositories in an organization.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-private-repo-fork-pr-workflow-settings-for-an-organization
//
//meta:operation PUT /orgs/{org}/actions/permissions/fork-pr-workflows-private-repos
func (s *ActionsService) UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(ctx context.Context, org string, permissions *WorkflowsPermissionsOpt) (*Response, error) {
u := fmt.Sprintf("orgs/%v/actions/permissions/fork-pr-workflows-private-repos", org)
req, err := s.client.NewRequest("PUT", u, permissions)
if err != nil {
return nil, err
}

return s.client.Do(ctx, req, nil)
}
81 changes: 81 additions & 0 deletions github/actions_permissions_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,84 @@ func TestActionsService_RemoveRepositorySelfHostedRunnersAllowedInOrganization(t
return client.Actions.RemoveRepositorySelfHostedRunnersAllowedInOrganization(ctx, "o", 123)
})
}

func TestActionsService_GetPrivateRepoForkPRWorkflowSettingsInOrganization(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"run_workflows_from_fork_pull_requests": true, "send_write_tokens_to_workflows": false, "send_secrets_and_variables": true, "require_approval_for_fork_pr_workflows": false}`)
})

ctx := context.Background()
permissions, _, err := client.Actions.GetPrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "o")
if err != nil {
t.Errorf("Actions.GetPrivateRepoForkPRWorkflowSettingsInOrganization returned error: %v", err)
}
want := &WorkflowsPermissions{
RunWorkflowsFromForkPullRequests: Ptr(true),
SendWriteTokensToWorkflows: Ptr(false),
SendSecretsAndVariables: Ptr(true),
RequireApprovalForForkPRWorkflows: Ptr(false),
}
if !cmp.Equal(permissions, want) {
t.Errorf("Actions.GetPrivateRepoForkPRWorkflowSettingsInOrganization returned %+v, want %+v", permissions, want)
}

const methodName = "GetPrivateRepoForkPRWorkflowSettingsInOrganization"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Actions.GetPrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "\n")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Actions.GetPrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "o")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &WorkflowsPermissionsOpt{
RunWorkflowsFromForkPullRequests: true,
SendWriteTokensToWorkflows: Ptr(false),
SendSecretsAndVariables: Ptr(true),
}

mux.HandleFunc("/orgs/o/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
v := new(WorkflowsPermissionsOpt)
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.UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "o", input)
if err != nil {
t.Errorf("Actions.UpdatePrivateRepoForkPRWorkflowSettingsInOrganization returned error: %v", err)
}

if resp.StatusCode != http.StatusNoContent {
t.Errorf("Actions.UpdatePrivateRepoForkPRWorkflowSettingsInOrganization = %d, want %d", resp.StatusCode, http.StatusNoContent)
}

const methodName = "UpdatePrivateRepoForkPRWorkflowSettingsInOrganization"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "\n", input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "o", input)
})
}
20 changes: 20 additions & 0 deletions github/actions_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ type CreateWorkflowDispatchEventRequest struct {
Inputs map[string]any `json:"inputs,omitempty"`
}

// WorkflowsPermissions represents the permissions for workflows in a repository.
type WorkflowsPermissions struct {
RunWorkflowsFromForkPullRequests *bool `json:"run_workflows_from_fork_pull_requests,omitempty"`
SendWriteTokensToWorkflows *bool `json:"send_write_tokens_to_workflows,omitempty"`
SendSecretsAndVariables *bool `json:"send_secrets_and_variables,omitempty"`
RequireApprovalForForkPRWorkflows *bool `json:"require_approval_for_fork_pr_workflows,omitempty"`
}

func (w WorkflowsPermissions) String() string {
return Stringify(w)
}

// WorkflowsPermissionsOpt specifies options for editing workflows permissions in a repository.
type WorkflowsPermissionsOpt struct {
RunWorkflowsFromForkPullRequests bool `json:"run_workflows_from_fork_pull_requests"`
SendWriteTokensToWorkflows *bool `json:"send_write_tokens_to_workflows,omitempty"`
SendSecretsAndVariables *bool `json:"send_secrets_and_variables,omitempty"`
RequireApprovalForForkPRWorkflows *bool `json:"require_approval_for_fork_pr_workflows,omitempty"`
}

// ListWorkflows lists all workflows in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/workflows#list-repository-workflows
Expand Down
56 changes: 56 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading