Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make requested changes
  • Loading branch information
mohaldu committed Oct 16, 2022
commit 4ccbae5b8940b87af7de6a6546760a1c7eca4a37
36 changes: 18 additions & 18 deletions github/orgs_custom_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type OrganizationCustomRepoRoles struct {
// See https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization
// for more information.
type CustomRepoRoles struct {
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
Permissions *[]string `json:"permissions,omitempty"`
ID *int64 `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}

// ListCustomRepoRoles lists the custom repository roles available in this organization.
Expand All @@ -48,15 +48,15 @@ func (s *OrganizationsService) ListCustomRepoRoles(ctx context.Context, org stri
return customRepoRoles, resp, nil
}

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

// CreateCustomRepoRole creates a custom repository role in this organization
// CreateCustomRepoRole creates a custom repository role in this organization.
// In order to create custom repository roles in an organization, the authenticated user must be an organization owner.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/custom-roles#create-a-custom-role
Expand All @@ -77,12 +77,12 @@ func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org str
return resultingRole, resp, err
}

// CreateCustomRepoRole creates a custom repository role in this organization
// UpdateCustomRepoRole creates a custom repository role in this organization.
// In order to update custom repository roles in an organization, the authenticated user must be an organization owner.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/custom-roles#update-a-custom-role
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID string, opts *CreateOrUpdateCustomRoleOptions) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom_roles/%v", org, roleId)
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org, roleID string, opts *CreateOrUpdateCustomRoleOptions) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom_roles/%v", org, roleID)

req, err := s.client.NewRequest("PATCH", u, opts)
if err != nil {
Expand All @@ -98,12 +98,12 @@ func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org str
return resultingRole, resp, err
}

// DeleteCustomRepoRole deletes an existing custom repository role in this organization
// DeleteCustomRepoRole deletes an existing custom repository role in this organization.
// In order to delete custom repository roles in an organization, the authenticated user must be an organization owner.
//
// GitHub API docs: https://docs.github.com/en/rest/orgs/custom-roles#delete-a-custom-role
func (s *OrganizationsService) DeleteCustomRepoRole(ctx context.Context, org string, roleID string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/custom_roles/%v", org, roleId)
func (s *OrganizationsService) DeleteCustomRepoRole(ctx context.Context, org, roleID string) (*Response, error) {
u := fmt.Sprintf("orgs/%v/custom_roles/%v", org, roleID)

req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
Expand All @@ -116,5 +116,5 @@ func (s *OrganizationsService) DeleteCustomRepoRole(ctx context.Context, org str
return resp, err
}

return resp, err
return resp, nil
}
8 changes: 4 additions & 4 deletions github/orgs_custom_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestOrganizationsService_ListCustomRepoRoles(t *testing.T) {
t.Errorf("Organizations.ListCustomRepoRoles returned error: %v", err)
}

want := &OrganizationCustomRepoRoles{TotalCount: Int(1), CustomRepoRoles: []*CustomRepoRoles{{ID: Int64(1), Name: String("Developer"), BaseRole: String("write"), Permissions: &[]string{"delete_alerts_code_scanning"}}}}
want := &OrganizationCustomRepoRoles{TotalCount: Int(1), CustomRepoRoles: []*CustomRepoRoles{{ID: Int64(1), Name: String("Developer"), BaseRole: String("write"), Permissions: []string{"delete_alerts_code_scanning"}}}}
if !cmp.Equal(apps, want) {
t.Errorf("Organizations.ListCustomRepoRoles returned %+v, want %+v", apps, want)
}
Expand Down Expand Up @@ -64,14 +64,14 @@ func TestOrganizationsService_CreateCustomRepoRole(t *testing.T) {
Name: String("Labeler"),
Description: String("A role for issue and PR labelers"),
BaseRole: String("read"),
Permissions: &[]string{"add_label"},
Permissions: []string{"add_label"},
}
apps, _, err := client.Organizations.CreateCustomRepoRole(ctx, "o", opts)
if err != nil {
t.Errorf("Organizations.CreateCustomRepoRole returned error: %v", err)
}

want := &CustomRepoRoles{ID: Int64(8030), Name: String("Labeler"), BaseRole: String("read"), Permissions: &[]string{"add_label"}, Description: String("A role for issue and PR labelers")}
want := &CustomRepoRoles{ID: Int64(8030), Name: String("Labeler"), BaseRole: String("read"), Permissions: []string{"add_label"}, Description: String("A role for issue and PR labelers")}

if !cmp.Equal(apps, want) {
t.Errorf("Organizations.CreateCustomRepoRole returned %+v, want %+v", apps, want)
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestOrganizationsService_UpdateCustomRepoRole(t *testing.T) {
t.Errorf("Organizations.UpdateCustomRepoRole returned error: %v", err)
}

want := &CustomRepoRoles{ID: Int64(8030), Name: String("Updated Name"), BaseRole: String("read"), Permissions: &[]string{"add_label"}, Description: String("Updated Description")}
want := &CustomRepoRoles{ID: Int64(8030), Name: String("Updated Name"), BaseRole: String("read"), Permissions: []string{"add_label"}, Description: String("Updated Description")}

if !cmp.Equal(apps, want) {
t.Errorf("Organizations.UpdateCustomRepoRole returned %+v, want %+v", apps, want)
Expand Down