Skip to content

Commit f0a9d4d

Browse files
author
Andríyun
committed
Allow create custom repository/organization roles without permissions #3226
Signed-off-by: Andríyun <[email protected]>
1 parent f5d2850 commit f0a9d4d

File tree

4 files changed

+179
-74
lines changed

4 files changed

+179
-74
lines changed

github/github-accessors.go

+66-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

+86-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/orgs_custom_roles.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,30 @@ type CustomRepoRoles struct {
4949
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
5050
}
5151

52-
// CreateOrUpdateOrgRoleOptions represents options required to create or update a custom organization role.
53-
type CreateOrUpdateOrgRoleOptions struct {
52+
// CreateOrgRoleOptions represents options required to create a custom organization role.
53+
type CreateOrgRoleOptions struct {
54+
Name *string `json:"name"`
55+
Description *string `json:"description"`
56+
Permissions []string `json:"permissions"`
57+
}
58+
59+
// UpdateOrgRoleOptions represents options used to update a custom organization role.
60+
type UpdateOrgRoleOptions struct {
5461
Name *string `json:"name,omitempty"`
5562
Description *string `json:"description,omitempty"`
5663
Permissions []string `json:"permissions,omitempty"`
5764
}
5865

59-
// CreateOrUpdateCustomRepoRoleOptions represents options required to create or update a custom repository role.
60-
type CreateOrUpdateCustomRepoRoleOptions struct {
66+
// CreateCustomRepoRoleOptions represents options required to create a custom repository role.
67+
type CreateCustomRepoRoleOptions struct {
68+
Name *string `json:"name"`
69+
Description *string `json:"description"`
70+
BaseRole *string `json:"base_role"`
71+
Permissions []string `json:"permissions"`
72+
}
73+
74+
// UpdateCustomRepoRoleOptions represents options used to update a custom repository role.
75+
type UpdateCustomRepoRoleOptions struct {
6176
Name *string `json:"name,omitempty"`
6277
Description *string `json:"description,omitempty"`
6378
BaseRole *string `json:"base_role,omitempty"`
@@ -93,7 +108,7 @@ func (s *OrganizationsService) ListRoles(ctx context.Context, org string) (*Orga
93108
// GitHub API docs: https://docs.github.com/rest/orgs/organization-roles#create-a-custom-organization-role
94109
//
95110
//meta:operation POST /orgs/{org}/organization-roles
96-
func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts *CreateOrUpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
111+
func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts *CreateOrgRoleOptions) (*CustomOrgRoles, *Response, error) {
97112
u := fmt.Sprintf("orgs/%v/organization-roles", org)
98113

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

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

191206
req, err := s.client.NewRequest("POST", u, opts)
@@ -208,7 +223,7 @@ func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org str
208223
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/custom-roles#update-a-custom-repository-role
209224
//
210225
//meta:operation PATCH /orgs/{org}/custom-repository-roles/{role_id}
211-
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID int64, opts *CreateOrUpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
226+
func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org string, roleID int64, opts *UpdateCustomRepoRoleOptions) (*CustomRepoRoles, *Response, error) {
212227
u := fmt.Sprintf("orgs/%v/custom-repository-roles/%v", org, roleID)
213228

214229
req, err := s.client.NewRequest("PATCH", u, opts)

github/orgs_custom_roles_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) {
109109

110110
ctx := context.Background()
111111

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

152152
ctx := context.Background()
153153

154-
opts := &CreateOrUpdateOrgRoleOptions{
154+
opts := &UpdateOrgRoleOptions{
155155
Name: String("Updated Name"),
156156
Description: String("Updated Description"),
157157
}
@@ -304,7 +304,7 @@ func TestOrganizationsService_CreateCustomRepoRole(t *testing.T) {
304304

305305
ctx := context.Background()
306306

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

348348
ctx := context.Background()
349349

350-
opts := &CreateOrUpdateCustomRepoRoleOptions{
350+
opts := &UpdateCustomRepoRoleOptions{
351351
Name: String("Updated Name"),
352352
Description: String("Updated Description"),
353353
}

0 commit comments

Comments
 (0)