Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

// EditPrivateRepoForkPRWorkflowSettingsInEnterprise 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) EditPrivateRepoForkPRWorkflowSettingsInEnterprise(ctx context.Context, enterprise string, permissions WorkflowsPermissions) (*Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the doc, the body parameter run_workflows_from_fork_pull_requests is required. So, we can't reuse WorkflowsPermissions here because RunWorkflowsFromForkPullRequests has a pointer type *bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I use a mixture of pointer and non-pointer fileds to address that. Thanks for your review!

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)
}
82 changes: 82 additions & 0 deletions github/actions_permissions_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,85 @@ 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_EditPrivateRepoForkPRWorkflowSettingsInEnterprise(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestActionsService_EditPrivateRepoForkPRWorkflowSettingsInEnterprise(t *testing.T) {
func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(t *testing.T) {

t.Parallel()
client, mux, _ := setup(t)

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

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

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

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

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.EditPrivateRepoForkPRWorkflowSettingsInEnterprise(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
}

// EditPrivateRepoForkPRWorkflowSettingsInOrganization 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) EditPrivateRepoForkPRWorkflowSettingsInOrganization(ctx context.Context, org string, permissions WorkflowsPermissions) (*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)
}
82 changes: 82 additions & 0 deletions github/actions_permissions_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,85 @@ 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_EditPrivateRepoForkPRWorkflowSettingsInOrganization(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestActionsService_EditPrivateRepoForkPRWorkflowSettingsInOrganization(t *testing.T) {
func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I fix it. Thank you!

t.Parallel()
client, mux, _ := setup(t)

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

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

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

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

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Actions.EditPrivateRepoForkPRWorkflowSettingsInOrganization(ctx, "o", *input)
})
}
12 changes: 12 additions & 0 deletions github/actions_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ 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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RequireApprovalForForkPrWorkflows *bool `json:"require_approval_for_fork_pr_workflows,omitempty"`
RequireApprovalForForkPRWorkflows *bool `json:"require_approval_for_fork_pr_workflows,omitempty"`

}

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

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

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

44 changes: 44 additions & 0 deletions github/github-accessors_test.go

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

14 changes: 14 additions & 0 deletions github/github-stringify_test.go

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

Loading
Loading