diff --git a/github/github-accessors.go b/github/github-accessors.go index aa52b9ae260..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 { @@ -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 { @@ -7391,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 "" } @@ -7399,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{} } @@ -7407,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 "" } @@ -7415,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 } @@ -7423,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 "" } @@ -7431,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 } @@ -7439,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 "" } @@ -7447,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{} } @@ -30486,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 { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 037406b83d6..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 @@ -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 @@ -9683,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() @@ -39307,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 diff --git a/github/orgs_organization_roles.go b/github/orgs_organization_roles.go index 0954b92d41b..07b9744cbd4 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,12 +29,20 @@ type CustomOrgRoles struct { BaseRole *string `json:"base_role,omitempty"` } -// CreateOrUpdateOrgRoleOptions represents options required to create or update a custom organization role. -type CreateOrUpdateOrgRoleOptions struct { - Name *string `json:"name,omitempty"` +// CreateCustomOrgRoleRequest represents body parameters 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"` + BaseRole *string `json:"base_role,omitempty"` // Can be one of: read, triage, write, maintain, admin +} + +// UpdateCustomOrgRoleRequest represents body parameters to update a custom organization role. +type UpdateCustomOrgRoleRequest struct { + Name *string `json:"name,omitempty"` + Description *string `json:"description,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. @@ -66,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) @@ -74,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 @@ -89,15 +97,15 @@ 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, 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 } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return nil, resp, err @@ -112,15 +120,15 @@ 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, 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 } - resultingRole := new(CustomOrgRoles) + resultingRole := new(CustomOrgRole) resp, err := s.client.Do(ctx, req, resultingRole) if err != nil { return nil, resp, err @@ -143,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 1ae9b9ff111..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,17 +207,17 @@ func TestOrganizationsService_CreateCustomOrgRole(t *testing.T) { ctx := t.Context() - opts := &CreateOrUpdateOrgRoleOptions{ - Name: Ptr("Reader"), - Description: Ptr("A role for reading custom org roles"), + opts := CreateCustomOrgRoleRequest{ + 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 { 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 := &CreateOrUpdateOrgRoleOptions{ + 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) }