fix!: Resolve inconsistent options for create and update on custom org role#4075
Conversation
… and `UpdateOrgRoleOptions` with appropriate structs for each operation
create and update operations on custom organization rolecreate and update on custom org role
create and update on custom org rolecreate and update on custom org role
create and update on custom org rolecreate and update on custom org role
create and update on custom org rolecreate and update on custom org role
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4075 +/- ##
=======================================
Coverage 93.65% 93.65%
=======================================
Files 210 210
Lines 19416 19416
=======================================
Hits 18184 18184
Misses 1034 1034
Partials 198 198 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @munlicode!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra
github/orgs_organization_roles.go
Outdated
| // | ||
| //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) { |
There was a problem hiding this comment.
CreateOrgRoleOptions are body parameters, but we typically use the Options suffix for query parameters. Also, a request body is required when creating a custom org role.
Additionally, we are returning a role, not roles.
Therefore, I propose the following renamings:
CreateOrgRoleOptions -> CreateCustomOrgRoleRequest
CustomOrgRoles -> CustomOrgRole
| func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts *CreateOrgRoleOptions) (*CustomOrgRoles, *Response, error) { | |
| func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, request CreateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { |
We're breaking this endpoint anyway, so let’s do it in the best possible way.
There was a problem hiding this comment.
Would it not be confusing to have request and req ?
func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, request CreateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) {
u := fmt.Sprintf("orgs/%v/organization-roles", org)
req, err := s.client.NewRequest("POST", u, request)
...If it is fine, I am ready to rename opts to request.
There was a problem hiding this comment.
We can call it Body, but that would require significant refactoring.
And the Request prefix is common across the code base:
Line 2324 in 09946e5
go-github/github/actions_runners.go
Line 87 in 09946e5
There was a problem hiding this comment.
The parameter name can be simply create instead of request.
github/orgs_organization_roles.go
Outdated
| // | ||
| //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) { |
There was a problem hiding this comment.
Same as above:
| func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, opts *UpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) { | |
| func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, request UpdateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { |
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
BREAKING CHANGE:
CreateCustomOrgRoleandUpdateCustomOrgRolenow take their own options.CreateCustomOrgRoleandUpdateCustomOrgRoleintoCreateOrgRoleOptionsandUpdateOrgRoleOptions.namerequired option on create operation.Fixes: #4074.