From 29d72872e442d6c27fa32a7d18b1cffae1f3d950 Mon Sep 17 00:00:00 2001 From: munlicode Date: Mon, 9 Mar 2026 18:40:37 +0500 Subject: [PATCH 1/6] fix: Split `CreateOrUpdateOrgRoleOptions` into `CreateOrgRoleOptions` and `UpdateOrgRoleOptions` with appropriate structs for each operation --- github/github-accessors.go | 64 ++++++++++++------- github/github-accessors_test.go | 88 ++++++++++++++++---------- github/orgs_organization_roles.go | 18 ++++-- github/orgs_organization_roles_test.go | 8 +-- 4 files changed, 112 insertions(+), 66 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index aa52b9ae260..18aef8c33a4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -7014,6 +7014,22 @@ func (c *CreateOrgInvitationOptions) GetRole() string { return *c.Role } +// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. +func (c *CreateOrgRoleOptions) GetBaseRole() string { + if c == nil || c.BaseRole == nil { + return "" + } + return *c.BaseRole +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (c *CreateOrgRoleOptions) GetDescription() string { + if c == nil || c.Description == nil { + return "" + } + return *c.Description +} + // GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. func (c *CreateOrUpdateCustomRepoRoleOptions) GetBaseRole() string { if c == nil || c.BaseRole == nil { @@ -7062,30 +7078,6 @@ func (c *CreateOrUpdateIssueTypesOptions) GetIsPrivate() bool { return *c.IsPrivate } -// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. -func (c *CreateOrUpdateOrgRoleOptions) GetBaseRole() string { - if c == nil || c.BaseRole == nil { - return "" - } - return *c.BaseRole -} - -// GetDescription returns the Description field if it's non-nil, zero value otherwise. -func (c *CreateOrUpdateOrgRoleOptions) GetDescription() string { - if c == nil || c.Description == nil { - return "" - } - return *c.Description -} - -// GetName returns the Name field if it's non-nil, zero value otherwise. -func (c *CreateOrUpdateOrgRoleOptions) GetName() string { - if c == nil || c.Name == nil { - return "" - } - return *c.Name -} - // GetFrom returns the From field if it's non-nil, zero value otherwise. func (c *CreateProtectedChanges) GetFrom() bool { if c == nil || c.From == nil { @@ -30646,6 +30638,30 @@ func (u *UpdateOrganizationPrivateRegistry) GetVisibility() *PrivateRegistryVisi return u.Visibility } +// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. +func (u *UpdateOrgRoleOptions) GetBaseRole() string { + if u == nil || u.BaseRole == nil { + return "" + } + return *u.BaseRole +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (u *UpdateOrgRoleOptions) GetDescription() string { + if u == nil || u.Description == nil { + return "" + } + return *u.Description +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (u *UpdateOrgRoleOptions) GetName() string { + if u == nil || u.Name == nil { + return "" + } + return *u.Name +} + // GetArchived returns the Archived field if it's non-nil, zero value otherwise. func (u *UpdateProjectItemOptions) GetArchived() bool { if u == nil || u.Archived == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 037406b83d6..4c6090ca40f 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -9178,6 +9178,28 @@ func TestCreateOrgInvitationOptions_GetRole(tt *testing.T) { c.GetRole() } +func TestCreateOrgRoleOptions_GetBaseRole(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateOrgRoleOptions{BaseRole: &zeroValue} + c.GetBaseRole() + c = &CreateOrgRoleOptions{} + c.GetBaseRole() + c = nil + c.GetBaseRole() +} + +func TestCreateOrgRoleOptions_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateOrgRoleOptions{Description: &zeroValue} + c.GetDescription() + c = &CreateOrgRoleOptions{} + c.GetDescription() + c = nil + c.GetDescription() +} + func TestCreateOrUpdateCustomRepoRoleOptions_GetBaseRole(tt *testing.T) { tt.Parallel() var zeroValue string @@ -9244,39 +9266,6 @@ func TestCreateOrUpdateIssueTypesOptions_GetIsPrivate(tt *testing.T) { c.GetIsPrivate() } -func TestCreateOrUpdateOrgRoleOptions_GetBaseRole(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CreateOrUpdateOrgRoleOptions{BaseRole: &zeroValue} - c.GetBaseRole() - c = &CreateOrUpdateOrgRoleOptions{} - c.GetBaseRole() - c = nil - c.GetBaseRole() -} - -func TestCreateOrUpdateOrgRoleOptions_GetDescription(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CreateOrUpdateOrgRoleOptions{Description: &zeroValue} - c.GetDescription() - c = &CreateOrUpdateOrgRoleOptions{} - c.GetDescription() - c = nil - c.GetDescription() -} - -func TestCreateOrUpdateOrgRoleOptions_GetName(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CreateOrUpdateOrgRoleOptions{Name: &zeroValue} - c.GetName() - c = &CreateOrUpdateOrgRoleOptions{} - c.GetName() - c = nil - c.GetName() -} - func TestCreateProtectedChanges_GetFrom(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -39524,6 +39513,39 @@ func TestUpdateOrganizationPrivateRegistry_GetVisibility(tt *testing.T) { u.GetVisibility() } +func TestUpdateOrgRoleOptions_GetBaseRole(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateOrgRoleOptions{BaseRole: &zeroValue} + u.GetBaseRole() + u = &UpdateOrgRoleOptions{} + u.GetBaseRole() + u = nil + u.GetBaseRole() +} + +func TestUpdateOrgRoleOptions_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateOrgRoleOptions{Description: &zeroValue} + u.GetDescription() + u = &UpdateOrgRoleOptions{} + u.GetDescription() + u = nil + u.GetDescription() +} + +func TestUpdateOrgRoleOptions_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateOrgRoleOptions{Name: &zeroValue} + u.GetName() + u = &UpdateOrgRoleOptions{} + u.GetName() + u = nil + u.GetName() +} + func TestUpdateProjectItemOptions_GetArchived(tt *testing.T) { tt.Parallel() var zeroValue bool diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 0954b92d41b..5198e40f1e5 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -29,11 +29,19 @@ type CustomOrgRoles struct { BaseRole *string `json:"base_role,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"` + Permissions []string `json:"permissions"` + Description *string `json:"description,omitempty"` + BaseRole *string `json:"base_role,omitempty"` +} + +// UpdateOrgRoleOptions represents options required to update a custom organization role. +type UpdateOrgRoleOptions struct { Name *string `json:"name,omitempty"` + Permissions []string `json:"permissions,omitempty"` Description *string `json:"description,omitempty"` - Permissions []string `json:"permissions"` BaseRole *string `json:"base_role,omitempty"` } @@ -89,7 +97,7 @@ func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleI // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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) @@ -112,7 +120,7 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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) diff --git a/github/orgs_organization_roles_test.go b/github/orgs_organization_roles_test.go index 1ae9b9ff111..90993bd2932 100644 --- a/github/orgs_organization_roles_test.go +++ b/github/orgs_organization_roles_test.go @@ -207,10 +207,10 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) { ctx := t.Context() - opts := &CreateOrUpdateOrgRoleOptions{ - Name: Ptr("Reader"), - Description: Ptr("A role for reading custom org roles"), + opts := &CreateOrgRoleOptions{ + Name: "Reader", Permissions: []string{"read_organization_custom_org_role"}, + Description: Ptr("A role for reading custom org roles"), } gotRoles, _, err := client.Organizations.CreateCustomOrgRole(ctx, "o", opts) if err != nil { @@ -249,7 +249,7 @@ func TestOrganizationsService_UpdateCustomOrgRole(t *testing.T) { ctx := t.Context() - opts := &CreateOrUpdateOrgRoleOptions{ + opts := &UpdateOrgRoleOptions{ Name: Ptr("Updated Name"), Description: Ptr("Updated Description"), } From 1bf3aee125d9d7a7fb6fbb9e926206f99d2336b1 Mon Sep 17 00:00:00 2001 From: Nurzhan Muratkhan Date: Tue, 10 Mar 2026 14:18:20 +0500 Subject: [PATCH 2/6] chore: Rearrange fields as they appear in the doc Co-authored-by: Oleksandr Redko --- github/orgs_organization_roles.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 5198e40f1e5..de085141a85 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -32,9 +32,9 @@ type CustomOrgRoles struct { // CreateOrgRoleOptions represents options required to create a custom organization role. type CreateOrgRoleOptions struct { Name string `json:"name"` - Permissions []string `json:"permissions"` Description *string `json:"description,omitempty"` - BaseRole *string `json:"base_role,omitempty"` + Permissions []string `json:"permissions"` + BaseRole *string `json:"base_role,omitempty"` // Can be one of: read, triage, write, maintain, admin } // UpdateOrgRoleOptions represents options required to update a custom organization role. From cc97f4692795e24881fdcd759d93648141baade9 Mon Sep 17 00:00:00 2001 From: munlicode Date: Tue, 10 Mar 2026 15:02:28 +0500 Subject: [PATCH 3/6] refactor!: Align custom org role types with documentation standards. --- github/github-accessors.go | 96 +++++++-------- github/github-accessors_test.go | 156 ++++++++++++------------- github/orgs_organization_roles.go | 34 +++--- github/orgs_organization_roles_test.go | 22 ++-- 4 files changed, 154 insertions(+), 154 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 18aef8c33a4..9b839cd248e 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6854,6 +6854,22 @@ func (c *CreateCodespaceOptions) GetWorkingDirectory() string { return *c.WorkingDirectory } +// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. +func (c *CreateCustomOrgRoleRequest) GetBaseRole() string { + if c == nil || c.BaseRole == nil { + return "" + } + return *c.BaseRole +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (c *CreateCustomOrgRoleRequest) GetDescription() string { + if c == nil || c.Description == nil { + return "" + } + return *c.Description +} + // GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. func (c *CreateEnterpriseRunnerGroupRequest) GetAllowsPublicRepositories() bool { if c == nil || c.AllowsPublicRepositories == nil { @@ -7014,22 +7030,6 @@ func (c *CreateOrgInvitationOptions) GetRole() string { return *c.Role } -// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. -func (c *CreateOrgRoleOptions) GetBaseRole() string { - if c == nil || c.BaseRole == nil { - return "" - } - return *c.BaseRole -} - -// GetDescription returns the Description field if it's non-nil, zero value otherwise. -func (c *CreateOrgRoleOptions) GetDescription() string { - if c == nil || c.Description == nil { - return "" - } - return *c.Description -} - // GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. func (c *CreateOrUpdateCustomRepoRoleOptions) GetBaseRole() string { if c == nil || c.BaseRole == nil { @@ -7383,7 +7383,7 @@ func (c *CustomDeploymentProtectionRuleRequest) GetIntegrationID() int64 { } // GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetBaseRole() string { +func (c *CustomOrgRole) GetBaseRole() string { if c == nil || c.BaseRole == nil { return "" } @@ -7391,7 +7391,7 @@ func (c *CustomOrgRoles) GetBaseRole() string { } // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetCreatedAt() Timestamp { +func (c *CustomOrgRole) GetCreatedAt() Timestamp { if c == nil || c.CreatedAt == nil { return Timestamp{} } @@ -7399,7 +7399,7 @@ func (c *CustomOrgRoles) GetCreatedAt() Timestamp { } // GetDescription returns the Description field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetDescription() string { +func (c *CustomOrgRole) GetDescription() string { if c == nil || c.Description == nil { return "" } @@ -7407,7 +7407,7 @@ func (c *CustomOrgRoles) GetDescription() string { } // GetID returns the ID field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetID() int64 { +func (c *CustomOrgRole) GetID() int64 { if c == nil || c.ID == nil { return 0 } @@ -7415,7 +7415,7 @@ func (c *CustomOrgRoles) GetID() int64 { } // GetName returns the Name field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetName() string { +func (c *CustomOrgRole) GetName() string { if c == nil || c.Name == nil { return "" } @@ -7423,7 +7423,7 @@ func (c *CustomOrgRoles) GetName() string { } // GetOrg returns the Org field. -func (c *CustomOrgRoles) GetOrg() *Organization { +func (c *CustomOrgRole) GetOrg() *Organization { if c == nil { return nil } @@ -7431,7 +7431,7 @@ func (c *CustomOrgRoles) GetOrg() *Organization { } // GetSource returns the Source field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetSource() string { +func (c *CustomOrgRole) GetSource() string { if c == nil || c.Source == nil { return "" } @@ -7439,7 +7439,7 @@ func (c *CustomOrgRoles) GetSource() string { } // GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. -func (c *CustomOrgRoles) GetUpdatedAt() Timestamp { +func (c *CustomOrgRole) GetUpdatedAt() Timestamp { if c == nil || c.UpdatedAt == nil { return Timestamp{} } @@ -30478,6 +30478,30 @@ func (u *UpdateCodespaceOptions) GetMachine() string { return *u.Machine } +// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. +func (u *UpdateCustomOrgRoleRequest) GetBaseRole() string { + if u == nil || u.BaseRole == nil { + return "" + } + return *u.BaseRole +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (u *UpdateCustomOrgRoleRequest) GetDescription() string { + if u == nil || u.Description == nil { + return "" + } + return *u.Description +} + +// GetName returns the Name field if it's non-nil, zero value otherwise. +func (u *UpdateCustomOrgRoleRequest) GetName() string { + if u == nil || u.Name == nil { + return "" + } + return *u.Name +} + // GetQuerySuite returns the QuerySuite field if it's non-nil, zero value otherwise. func (u *UpdateDefaultSetupConfigurationOptions) GetQuerySuite() string { if u == nil || u.QuerySuite == nil { @@ -30638,30 +30662,6 @@ func (u *UpdateOrganizationPrivateRegistry) GetVisibility() *PrivateRegistryVisi return u.Visibility } -// GetBaseRole returns the BaseRole field if it's non-nil, zero value otherwise. -func (u *UpdateOrgRoleOptions) GetBaseRole() string { - if u == nil || u.BaseRole == nil { - return "" - } - return *u.BaseRole -} - -// GetDescription returns the Description field if it's non-nil, zero value otherwise. -func (u *UpdateOrgRoleOptions) GetDescription() string { - if u == nil || u.Description == nil { - return "" - } - return *u.Description -} - -// GetName returns the Name field if it's non-nil, zero value otherwise. -func (u *UpdateOrgRoleOptions) GetName() string { - if u == nil || u.Name == nil { - return "" - } - return *u.Name -} - // GetArchived returns the Archived field if it's non-nil, zero value otherwise. func (u *UpdateProjectItemOptions) GetArchived() bool { if u == nil || u.Archived == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 4c6090ca40f..b7c5d32b34f 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8970,6 +8970,28 @@ func TestCreateCodespaceOptions_GetWorkingDirectory(tt *testing.T) { c.GetWorkingDirectory() } +func TestCreateCustomOrgRoleRequest_GetBaseRole(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateCustomOrgRoleRequest{BaseRole: &zeroValue} + c.GetBaseRole() + c = &CreateCustomOrgRoleRequest{} + c.GetBaseRole() + c = nil + c.GetBaseRole() +} + +func TestCreateCustomOrgRoleRequest_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CreateCustomOrgRoleRequest{Description: &zeroValue} + c.GetDescription() + c = &CreateCustomOrgRoleRequest{} + c.GetDescription() + c = nil + c.GetDescription() +} + func TestCreateEnterpriseRunnerGroupRequest_GetAllowsPublicRepositories(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -9178,28 +9200,6 @@ func TestCreateOrgInvitationOptions_GetRole(tt *testing.T) { c.GetRole() } -func TestCreateOrgRoleOptions_GetBaseRole(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CreateOrgRoleOptions{BaseRole: &zeroValue} - c.GetBaseRole() - c = &CreateOrgRoleOptions{} - c.GetBaseRole() - c = nil - c.GetBaseRole() -} - -func TestCreateOrgRoleOptions_GetDescription(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CreateOrgRoleOptions{Description: &zeroValue} - c.GetDescription() - c = &CreateOrgRoleOptions{} - c.GetDescription() - c = nil - c.GetDescription() -} - func TestCreateOrUpdateCustomRepoRoleOptions_GetBaseRole(tt *testing.T) { tt.Parallel() var zeroValue string @@ -9672,86 +9672,86 @@ func TestCustomDeploymentProtectionRuleRequest_GetIntegrationID(tt *testing.T) { c.GetIntegrationID() } -func TestCustomOrgRoles_GetBaseRole(tt *testing.T) { +func TestCustomOrgRole_GetBaseRole(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomOrgRoles{BaseRole: &zeroValue} + c := &CustomOrgRole{BaseRole: &zeroValue} c.GetBaseRole() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetBaseRole() c = nil c.GetBaseRole() } -func TestCustomOrgRoles_GetCreatedAt(tt *testing.T) { +func TestCustomOrgRole_GetCreatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp - c := &CustomOrgRoles{CreatedAt: &zeroValue} + c := &CustomOrgRole{CreatedAt: &zeroValue} c.GetCreatedAt() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetCreatedAt() c = nil c.GetCreatedAt() } -func TestCustomOrgRoles_GetDescription(tt *testing.T) { +func TestCustomOrgRole_GetDescription(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomOrgRoles{Description: &zeroValue} + c := &CustomOrgRole{Description: &zeroValue} c.GetDescription() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetDescription() c = nil c.GetDescription() } -func TestCustomOrgRoles_GetID(tt *testing.T) { +func TestCustomOrgRole_GetID(tt *testing.T) { tt.Parallel() var zeroValue int64 - c := &CustomOrgRoles{ID: &zeroValue} + c := &CustomOrgRole{ID: &zeroValue} c.GetID() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetID() c = nil c.GetID() } -func TestCustomOrgRoles_GetName(tt *testing.T) { +func TestCustomOrgRole_GetName(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomOrgRoles{Name: &zeroValue} + c := &CustomOrgRole{Name: &zeroValue} c.GetName() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetName() c = nil c.GetName() } -func TestCustomOrgRoles_GetOrg(tt *testing.T) { +func TestCustomOrgRole_GetOrg(tt *testing.T) { tt.Parallel() - c := &CustomOrgRoles{} + c := &CustomOrgRole{} c.GetOrg() c = nil c.GetOrg() } -func TestCustomOrgRoles_GetSource(tt *testing.T) { +func TestCustomOrgRole_GetSource(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CustomOrgRoles{Source: &zeroValue} + c := &CustomOrgRole{Source: &zeroValue} c.GetSource() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetSource() c = nil c.GetSource() } -func TestCustomOrgRoles_GetUpdatedAt(tt *testing.T) { +func TestCustomOrgRole_GetUpdatedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp - c := &CustomOrgRoles{UpdatedAt: &zeroValue} + c := &CustomOrgRole{UpdatedAt: &zeroValue} c.GetUpdatedAt() - c = &CustomOrgRoles{} + c = &CustomOrgRole{} c.GetUpdatedAt() c = nil c.GetUpdatedAt() @@ -39296,6 +39296,39 @@ func TestUpdateCodespaceOptions_GetMachine(tt *testing.T) { u.GetMachine() } +func TestUpdateCustomOrgRoleRequest_GetBaseRole(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateCustomOrgRoleRequest{BaseRole: &zeroValue} + u.GetBaseRole() + u = &UpdateCustomOrgRoleRequest{} + u.GetBaseRole() + u = nil + u.GetBaseRole() +} + +func TestUpdateCustomOrgRoleRequest_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateCustomOrgRoleRequest{Description: &zeroValue} + u.GetDescription() + u = &UpdateCustomOrgRoleRequest{} + u.GetDescription() + u = nil + u.GetDescription() +} + +func TestUpdateCustomOrgRoleRequest_GetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UpdateCustomOrgRoleRequest{Name: &zeroValue} + u.GetName() + u = &UpdateCustomOrgRoleRequest{} + u.GetName() + u = nil + u.GetName() +} + func TestUpdateDefaultSetupConfigurationOptions_GetQuerySuite(tt *testing.T) { tt.Parallel() var zeroValue string @@ -39513,39 +39546,6 @@ func TestUpdateOrganizationPrivateRegistry_GetVisibility(tt *testing.T) { u.GetVisibility() } -func TestUpdateOrgRoleOptions_GetBaseRole(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UpdateOrgRoleOptions{BaseRole: &zeroValue} - u.GetBaseRole() - u = &UpdateOrgRoleOptions{} - u.GetBaseRole() - u = nil - u.GetBaseRole() -} - -func TestUpdateOrgRoleOptions_GetDescription(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UpdateOrgRoleOptions{Description: &zeroValue} - u.GetDescription() - u = &UpdateOrgRoleOptions{} - u.GetDescription() - u = nil - u.GetDescription() -} - -func TestUpdateOrgRoleOptions_GetName(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UpdateOrgRoleOptions{Name: &zeroValue} - u.GetName() - u = &UpdateOrgRoleOptions{} - u.GetName() - u = nil - u.GetName() -} - func TestUpdateProjectItemOptions_GetArchived(tt *testing.T) { tt.Parallel() var zeroValue bool diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index de085141a85..7233ac76c3a 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -12,12 +12,12 @@ import ( // OrganizationCustomRoles represents custom organization roles available in specified organization. type OrganizationCustomRoles struct { - TotalCount *int `json:"total_count,omitempty"` - CustomRepoRoles []*CustomOrgRoles `json:"roles,omitempty"` + TotalCount *int `json:"total_count,omitempty"` + CustomRepoRoles []*CustomOrgRole `json:"roles,omitempty"` } -// CustomOrgRoles represents custom organization role available in specified organization. -type CustomOrgRoles struct { +// CustomOrgRole represents custom organization role available in specified organization. +type CustomOrgRole struct { ID *int64 `json:"id,omitempty"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` @@ -29,20 +29,20 @@ type CustomOrgRoles struct { BaseRole *string `json:"base_role,omitempty"` } -// CreateOrgRoleOptions represents options required to create a custom organization role. -type CreateOrgRoleOptions struct { +// CreateCustomOrgRoleRequest represents options required to create a custom organization role. +type CreateCustomOrgRoleRequest struct { Name string `json:"name"` Description *string `json:"description,omitempty"` Permissions []string `json:"permissions"` BaseRole *string `json:"base_role,omitempty"` // Can be one of: read, triage, write, maintain, admin } -// UpdateOrgRoleOptions represents options required to update a custom organization role. -type UpdateOrgRoleOptions struct { +// UpdateCustomOrgRoleRequest represents options required to update a custom organization role. +type UpdateCustomOrgRoleRequest struct { Name *string `json:"name,omitempty"` - Permissions []string `json:"permissions,omitempty"` Description *string `json:"description,omitempty"` - BaseRole *string `json:"base_role,omitempty"` + Permissions []string `json:"permissions,omitempty"` + BaseRole *string `json:"base_role,omitempty"` // Can be one of: none, read, triage, write, maintain, admin } // ListRoles lists the custom roles available in this organization. @@ -74,7 +74,7 @@ func (s *OrganizationsService) ListRoles(ctx context.Context, org string) (*Orga // GitHub API docs: https://docs.github.com/rest/orgs/organization-roles#get-an-organization-role // //meta:operation GET /orgs/{org}/organization-roles/{role_id} -func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleID int64) (*CustomOrgRoles, *Response, error) { +func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleID int64) (*CustomOrgRole, *Response, error) { u := fmt.Sprintf("orgs/%v/organization-roles/%v", org, roleID) req, err := s.client.NewRequest("GET", u, nil) @@ -82,7 +82,7 @@ func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleI return nil, nil, err } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return nil, resp, err @@ -97,7 +97,7 @@ func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleI // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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 *CreateOrgRoleOptions) (*CustomOrgRoles, *Response, error) { +func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org string, opts CreateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { u := fmt.Sprintf("orgs/%v/organization-roles", org) req, err := s.client.NewRequest("POST", u, opts) @@ -105,7 +105,7 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri return nil, nil, err } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return nil, resp, err @@ -120,7 +120,7 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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 *UpdateOrgRoleOptions) (*CustomOrgRoles, *Response, error) { +func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, opts UpdateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { u := fmt.Sprintf("orgs/%v/organization-roles/%v", org, roleID) req, err := s.client.NewRequest("PATCH", u, opts) @@ -128,7 +128,7 @@ func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org stri return nil, nil, err } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return nil, resp, err @@ -151,7 +151,7 @@ func (s *OrganizationsService) DeleteCustomOrgRole(ctx context.Context, org stri return nil, err } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return resp, err diff --git a/github/orgs_organization_roles_test.go b/github/orgs_organization_roles_test.go index 90993bd2932..7ef01fc71e2 100644 --- a/github/orgs_organization_roles_test.go +++ b/github/orgs_organization_roles_test.go @@ -54,7 +54,7 @@ func TestOrganizationsService_ListRoles(t *testing.T) { want := &OrganizationCustomRoles{ TotalCount: Ptr(1), - CustomRepoRoles: []*CustomOrgRoles{ + CustomRepoRoles: []*CustomOrgRole{ { ID: Ptr(int64(1)), Name: Ptr("Auditor"), @@ -123,7 +123,7 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { t.Errorf("Organizations.GetOrgRole returned error: %v", err) } - wantBuiltInRole := &CustomOrgRoles{ + wantBuiltInRole := &CustomOrgRole{ ID: Ptr(int64(8132)), Name: Ptr("all_repo_read"), Description: Ptr("Grants read access to all repositories in the organization."), @@ -162,7 +162,7 @@ func TestOrganizationsService_GetOrgRole(t *testing.T) { t.Errorf("Organizations.GetOrgRole returned error: %v", err) } - wantCustomRole := &CustomOrgRoles{ + wantCustomRole := &CustomOrgRole{ ID: Ptr(int64(123456)), Name: Ptr("test-role"), Description: Ptr("test-role"), @@ -207,7 +207,7 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) { ctx := t.Context() - opts := &CreateOrgRoleOptions{ + opts := CreateCustomOrgRoleRequest{ Name: "Reader", Permissions: []string{"read_organization_custom_org_role"}, Description: Ptr("A role for reading custom org roles"), @@ -217,7 +217,7 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) { t.Errorf("Organizations.CreateCustomOrgRole returned error: %v", err) } - want := &CustomOrgRoles{ID: Ptr(int64(8030)), Name: Ptr("Reader"), Permissions: []string{"read_organization_custom_org_role"}, Description: Ptr("A role for reading custom org roles")} + want := &CustomOrgRole{ID: Ptr(int64(8030)), Name: Ptr("Reader"), Permissions: []string{"read_organization_custom_org_role"}, Description: Ptr("A role for reading custom org roles")} if !cmp.Equal(gotRoles, want) { t.Errorf("Organizations.CreateCustomOrgRole returned %+v, want %+v", gotRoles, want) @@ -225,12 +225,12 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) { const methodName = "CreateCustomOrgRole" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Organizations.CreateCustomOrgRole(ctx, "\no", nil) + _, _, err = client.Organizations.CreateCustomOrgRole(ctx, "\no", CreateCustomOrgRoleRequest{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Organizations.CreateCustomOrgRole(ctx, "o", nil) + got, resp, err := client.Organizations.CreateCustomOrgRole(ctx, "o", CreateCustomOrgRoleRequest{}) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -249,7 +249,7 @@ func TestOrganizationsService_UpdateCustomOrgRole(t *testing.T) { ctx := t.Context() - opts := &UpdateOrgRoleOptions{ + opts := UpdateCustomOrgRoleRequest{ Name: Ptr("Updated Name"), Description: Ptr("Updated Description"), } @@ -258,7 +258,7 @@ func TestOrganizationsService_UpdateCustomOrgRole(t *testing.T) { t.Errorf("Organizations.UpdateCustomOrgRole returned error: %v", err) } - want := &CustomOrgRoles{ID: Ptr(int64(8030)), Name: Ptr("Updated Name"), Permissions: []string{"read_organization_custom_org_role"}, Description: Ptr("Updated Description")} + want := &CustomOrgRole{ID: Ptr(int64(8030)), Name: Ptr("Updated Name"), Permissions: []string{"read_organization_custom_org_role"}, Description: Ptr("Updated Description")} if !cmp.Equal(gotRoles, want) { t.Errorf("Organizations.UpdateCustomOrgRole returned %+v, want %+v", gotRoles, want) @@ -266,12 +266,12 @@ func TestOrganizationsService_UpdateCustomOrgRole(t *testing.T) { const methodName = "UpdateCustomOrgRole" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Organizations.UpdateCustomOrgRole(ctx, "\no", 8030, nil) + _, _, err = client.Organizations.UpdateCustomOrgRole(ctx, "\no", 8030, UpdateCustomOrgRoleRequest{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Organizations.UpdateCustomOrgRole(ctx, "o", 8030, nil) + got, resp, err := client.Organizations.UpdateCustomOrgRole(ctx, "o", 8030, UpdateCustomOrgRoleRequest{}) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } From 3029f2690bff511fb694bcaa8cea30ad2c262beb Mon Sep 17 00:00:00 2001 From: munlicode Date: Tue, 10 Mar 2026 15:18:39 +0500 Subject: [PATCH 4/6] chore: Rename `opts` to `request` to follow code base style --- github/orgs_organization_roles.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 7233ac76c3a..85a60ee62cf 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -97,10 +97,10 @@ func (s *OrganizationsService) GetOrgRole(ctx context.Context, org string, roleI // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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 CreateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { +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, opts) + req, err := s.client.NewRequest("POST", u, request) if err != nil { return nil, nil, err } @@ -120,10 +120,10 @@ func (s *OrganizationsService) CreateCustomOrgRole(ctx context.Context, org stri // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/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 UpdateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { +func (s *OrganizationsService) UpdateCustomOrgRole(ctx context.Context, org string, roleID int64, request UpdateCustomOrgRoleRequest) (*CustomOrgRole, *Response, error) { u := fmt.Sprintf("orgs/%v/organization-roles/%v", org, roleID) - req, err := s.client.NewRequest("PATCH", u, opts) + req, err := s.client.NewRequest("PATCH", u, request) if err != nil { return nil, nil, err } From c1d08de0dba00d9e814faf8cdeea71833c915041 Mon Sep 17 00:00:00 2001 From: Nurzhan Muratkhan Date: Tue, 10 Mar 2026 15:38:21 +0500 Subject: [PATCH 5/6] docs: Update comment for `UpdateCustomOrgRoleRequest` Change `options required` to `body parameters`. Co-authored-by: Oleksandr Redko --- github/orgs_organization_roles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 85a60ee62cf..054e96177a7 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -37,7 +37,7 @@ type CreateCustomOrgRoleRequest struct { BaseRole *string `json:"base_role,omitempty"` // Can be one of: read, triage, write, maintain, admin } -// UpdateCustomOrgRoleRequest represents options required to update a custom organization role. +// UpdateCustomOrgRoleRequest represents body parameters to update a custom organization role. type UpdateCustomOrgRoleRequest struct { Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` From ad1c650adeade3b101cb30b4cea1e0dab1eb0b3f Mon Sep 17 00:00:00 2001 From: Nurzhan Muratkhan Date: Tue, 10 Mar 2026 15:39:19 +0500 Subject: [PATCH 6/6] docs: Update comment for `CreateCustomOrgRoleRequest` type Change `options required` to `body parameters required` Co-authored-by: Oleksandr Redko --- github/orgs_organization_roles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 054e96177a7..07b9744cbd4 100644 --- a/github/orgs_organization_roles.go +++ b/github/orgs_organization_roles.go @@ -29,7 +29,7 @@ type CustomOrgRole struct { BaseRole *string `json:"base_role,omitempty"` } -// CreateCustomOrgRoleRequest represents options required to create a custom organization role. +// CreateCustomOrgRoleRequest represents body parameters required to create a custom organization role. type CreateCustomOrgRoleRequest struct { Name string `json:"name"` Description *string `json:"description,omitempty"`