Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ linters:
- ConfigApplyOptions
- ConfigSettings
- CreateCodespaceOptions
- CreateOrUpdateCustomRepoRoleOptions
- CreateOrUpdateIssueTypesOptions
- CreateOrgInvitationOptions
- CreateUpdateEnvironment
Expand Down Expand Up @@ -281,7 +280,6 @@ linters:
- CreateCheckRunOptions
- CreateCheckSuiteOptions
- CreateCodespaceOptions
- CreateOrUpdateCustomRepoRoleOptions
- CreateOrUpdateIssueTypesOptions
- CreateOrgInvitationOptions
- ImpersonateUserOptions
Expand Down
96 changes: 64 additions & 32 deletions github/github-accessors.go

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

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

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

18 changes: 13 additions & 5 deletions github/orgs_custom_repository_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ type CustomRepoRoles struct {
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
}

// CreateOrUpdateCustomRepoRoleOptions represents options required to create or update a custom repository role.
type CreateOrUpdateCustomRepoRoleOptions struct {
// CreateCustomRepoRoleRequest represents the parameters to create a custom repository role.
type CreateCustomRepoRoleRequest struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
BaseRole string `json:"base_role"`
Permissions []string `json:"permissions"`
}

// UpdateCustomRepoRoleRequest represents the parameters to update a custom repository role.
type UpdateCustomRepoRoleRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
Permissions []string `json:"permissions"`
Permissions []string `json:"permissions,omitzero"`
}

// RepoFineGrainedPermission represents a fine-grained permission that can be used in a custom repository role.
Expand Down Expand Up @@ -96,7 +104,7 @@ func (s *OrganizationsService) GetCustomRepoRole(ctx context.Context, org string
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/custom-roles?apiVersion=2022-11-28#create-a-custom-repository-role
//
//meta:operation POST /orgs/{org}/custom-repository-roles
func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org string, body *CreateOrUpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org string, body CreateCustomRepoRoleRequest) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom-repository-roles", org)

req, err := s.client.NewRequest(ctx, "POST", u, body)
Expand All @@ -119,7 +127,7 @@ func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org str
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/custom-roles?apiVersion=2022-11-28#update-a-custom-repository-role
//
//meta:operation PATCH /orgs/{org}/custom-repository-roles/{role_id}
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID int64, body *CreateOrUpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID int64, body UpdateCustomRepoRoleRequest) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom-repository-roles/%v", org, roleID)

req, err := s.client.NewRequest(ctx, "PATCH", u, body)
Expand Down
20 changes: 10 additions & 10 deletions github/orgs_custom_repository_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ func TestOrganizationsService_CreateCustomRepoRole(t *testing.T) {

ctx := t.Context()

opts := &CreateOrUpdateCustomRepoRoleOptions{
Name: Ptr("Labeler"),
body := CreateCustomRepoRoleRequest{
Name: "Labeler",
Description: Ptr("A role for issue and PR labelers"),
BaseRole: Ptr("read"),
BaseRole: "read",
Permissions: []string{"add_label"},
}
apps, _, err := client.Organizations.CreateCustomRepoRole(ctx, "o", opts)
apps, _, err := client.Organizations.CreateCustomRepoRole(ctx, "o", body)
if err != nil {
t.Errorf("Organizations.CreateCustomRepoRole returned error: %v", err)
}
Expand All @@ -202,12 +202,12 @@ func TestOrganizationsService_CreateCustomRepoRole(t *testing.T) {

const methodName = "CreateCustomRepoRole"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.CreateCustomRepoRole(ctx, "\no", nil)
_, _, err = client.Organizations.CreateCustomRepoRole(ctx, "\no", CreateCustomRepoRoleRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.CreateCustomRepoRole(ctx, "o", nil)
got, resp, err := client.Organizations.CreateCustomRepoRole(ctx, "o", CreateCustomRepoRoleRequest{})
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand All @@ -226,11 +226,11 @@ func TestOrganizationsService_UpdateCustomRepoRole(t *testing.T) {

ctx := t.Context()

opts := &CreateOrUpdateCustomRepoRoleOptions{
body := UpdateCustomRepoRoleRequest{
Name: Ptr("Updated Name"),
Description: Ptr("Updated Description"),
}
apps, _, err := client.Organizations.UpdateCustomRepoRole(ctx, "o", 8030, opts)
apps, _, err := client.Organizations.UpdateCustomRepoRole(ctx, "o", 8030, body)
if err != nil {
t.Errorf("Organizations.UpdateCustomRepoRole returned error: %v", err)
}
Expand All @@ -243,12 +243,12 @@ func TestOrganizationsService_UpdateCustomRepoRole(t *testing.T) {

const methodName = "UpdateCustomRepoRole"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.UpdateCustomRepoRole(ctx, "\no", 8030, nil)
_, _, err = client.Organizations.UpdateCustomRepoRole(ctx, "\no", 8030, UpdateCustomRepoRoleRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.UpdateCustomRepoRole(ctx, "o", 8030, nil)
got, resp, err := client.Organizations.UpdateCustomRepoRole(ctx, "o", 8030, UpdateCustomRepoRoleRequest{})
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
Loading