Skip to content

Commit 1b0a91c

Browse files
authored
feat!: Address post-merge enterprise billing cost center review (#3805)
BREAKING CHANGES: Various `EnterpriseService` structs have been renamed for consistency.
1 parent 8760289 commit 1b0a91c

File tree

4 files changed

+110
-183
lines changed

4 files changed

+110
-183
lines changed

github/enterprise_billing_cost_centers.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ type CostCenters struct {
3030
CostCenters []*CostCenter `json:"costCenters,omitempty"`
3131
}
3232

33-
// CostCenterListOptions specifies optional parameters to the EnterpriseService.ListCostCenters method.
34-
type CostCenterListOptions struct {
33+
// ListCostCenterOptions specifies optional parameters to the EnterpriseService.ListCostCenters method.
34+
type ListCostCenterOptions struct {
35+
// Set to `active` or `deleted` to only list cost centers in a specific state.
3536
State *string `url:"state,omitempty"`
3637
}
3738

3839
// CostCenterRequest represents a request to create or update a cost center.
3940
type CostCenterRequest struct {
40-
Name *string `json:"name,omitempty"`
41+
Name string `json:"name"`
4142
}
4243

4344
// CostCenterResourceRequest represents a request to add or remove resources from a cost center.
@@ -47,8 +48,8 @@ type CostCenterResourceRequest struct {
4748
Repositories []string `json:"repositories,omitempty"`
4849
}
4950

50-
// CostCenterAddResourceResponse represents a response from adding resources to a cost center.
51-
type CostCenterAddResourceResponse struct {
51+
// AddResourcesToCostCenterResponse represents a response from adding resources to a cost center.
52+
type AddResourcesToCostCenterResponse struct {
5253
Message *string `json:"message,omitempty"`
5354
ReassignedResources []*ReassignedResource `json:"reassigned_resources,omitempty"`
5455
}
@@ -60,25 +61,25 @@ type ReassignedResource struct {
6061
PreviousCostCenter *string `json:"previous_cost_center,omitempty"`
6162
}
6263

63-
// CostCenterRemoveResourceResponse represents a response from removing resources from a cost center.
64-
type CostCenterRemoveResourceResponse struct {
64+
// RemoveResourcesFromCostCenterResponse represents a response from removing resources from a cost center.
65+
type RemoveResourcesFromCostCenterResponse struct {
6566
Message *string `json:"message,omitempty"`
6667
}
6768

68-
// CostCenterDeleteResponse represents a response from deleting a cost center.
69-
type CostCenterDeleteResponse struct {
70-
Message *string `json:"message,omitempty"`
71-
ID *string `json:"id,omitempty"`
72-
Name *string `json:"name,omitempty"`
73-
CostCenterState *string `json:"costCenterState,omitempty"`
69+
// DeleteCostCenterResponse represents a response from deleting a cost center.
70+
type DeleteCostCenterResponse struct {
71+
Message string `json:"message"`
72+
ID string `json:"id"`
73+
Name string `json:"name"`
74+
CostCenterState string `json:"costCenterState"`
7475
}
7576

7677
// ListCostCenters lists all cost centers for an enterprise.
7778
//
7879
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#get-all-cost-centers-for-an-enterprise
7980
//
8081
//meta:operation GET /enterprises/{enterprise}/settings/billing/cost-centers
81-
func (s *EnterpriseService) ListCostCenters(ctx context.Context, enterprise string, opts *CostCenterListOptions) (*CostCenters, *Response, error) {
82+
func (s *EnterpriseService) ListCostCenters(ctx context.Context, enterprise string, opts *ListCostCenterOptions) (*CostCenters, *Response, error) {
8283
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers", enterprise)
8384
u, err := addOptions(u, opts)
8485
if err != nil {
@@ -170,15 +171,15 @@ func (s *EnterpriseService) UpdateCostCenter(ctx context.Context, enterprise, co
170171
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#delete-a-cost-center
171172
//
172173
//meta:operation DELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}
173-
func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, costCenterID string) (*CostCenterDeleteResponse, *Response, error) {
174+
func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, costCenterID string) (*DeleteCostCenterResponse, *Response, error) {
174175
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v", enterprise, costCenterID)
175176

176177
req, err := s.client.NewRequest("DELETE", u, nil)
177178
if err != nil {
178179
return nil, nil, err
179180
}
180181

181-
result := &CostCenterDeleteResponse{}
182+
result := &DeleteCostCenterResponse{}
182183
resp, err := s.client.Do(ctx, req, result)
183184
if err != nil {
184185
return nil, resp, err
@@ -192,15 +193,15 @@ func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, co
192193
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#add-resources-to-a-cost-center
193194
//
194195
//meta:operation POST /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
195-
func (s *EnterpriseService) AddResourcesToCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*CostCenterAddResourceResponse, *Response, error) {
196+
func (s *EnterpriseService) AddResourcesToCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*AddResourcesToCostCenterResponse, *Response, error) {
196197
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v/resource", enterprise, costCenterID)
197198

198199
req, err := s.client.NewRequest("POST", u, resources)
199200
if err != nil {
200201
return nil, nil, err
201202
}
202203

203-
result := &CostCenterAddResourceResponse{}
204+
result := &AddResourcesToCostCenterResponse{}
204205
resp, err := s.client.Do(ctx, req, result)
205206
if err != nil {
206207
return nil, resp, err
@@ -214,15 +215,15 @@ func (s *EnterpriseService) AddResourcesToCostCenter(ctx context.Context, enterp
214215
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#remove-resources-from-a-cost-center
215216
//
216217
//meta:operation DELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
217-
func (s *EnterpriseService) RemoveResourcesFromCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*CostCenterRemoveResourceResponse, *Response, error) {
218+
func (s *EnterpriseService) RemoveResourcesFromCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*RemoveResourcesFromCostCenterResponse, *Response, error) {
218219
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v/resource", enterprise, costCenterID)
219220

220221
req, err := s.client.NewRequest("DELETE", u, resources)
221222
if err != nil {
222223
return nil, nil, err
223224
}
224225

225-
result := &CostCenterRemoveResourceResponse{}
226+
result := &RemoveResourcesFromCostCenterResponse{}
226227
resp, err := s.client.Do(ctx, req, result)
227228
if err != nil {
228229
return nil, resp, err

github/enterprise_billing_cost_centers_test.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestEnterpriseService_ListCostCenters(t *testing.T) {
5656
})
5757

5858
ctx := t.Context()
59-
opts := &CostCenterListOptions{
59+
opts := &ListCostCenterOptions{
6060
State: Ptr("active"),
6161
}
6262
costCenters, _, err := client.Enterprise.ListCostCenters(ctx, "e", opts)
@@ -139,7 +139,7 @@ func TestEnterpriseService_CreateCostCenter(t *testing.T) {
139139

140140
ctx := t.Context()
141141
req := CostCenterRequest{
142-
Name: Ptr("Engineering Team"),
142+
Name: "Engineering Team",
143143
}
144144
costCenter, _, err := client.Enterprise.CreateCostCenter(ctx, "e", req)
145145
if err != nil {
@@ -280,7 +280,7 @@ func TestEnterpriseService_UpdateCostCenter(t *testing.T) {
280280

281281
ctx := t.Context()
282282
req := CostCenterRequest{
283-
Name: Ptr("Updated Cost Center Name"),
283+
Name: "Updated Cost Center Name",
284284
}
285285
costCenter, _, err := client.Enterprise.UpdateCostCenter(ctx, "e", "2eeb8ffe-6903-11ee-8c99-0242ac120002", req)
286286
if err != nil {
@@ -351,11 +351,11 @@ func TestEnterpriseService_DeleteCostCenter(t *testing.T) {
351351
t.Errorf("Enterprise.DeleteCostCenter returned error: %v", err)
352352
}
353353

354-
want := &CostCenterDeleteResponse{
355-
Message: Ptr("Cost center successfully deleted."),
356-
ID: Ptr("2eeb8ffe-6903-11ee-8c99-0242ac120002"),
357-
Name: Ptr("Engineering Team"),
358-
CostCenterState: Ptr("CostCenterArchived"),
354+
want := &DeleteCostCenterResponse{
355+
Message: "Cost center successfully deleted.",
356+
ID: "2eeb8ffe-6903-11ee-8c99-0242ac120002",
357+
Name: "Engineering Team",
358+
CostCenterState: "CostCenterArchived",
359359
}
360360
if !cmp.Equal(result, want) {
361361
t.Errorf("Enterprise.DeleteCostCenter returned %+v, want %+v", result, want)
@@ -423,7 +423,7 @@ func TestEnterpriseService_AddResourcesToCostCenter(t *testing.T) {
423423
t.Errorf("Enterprise.AddResourcesToCostCenter returned error: %v", err)
424424
}
425425

426-
want := &CostCenterAddResourceResponse{
426+
want := &AddResourcesToCostCenterResponse{
427427
Message: Ptr("Resources successfully added to the cost center."),
428428
ReassignedResources: []*ReassignedResource{
429429
{
@@ -492,7 +492,7 @@ func TestEnterpriseService_RemoveResourcesFromCostCenter(t *testing.T) {
492492
t.Errorf("Enterprise.RemoveResourcesFromCostCenter returned error: %v", err)
493493
}
494494

495-
want := &CostCenterRemoveResourceResponse{
495+
want := &RemoveResourcesFromCostCenterResponse{
496496
Message: Ptr("Resources successfully removed from the cost center."),
497497
}
498498
if !cmp.Equal(result, want) {
@@ -607,7 +607,7 @@ func TestCostCenterRequest_Marshal(t *testing.T) {
607607
testJSONMarshal(t, &CostCenterRequest{}, "{}")
608608

609609
u := &CostCenterRequest{
610-
Name: Ptr("Engineering"),
610+
Name: "Engineering",
611611
}
612612

613613
want := `{
@@ -635,3 +635,24 @@ func TestCostCenterResourceRequest_Marshal(t *testing.T) {
635635

636636
testJSONMarshal(t, u, want)
637637
}
638+
639+
func TestDeleteCostCenterResponse_Marshal(t *testing.T) {
640+
t.Parallel()
641+
testJSONMarshal(t, &DeleteCostCenterResponse{}, `{"message":"","id":"","name":"","costCenterState":""}`)
642+
643+
u := &DeleteCostCenterResponse{
644+
Message: "Cost center successfully deleted.",
645+
ID: "2eeb8ffe-6903-11ee-8c99-0242ac120002",
646+
Name: "Engineering Team",
647+
CostCenterState: "CostCenterArchived",
648+
}
649+
650+
want := `{
651+
"message": "Cost center successfully deleted.",
652+
"id": "2eeb8ffe-6903-11ee-8c99-0242ac120002",
653+
"name": "Engineering Team",
654+
"costCenterState": "CostCenterArchived"
655+
}`
656+
657+
testJSONMarshal(t, u, want)
658+
}

github/github-accessors.go

Lines changed: 24 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)