Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions github/enterprise_billing_cost_centers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ type CostCenters struct {
CostCenters []*CostCenter `json:"costCenters,omitempty"`
}

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

// CostCenterRequest represents a request to create or update a cost center.
type CostCenterRequest struct {
Name *string `json:"name,omitempty"`
Name string `json:"name"`
}

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

// CostCenterAddResourceResponse represents a response from adding resources to a cost center.
type CostCenterAddResourceResponse struct {
// AddResourcesToCostCenterResponse represents a response from adding resources to a cost center.
type AddResourcesToCostCenterResponse struct {
Message *string `json:"message,omitempty"`
ReassignedResources []*ReassignedResource `json:"reassigned_resources,omitempty"`
}
Expand All @@ -60,25 +61,25 @@ type ReassignedResource struct {
PreviousCostCenter *string `json:"previous_cost_center,omitempty"`
}

// CostCenterRemoveResourceResponse represents a response from removing resources from a cost center.
type CostCenterRemoveResourceResponse struct {
// RemoveResourcesFromCostCenterResponse represents a response from removing resources from a cost center.
type RemoveResourcesFromCostCenterResponse struct {
Message *string `json:"message,omitempty"`
}

// CostCenterDeleteResponse represents a response from deleting a cost center.
type CostCenterDeleteResponse struct {
Message *string `json:"message,omitempty"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
CostCenterState *string `json:"costCenterState,omitempty"`
// DeleteCostCenterResponse represents a response from deleting a cost center.
type DeleteCostCenterResponse struct {
Message string `json:"message"`
ID string `json:"id"`
Name string `json:"name"`
CostCenterState string `json:"costCenterState"`
}

// ListCostCenters lists all cost centers for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#get-all-cost-centers-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/settings/billing/cost-centers
func (s *EnterpriseService) ListCostCenters(ctx context.Context, enterprise string, opts *CostCenterListOptions) (*CostCenters, *Response, error) {
func (s *EnterpriseService) ListCostCenters(ctx context.Context, enterprise string, opts *ListCostCenterOptions) (*CostCenters, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers", enterprise)
u, err := addOptions(u, opts)
if err != nil {
Expand Down Expand Up @@ -170,15 +171,15 @@ func (s *EnterpriseService) UpdateCostCenter(ctx context.Context, enterprise, co
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/billing#delete-a-cost-center
//
//meta:operation DELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}
func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, costCenterID string) (*CostCenterDeleteResponse, *Response, error) {
func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, costCenterID string) (*DeleteCostCenterResponse, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v", enterprise, costCenterID)

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

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

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

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

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

result := &CostCenterRemoveResourceResponse{}
result := &RemoveResourcesFromCostCenterResponse{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
Expand Down
43 changes: 32 additions & 11 deletions github/enterprise_billing_cost_centers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestEnterpriseService_ListCostCenters(t *testing.T) {
})

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

ctx := t.Context()
req := CostCenterRequest{
Name: Ptr("Engineering Team"),
Name: "Engineering Team",
}
costCenter, _, err := client.Enterprise.CreateCostCenter(ctx, "e", req)
if err != nil {
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestEnterpriseService_UpdateCostCenter(t *testing.T) {

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

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

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

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

u := &CostCenterRequest{
Name: Ptr("Engineering"),
Name: "Engineering",
}

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

testJSONMarshal(t, u, want)
}

func TestDeleteCostCenterResponse_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &DeleteCostCenterResponse{}, `{"message":"","id":"","name":"","costCenterState":""}`)

u := &DeleteCostCenterResponse{
Message: "Cost center successfully deleted.",
ID: "2eeb8ffe-6903-11ee-8c99-0242ac120002",
Name: "Engineering Team",
CostCenterState: "CostCenterArchived",
}

want := `{
"message": "Cost center successfully deleted.",
"id": "2eeb8ffe-6903-11ee-8c99-0242ac120002",
"name": "Engineering Team",
"costCenterState": "CostCenterArchived"
}`

testJSONMarshal(t, u, want)
}
88 changes: 24 additions & 64 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading