Skip to content

Commit

Permalink
Allow create custom repository/organization roles without permissions #…
Browse files Browse the repository at this point in the history
…3226

Signed-off-by: Andríyun <[email protected]>
  • Loading branch information
Andríyun committed Aug 13, 2024
1 parent f5d2850 commit f0a9d4d
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 74 deletions.
92 changes: 66 additions & 26 deletions github/github-accessors.go

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

122 changes: 86 additions & 36 deletions github/github-accessors_test.go

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

31 changes: 23 additions & 8 deletions github/orgs_custom_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,30 @@ type CustomRepoRoles struct {
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
}

// CreateOrUpdateOrgRoleOptions represents options required to create or update a custom organization role.
type CreateOrUpdateOrgRoleOptions struct {
// CreateOrgRoleOptions represents options required to create a custom organization role.
type CreateOrgRoleOptions struct {
Name *string `json:"name"`
Description *string `json:"description"`
Permissions []string `json:"permissions"`
}

// UpdateOrgRoleOptions represents options used to update a custom organization role.
type UpdateOrgRoleOptions struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}

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

// UpdateCustomRepoRoleOptions represents options used to update a custom repository role.
type UpdateCustomRepoRoleOptions struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
BaseRole *string `json:"base_role,omitempty"`
Expand Down Expand Up @@ -93,7 +108,7 @@ func (s *OrganizationsService) ListRoles(ctx context.Context, org string) (*Orga
// GitHub API docs: https://docs.github.com/rest/orgs/organization-roles#create-a-custom-organization-role
//
//meta:operation POST /orgs/{org}/organization-roles
func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts *CreateOrUpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts *CreateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/organization-roles", org)

req, err := s.client.NewRequest("POST", u, opts)
Expand All @@ -116,7 +131,7 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri
// GitHub API docs: https://docs.github.com/rest/orgs/organization-roles#update-a-custom-organization-role
//
//meta:operation PATCH /orgs/{org}/organization-roles/{role_id}
func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, opts *CreateOrUpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, opts *UpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/organization-roles/%v", org, roleID)

req, err := s.client.NewRequest("PATCH", u, opts)
Expand Down Expand Up @@ -185,7 +200,7 @@ func (s *OrganizationsService) ListCustomRepoRoles(ctx context.Context, org stri
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/custom-roles#create-a-custom-repository-role
//
//meta:operation POST /orgs/{org}/custom-repository-roles
func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org string, opts *CreateOrUpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org string, opts *CreateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom-repository-roles", org)

req, err := s.client.NewRequest("POST", u, opts)
Expand All @@ -208,7 +223,7 @@ func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org str
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/custom-roles#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, opts *CreateOrUpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID int64, opts *UpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
u := fmt.Sprintf("orgs/%v/custom-repository-roles/%v", org, roleID)

req, err := s.client.NewRequest("PATCH", u, opts)
Expand Down
8 changes: 4 additions & 4 deletions github/orgs_custom_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) {

ctx := context.Background()

opts := &CreateOrUpdateOrgRoleOptions{
opts := &CreateOrgRoleOptions{
Name: String("Reader"),
Description: String("A role for reading custom org roles"),
Permissions: []string{"read_organization_custom_org_role"},
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestOrganizationsService_UpdateCustomOrgRole(t *testing.T) {

ctx := context.Background()

opts := &CreateOrUpdateOrgRoleOptions{
opts := &UpdateOrgRoleOptions{
Name: String("Updated Name"),
Description: String("Updated Description"),
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestOrganizationsService_CreateCustomRepoRole(t *testing.T) {

ctx := context.Background()

opts := &CreateOrUpdateCustomRepoRoleOptions{
opts := &CreateCustomRepoRoleOptions{
Name: String("Labeler"),
Description: String("A role for issue and PR labelers"),
BaseRole: String("read"),
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestOrganizationsService_UpdateCustomRepoRole(t *testing.T) {

ctx := context.Background()

opts := &CreateOrUpdateCustomRepoRoleOptions{
opts := &UpdateCustomRepoRoleOptions{
Name: String("Updated Name"),
Description: String("Updated Description"),
}
Expand Down

0 comments on commit f0a9d4d

Please sign in to comment.