From 586c06749490449fe9970925498762287544678c Mon Sep 17 00:00:00 2001 From: maishivamhoo123 Date: Fri, 5 Jun 2026 11:08:37 +0000 Subject: [PATCH 1/5] billing: add GetAICreditUsage endpoint for organization AI credits Signed-off-by: maishivamhoo123 --- github/billing.go | 26 +++++++ github/billing_test.go | 167 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) diff --git a/github/billing.go b/github/billing.go index 9e9d812a0e0..ff1b8f2d3b2 100644 --- a/github/billing.go +++ b/github/billing.go @@ -392,3 +392,29 @@ func (s *BillingService) GetPremiumRequestUsageReport(ctx context.Context, user return premiumRequestUsageReport, resp, nil } + +// GetAICreditUsage returns a report of the AI credit usage for an organization. +// +// GitHub API docs: https://docs.github.com/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-an-organization +// +//meta:operation GET /organizations/{org}/settings/billing/ai_credit/usage +func (s *BillingService) GetAICreditUsage(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { + u := fmt.Sprintf("organizations/%v/settings/billing/ai_credit/usage", org) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var aiCreditUsage *PremiumRequestUsageReport + resp, err := s.client.Do(req, &aiCreditUsage) + if err != nil { + return nil, resp, err + } + + return aiCreditUsage, resp, nil +} diff --git a/github/billing_test.go b/github/billing_test.go index 1c1ba31fe20..c6ad1748a26 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -720,3 +720,170 @@ func TestBillingService_PremiumRequestUsageItem_FloatQuantities(t *testing.T) { t.Errorf("Billing.GetOrganizationPremiumRequestUsageReport returned %+v, want %+v", report, want) } } + +func TestBillingService_GetAICreditUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "6", + "user": "testuser", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6 + }, + "organization": "GitHub", + "user": "testuser", + "product": "Copilot", + "model": "GPT-5", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 100, + "grossAmount": 1.0, + "discountQuantity": 0, + "discountAmount": 0.0, + "netQuantity": 100, + "netAmount": 1.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &PremiumRequestUsageReportOptions{ + Year: Ptr(2025), + Month: Ptr(6), + User: Ptr("testuser"), + } + report, _, err := client.Billing.GetAICreditUsage(ctx, "o", opts) + if err != nil { + t.Errorf("Billing.GetAICreditUsage returned error: %v", err) + } + + want := &PremiumRequestUsageReport{ + TimePeriod: PremiumRequestUsageTimePeriod{ + Year: 2025, + Month: Ptr(6), + }, + Organization: Ptr("GitHub"), + User: Ptr("testuser"), + Product: Ptr("Copilot"), + Model: Ptr("GPT-5"), + UsageItems: []*PremiumRequestUsageItem{ + { + Product: "Copilot", + SKU: "Copilot AI Credits", + Model: "GPT-5", + UnitType: "credits", + PricePerUnit: 0.01, + GrossQuantity: 100.0, + GrossAmount: 1.0, + DiscountQuantity: 0.0, + DiscountAmount: 0.0, + NetQuantity: 100.0, + NetAmount: 1.0, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetAICreditUsage returned %+v, want %+v", report, want) + } + + const methodName = "GetAICreditUsage" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetAICreditUsage(ctx, "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetAICreditUsage(ctx, "o", nil) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetAICreditUsage_invalidOrg(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Billing.GetAICreditUsage(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestBillingService_GetAICreditUsage_FloatQuantities(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6, + "day": 15 + }, + "organization": "testorg", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 1500.5, + "grossAmount": 15.005, + "discountQuantity": 100.5, + "discountAmount": 1.005, + "netQuantity": 1400.0, + "netAmount": 14.0 + } + ] + }`) + }) + + ctx := t.Context() + report, _, err := client.Billing.GetAICreditUsage(ctx, "o", nil) + if err != nil { + t.Fatalf("Billing.GetAICreditUsage returned error: %v", err) + } + + want := &PremiumRequestUsageReport{ + TimePeriod: PremiumRequestUsageTimePeriod{ + Year: 2025, + Month: Ptr(6), + Day: Ptr(15), + }, + Organization: Ptr("testorg"), + UsageItems: []*PremiumRequestUsageItem{ + { + Product: "Copilot", + SKU: "Copilot AI Credits", + Model: "GPT-5", + UnitType: "credits", + PricePerUnit: 0.01, + GrossQuantity: 1500.5, + GrossAmount: 15.005, + DiscountQuantity: 100.5, + DiscountAmount: 1.005, + NetQuantity: 1400.0, + NetAmount: 14.0, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetAICreditUsage returned %+v, want %+v", report, want) + } +} From 30c0797381d0cd013340dd496d931087714cf85d Mon Sep 17 00:00:00 2001 From: maishivamhoo123 Date: Sat, 6 Jun 2026 03:08:00 +0000 Subject: [PATCH 2/5] Added GetUserAICreditUsage and added test for this Signed-off-by: maishivamhoo123 --- github/billing.go | 30 ++++++- github/billing_test.go | 191 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 206 insertions(+), 15 deletions(-) diff --git a/github/billing.go b/github/billing.go index ff1b8f2d3b2..3b8fe043cc2 100644 --- a/github/billing.go +++ b/github/billing.go @@ -393,12 +393,12 @@ func (s *BillingService) GetPremiumRequestUsageReport(ctx context.Context, user return premiumRequestUsageReport, resp, nil } -// GetAICreditUsage returns a report of the AI credit usage for an organization. +// GetOrgAICreditUsage returns a report of the AI credit usage for an organization. // // GitHub API docs: https://docs.github.com/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-an-organization // //meta:operation GET /organizations/{org}/settings/billing/ai_credit/usage -func (s *BillingService) GetAICreditUsage(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { +func (s *BillingService) GetOrgAICreditUsage(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { u := fmt.Sprintf("organizations/%v/settings/billing/ai_credit/usage", org) u, err := addOptions(u, opts) if err != nil { @@ -418,3 +418,29 @@ func (s *BillingService) GetAICreditUsage(ctx context.Context, org string, opts return aiCreditUsage, resp, nil } + +// GetUserAICreditUsage returns a report of the AI credit usage for a user. +// +// GitHub API docs: https://docs.github.com/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-a-user +// +//meta:operation GET /users/{username}/settings/billing/ai_credit/usage +func (s *BillingService) GetUserAICreditUsage(ctx context.Context, username string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { + u := fmt.Sprintf("users/%v/settings/billing/ai_credit/usage", username) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var aiCreditUsage *PremiumRequestUsageReport + resp, err := s.client.Do(req, &aiCreditUsage) + if err != nil { + return nil, resp, err + } + + return aiCreditUsage, resp, nil +} diff --git a/github/billing_test.go b/github/billing_test.go index c6ad1748a26..fc6c48fbd1c 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -721,7 +721,7 @@ func TestBillingService_PremiumRequestUsageItem_FloatQuantities(t *testing.T) { } } -func TestBillingService_GetAICreditUsage(t *testing.T) { +func TestBillingService_GetOrgAICreditUsage(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -765,9 +765,9 @@ func TestBillingService_GetAICreditUsage(t *testing.T) { Month: Ptr(6), User: Ptr("testuser"), } - report, _, err := client.Billing.GetAICreditUsage(ctx, "o", opts) + report, _, err := client.Billing.GetOrgAICreditUsage(ctx, "o", opts) if err != nil { - t.Errorf("Billing.GetAICreditUsage returned error: %v", err) + t.Errorf("Billing.GetOrgAICreditUsage returned error: %v", err) } want := &PremiumRequestUsageReport{ @@ -796,17 +796,17 @@ func TestBillingService_GetAICreditUsage(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("Billing.GetAICreditUsage returned %+v, want %+v", report, want) + t.Errorf("Billing.GetOrgAICreditUsage returned %+v, want %+v", report, want) } - const methodName = "GetAICreditUsage" + const methodName = "GetOrgAICreditUsage" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetAICreditUsage(ctx, "\n", opts) + _, _, err = client.Billing.GetOrgAICreditUsage(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetAICreditUsage(ctx, "o", nil) + got, resp, err := client.Billing.GetOrgAICreditUsage(ctx, "o", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -814,16 +814,16 @@ func TestBillingService_GetAICreditUsage(t *testing.T) { }) } -func TestBillingService_GetAICreditUsage_invalidOrg(t *testing.T) { +func TestBillingService_GetOrgAICreditUsage_invalidOrg(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Billing.GetAICreditUsage(ctx, "%", nil) + _, _, err := client.Billing.GetOrgAICreditUsage(ctx, "%", nil) testURLParseError(t, err) } -func TestBillingService_GetAICreditUsage_FloatQuantities(t *testing.T) { +func TestBillingService_GetOrgAICreditUsage_FloatQuantities(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -855,9 +855,9 @@ func TestBillingService_GetAICreditUsage_FloatQuantities(t *testing.T) { }) ctx := t.Context() - report, _, err := client.Billing.GetAICreditUsage(ctx, "o", nil) + report, _, err := client.Billing.GetOrgAICreditUsage(ctx, "o", nil) if err != nil { - t.Fatalf("Billing.GetAICreditUsage returned error: %v", err) + t.Fatalf("Billing.GetOrgAICreditUsage returned error: %v", err) } want := &PremiumRequestUsageReport{ @@ -884,6 +884,171 @@ func TestBillingService_GetAICreditUsage_FloatQuantities(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("Billing.GetAICreditUsage returned %+v, want %+v", report, want) + t.Errorf("Billing.GetOrgAICreditUsage returned %+v, want %+v", report, want) + } +} + +func TestBillingService_GetUserAICreditUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/users/u/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "6", + "user": "testuser", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6 + }, + "user": "testuser", + "product": "Copilot", + "model": "GPT-5", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 100, + "grossAmount": 1.0, + "discountQuantity": 0, + "discountAmount": 0.0, + "netQuantity": 100, + "netAmount": 1.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &PremiumRequestUsageReportOptions{ + Year: Ptr(2025), + Month: Ptr(6), + User: Ptr("testuser"), + } + report, _, err := client.Billing.GetUserAICreditUsage(ctx, "u", opts) + if err != nil { + t.Errorf("Billing.GetUserAICreditUsage returned error: %v", err) + } + + want := &PremiumRequestUsageReport{ + TimePeriod: PremiumRequestUsageTimePeriod{ + Year: 2025, + Month: Ptr(6), + }, + User: Ptr("testuser"), + Product: Ptr("Copilot"), + Model: Ptr("GPT-5"), + UsageItems: []*PremiumRequestUsageItem{ + { + Product: "Copilot", + SKU: "Copilot AI Credits", + Model: "GPT-5", + UnitType: "credits", + PricePerUnit: 0.01, + GrossQuantity: 100.0, + GrossAmount: 1.0, + DiscountQuantity: 0.0, + DiscountAmount: 0.0, + NetQuantity: 100.0, + NetAmount: 1.0, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetUserAICreditUsage returned %+v, want %+v", report, want) + } + + const methodName = "GetUserAICreditUsage" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetUserAICreditUsage(ctx, "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetUserAICreditUsage(ctx, "u", nil) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetUserAICreditUsage_invalidUser(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Billing.GetUserAICreditUsage(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestBillingService_GetUserAICreditUsage_FloatQuantities(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/users/u/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6, + "day": 15 + }, + "user": "testuser", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 1500.5, + "grossAmount": 15.005, + "discountQuantity": 100.5, + "discountAmount": 1.005, + "netQuantity": 1400.0, + "netAmount": 14.0 + } + ] + }`) + }) + + ctx := t.Context() + report, _, err := client.Billing.GetUserAICreditUsage(ctx, "u", nil) + if err != nil { + t.Fatalf("Billing.GetUserAICreditUsage returned error: %v", err) + } + + want := &PremiumRequestUsageReport{ + TimePeriod: PremiumRequestUsageTimePeriod{ + Year: 2025, + Month: Ptr(6), + Day: Ptr(15), + }, + User: Ptr("testuser"), + UsageItems: []*PremiumRequestUsageItem{ + { + Product: "Copilot", + SKU: "Copilot AI Credits", + Model: "GPT-5", + UnitType: "credits", + PricePerUnit: 0.01, + GrossQuantity: 1500.5, + GrossAmount: 15.005, + DiscountQuantity: 100.5, + DiscountAmount: 1.005, + NetQuantity: 1400.0, + NetAmount: 14.0, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetUserAICreditUsage returned %+v, want %+v", report, want) } } From 2136437ae9969a4672eb6a00067447bb5fbe3559 Mon Sep 17 00:00:00 2001 From: maishivamhoo123 Date: Mon, 8 Jun 2026 12:38:44 +0000 Subject: [PATCH 3/5] refactor: merge duplicate enterprise billing structs Signed-off-by: maishivamhoo123 --- github/enterprise_billing.go | 208 +++++++++++ github/enterprise_billing_test.go | 588 ++++++++++++++++++++++++++++++ github/github-accessors.go | 456 +++++++++++++++++++++++ github/github-accessors_test.go | 489 +++++++++++++++++++++++++ 4 files changed, 1741 insertions(+) create mode 100644 github/enterprise_billing.go create mode 100644 github/enterprise_billing_test.go diff --git a/github/enterprise_billing.go b/github/enterprise_billing.go new file mode 100644 index 00000000000..ac9f2f89160 --- /dev/null +++ b/github/enterprise_billing.go @@ -0,0 +1,208 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// EnterpriseUsageReportOptions specifies optional parameters for the BillingService.GetEnterpriseUsageReport method. +type EnterpriseUsageReportOptions struct { + Year int `url:"year,omitempty"` + Month int `url:"month,omitempty"` + Day int `url:"day,omitempty"` + CostCenterID string `url:"cost_center_id,omitempty"` +} + +// EnterprisePremiumRequestUsageReportOptions specifies optional parameters for the BillingService.GetEnterprisePremiumRequestUsageReport and BillingService.GetEnterpriseAICreditUsage methods. +type EnterprisePremiumRequestUsageReportOptions struct { + Year int `url:"year,omitempty"` + Month int `url:"month,omitempty"` + Day int `url:"day,omitempty"` + Organization string `url:"organization,omitempty"` + User string `url:"user,omitempty"` + Model string `url:"model,omitempty"` + Product string `url:"product,omitempty"` + CostCenterID string `url:"cost_center_id,omitempty"` +} + +// EnterpriseUsageSummaryOptions specifies optional parameters for the BillingService.GetEnterpriseUsageSummary method. +type EnterpriseUsageSummaryOptions struct { + Year int `url:"year,omitempty"` + Month int `url:"month,omitempty"` + Day int `url:"day,omitempty"` + Organization string `url:"organization,omitempty"` + Repository string `url:"repository,omitempty"` + Product string `url:"product,omitempty"` + SKU string `url:"sku,omitempty"` + CostCenterID string `url:"cost_center_id,omitempty"` +} + +// EnterpriseUsageTimePeriod represents a time period used in aggregated enterprise billing reports. +type EnterpriseUsageTimePeriod struct { + Year int `json:"year"` + Month *int `json:"month,omitempty"` + Day *int `json:"day,omitempty"` +} + +// EnterpriseAggregatedUsageItem represents a single usage line item in aggregated enterprise reports (premium request, AI credit, summary). +type EnterpriseAggregatedUsageItem struct { + Product string `json:"product"` + SKU string `json:"sku"` + Model *string `json:"model,omitempty"` + UnitType string `json:"unitType"` + PricePerUnit float64 `json:"pricePerUnit"` + GrossQuantity float64 `json:"grossQuantity"` + GrossAmount float64 `json:"grossAmount"` + DiscountQuantity float64 `json:"discountQuantity"` + DiscountAmount float64 `json:"discountAmount"` + NetQuantity float64 `json:"netQuantity"` + NetAmount float64 `json:"netAmount"` +} + +// EnterpriseAggregatedUsageReport represents the aggregated billing usage report response for premium request, AI credit, and summary endpoints. +type EnterpriseAggregatedUsageReport struct { + TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` + Enterprise string `json:"enterprise"` + Organization *string `json:"organization,omitempty"` + Repository *string `json:"repository,omitempty"` + User *string `json:"user,omitempty"` + Product *string `json:"product,omitempty"` + Model *string `json:"model,omitempty"` + CostCenter *BillingCostCenter `json:"costCenter,omitempty"` + UsageItems []*EnterpriseAggregatedUsageItem `json:"usageItems"` +} + +// BillingCostCenter represents a cost center reference embedded in enterprise billing usage reports. +type BillingCostCenter struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// EnterpriseUsageItem represents a single usage line item in an enterprise billing platform report. +type EnterpriseUsageItem struct { + Date string `json:"date"` + Product string `json:"product"` + SKU string `json:"sku"` + Quantity float64 `json:"quantity"` + UnitType string `json:"unitType"` + PricePerUnit float64 `json:"pricePerUnit"` + GrossAmount float64 `json:"grossAmount"` + DiscountAmount float64 `json:"discountAmount"` + NetAmount float64 `json:"netAmount"` + OrganizationName string `json:"organizationName"` + RepositoryName *string `json:"repositoryName,omitempty"` +} + +// EnterpriseUsageReport represents the enterprise billing usage report response. +type EnterpriseUsageReport struct { + UsageItems []*EnterpriseUsageItem `json:"usageItems,omitempty"` +} + +// GetEnterpriseUsageReport returns a report of the total usage for an enterprise using the enhanced billing platform. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-report-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/settings/billing/usage +func (s *BillingService) GetEnterpriseUsageReport(ctx context.Context, enterprise string, opts *EnterpriseUsageReportOptions) (*EnterpriseUsageReport, *Response, error) { + u := fmt.Sprintf("enterprises/%v/settings/billing/usage", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var report *EnterpriseUsageReport + resp, err := s.client.Do(req, &report) + if err != nil { + return nil, resp, err + } + + return report, resp, nil +} + +// GetEnterpriseUsageSummary returns a summary report of usage for an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-summary-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/settings/billing/usage/summary +func (s *BillingService) GetEnterpriseUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { + u := fmt.Sprintf("enterprises/%v/settings/billing/usage/summary", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var report *EnterpriseAggregatedUsageReport + resp, err := s.client.Do(req, &report) + if err != nil { + return nil, resp, err + } + + return report, resp, nil +} + +// GetEnterprisePremiumRequestUsageReport returns a report of the premium request usage for an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-premium-request-usage-report-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/settings/billing/premium_request/usage +func (s *BillingService) GetEnterprisePremiumRequestUsageReport(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { + u := fmt.Sprintf("enterprises/%v/settings/billing/premium_request/usage", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var report *EnterpriseAggregatedUsageReport + resp, err := s.client.Do(req, &report) + if err != nil { + return nil, resp, err + } + + return report, resp, nil +} + +// GetEnterpriseAICreditUsage returns a report of the AI credit usage for an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/settings/billing/ai_credit/usage +func (s *BillingService) GetEnterpriseAICreditUsage(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { + u := fmt.Sprintf("enterprises/%v/settings/billing/ai_credit/usage", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var report *EnterpriseAggregatedUsageReport + resp, err := s.client.Do(req, &report) + if err != nil { + return nil, resp, err + } + + return report, resp, nil +} diff --git a/github/enterprise_billing_test.go b/github/enterprise_billing_test.go new file mode 100644 index 00000000000..2a6a4f021e7 --- /dev/null +++ b/github/enterprise_billing_test.go @@ -0,0 +1,588 @@ +// Copyright 2026 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBillingService_GetEnterpriseUsageReport(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2023", + "month": "8", + }) + fmt.Fprint(w, `{ + "usageItems": [ + { + "date": "2023-08-01", + "product": "Actions", + "sku": "Actions Linux", + "quantity": 100, + "unitType": "minutes", + "pricePerUnit": 0.008, + "grossAmount": 0.8, + "discountAmount": 0, + "netAmount": 0.8, + "organizationName": "GitHub", + "repositoryName": "github/example" + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageReportOptions{ + Year: 2023, + Month: 8, + } + report, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseUsageReport returned error: %v", err) + } + + want := &EnterpriseUsageReport{ + UsageItems: []*EnterpriseUsageItem{ + { + Date: "2023-08-01", + Product: "Actions", + SKU: "Actions Linux", + Quantity: 100.0, + UnitType: "minutes", + PricePerUnit: 0.008, + GrossAmount: 0.8, + DiscountAmount: 0.0, + NetAmount: 0.8, + OrganizationName: "GitHub", + RepositoryName: Ptr("github/example"), + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("GetEnterpriseUsageReport returned %+v, want %+v", report, want) + } +} + +func TestBillingService_GetEnterpriseUsageReport_WithCostCenter(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2023", + "cost_center_id": "cc-123", + }) + fmt.Fprint(w, `{ + "usageItems": [ + { + "date": "2023-08-01", + "product": "Actions", + "sku": "Actions Linux", + "quantity": 250, + "unitType": "minutes", + "pricePerUnit": 0.008, + "grossAmount": 2.0, + "discountAmount": 0.2, + "netAmount": 1.8, + "organizationName": "GitHub" + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageReportOptions{ + Year: 2023, + CostCenterID: "cc-123", + } + report, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseUsageReport returned error: %v", err) + } + + if len(report.UsageItems) != 1 { + t.Errorf("Expected 1 usage item, got %v", len(report.UsageItems)) + } + if report.UsageItems[0].NetAmount != 1.8 { + t.Errorf("Expected NetAmount 1.8, got %v", report.UsageItems[0].NetAmount) + } +} + +func TestBillingService_GetEnterpriseUsageReport_InvalidEnterprise(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestBillingService_GetEnterpriseUsageSummary(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "product": "Actions", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "usageItems": [ + { + "product": "Actions", + "sku": "actions_linux", + "unitType": "minutes", + "pricePerUnit": 0.008, + "grossQuantity": 1000, + "grossAmount": 8, + "discountQuantity": 0, + "discountAmount": 0, + "netQuantity": 1000, + "netAmount": 8 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageSummaryOptions{ + Year: 2025, + Product: "Actions", + } + report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + } + + want := &EnterpriseAggregatedUsageReport{ + TimePeriod: EnterpriseUsageTimePeriod{ + Year: 2025, + }, + Enterprise: "GitHub", + UsageItems: []*EnterpriseAggregatedUsageItem{ + { + Product: "Actions", + SKU: "actions_linux", + UnitType: "minutes", + PricePerUnit: 0.008, + GrossQuantity: 1000.0, + GrossAmount: 8.0, + DiscountQuantity: 0.0, + DiscountAmount: 0.0, + NetQuantity: 1000.0, + NetAmount: 8.0, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("GetEnterpriseUsageSummary returned %+v, want %+v", report, want) + } +} + +func TestBillingService_GetEnterpriseUsageSummary_MultipleItems(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "usageItems": [ + { + "product": "Actions", + "sku": "actions_linux", + "unitType": "minutes", + "pricePerUnit": 0.008, + "grossQuantity": 1000, + "grossAmount": 8, + "discountQuantity": 100, + "discountAmount": 0.8, + "netQuantity": 900, + "netAmount": 7.2 + }, + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 500, + "grossAmount": 5, + "discountQuantity": 0, + "discountAmount": 0, + "netQuantity": 500, + "netAmount": 5 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageSummaryOptions{ + Year: 2025, + } + report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + } + + if len(report.UsageItems) != 2 { + t.Errorf("Expected 2 usage items, got %v", len(report.UsageItems)) + } + if report.UsageItems[0].Product != "Actions" { + t.Errorf("Expected first product to be Actions, got %v", report.UsageItems[0].Product) + } + if report.UsageItems[1].Product != "Copilot" { + t.Errorf("Expected second product to be Copilot, got %v", report.UsageItems[1].Product) + } +} + +func TestBillingService_GetEnterpriseUsageSummary_WithRepository(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "repository": "acme/api", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "usageItems": [ + { + "product": "Actions", + "sku": "actions_linux", + "unitType": "minutes", + "pricePerUnit": 0.008, + "grossQuantity": 500, + "grossAmount": 4.0, + "discountQuantity": 0, + "discountAmount": 0, + "netQuantity": 500, + "netAmount": 4.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageSummaryOptions{ + Repository: "acme/api", + } + report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + } + + if len(report.UsageItems) != 1 { + t.Errorf("Expected 1 usage item, got %v", len(report.UsageItems)) + } +} + +func TestBillingService_GetEnterprisePremiumRequestUsageReport(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "10", + "user": "testuser", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 10 + }, + "enterprise": "GitHub", + "organization": "GitHub", + "user": "testuser", + "product": "Copilot", + "model": "GPT-5", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot Premium Request", + "model": "GPT-5", + "unitType": "requests", + "pricePerUnit": 0.04, + "grossQuantity": 100, + "grossAmount": 4.0, + "discountQuantity": 0, + "discountAmount": 0.0, + "netQuantity": 100, + "netAmount": 4.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Year: 2025, + Month: 10, + User: "testuser", + } + report, _, err := client.Billing.GetEnterprisePremiumRequestUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterprisePremiumRequestUsageReport returned error: %v", err) + } + + if report.Enterprise != "GitHub" { + t.Errorf("Expected enterprise GitHub, got %v", report.Enterprise) + } + if report.User == nil || *report.User != "testuser" { + t.Errorf("Expected user testuser, got %v", report.User) + } + if len(report.UsageItems) != 1 { + t.Errorf("Expected 1 usage item, got %v", len(report.UsageItems)) + } +} + +func TestBillingService_GetEnterpriseAICreditUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "6", + "user": "testuser", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6 + }, + "enterprise": "GitHub", + "organization": "GitHub", + "user": "testuser", + "product": "Copilot", + "model": "GPT-5", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 100, + "grossAmount": 1.0, + "discountQuantity": 0, + "discountAmount": 0.0, + "netQuantity": 100, + "netAmount": 1.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Year: 2025, + Month: 6, + User: "testuser", + } + report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + } + + if report.Enterprise != "GitHub" { + t.Errorf("Expected enterprise GitHub, got %v", report.Enterprise) + } + if report.User == nil || *report.User != "testuser" { + t.Errorf("Expected user testuser, got %v", report.User) + } + if len(report.UsageItems) != 1 { + t.Errorf("Expected 1 usage item, got %v", len(report.UsageItems)) + } + if report.UsageItems[0].UnitType != "credits" { + t.Errorf("Expected unitType credits, got %v", report.UsageItems[0].UnitType) + } +} + +func TestBillingService_GetEnterpriseAICreditUsage_FloatQuantities(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "3", + "day": "15", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 3, + "day": 15 + }, + "enterprise": "testenterprise", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 1500.5, + "grossAmount": 15.005, + "discountQuantity": 100.5, + "discountAmount": 1.005, + "netQuantity": 1400.0, + "netAmount": 14.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Year: 2025, + Month: 3, + Day: 15, + } + report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Fatalf("GetEnterpriseAICreditUsage returned error: %v", err) + } + + if report.UsageItems[0].GrossQuantity != 1500.5 { + t.Errorf("Expected GrossQuantity 1500.5, got %v", report.UsageItems[0].GrossQuantity) + } + if report.UsageItems[0].NetAmount != 14.0 { + t.Errorf("Expected NetAmount 14.0, got %v", report.UsageItems[0].NetAmount) + } +} + +func TestBillingService_GetEnterpriseAICreditUsage_WithCostCenter(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "cost_center_id": "cc-engineering", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "costCenter": { + "id": "cc-engineering", + "name": "Engineering Team" + }, + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 5000, + "grossAmount": 50.0, + "discountQuantity": 500, + "discountAmount": 5.0, + "netQuantity": 4500, + "netAmount": 45.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + CostCenterID: "cc-engineering", + } + report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + } + + if report.CostCenter == nil { + t.Error("Expected CostCenter to be set") + } + if report.CostCenter.ID != "cc-engineering" { + t.Errorf("Expected CostCenter ID cc-engineering, got %v", report.CostCenter.ID) + } + if report.CostCenter.Name != "Engineering Team" { + t.Errorf("Expected CostCenter Name Engineering Team, got %v", report.CostCenter.Name) + } +} + +func TestBillingService_GetEnterpriseAICreditUsage_WithOrganization(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "organization": "acme-corp", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "organization": "acme-corp", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot AI Credits", + "model": "GPT-5", + "unitType": "credits", + "pricePerUnit": 0.01, + "grossQuantity": 2000, + "grossAmount": 20.0, + "discountQuantity": 200, + "discountAmount": 2.0, + "netQuantity": 1800, + "netAmount": 18.0 + } + ] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Organization: "acme-corp", + } + report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + } + + if report.Organization == nil || *report.Organization != "acme-corp" { + t.Errorf("Expected organization acme-corp, got %v", report.Organization) + } +} diff --git a/github/github-accessors.go b/github/github-accessors.go index bc3194bc1b6..483b3ddfd95 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2862,6 +2862,22 @@ func (b *BasicAuthTransport) GetUsername() string { return b.Username } +// GetID returns the ID field. +func (b *BillingCostCenter) GetID() string { + if b == nil { + return "" + } + return b.ID +} + +// GetName returns the Name field. +func (b *BillingCostCenter) GetName() string { + if b == nil { + return "" + } + return b.Name +} + // GetContent returns the Content field if it's non-nil, zero value otherwise. func (b *Blob) GetContent() string { if b == nil || b.Content == nil { @@ -14366,6 +14382,166 @@ func (e *Enterprise) GetWebsiteURL() string { return *e.WebsiteURL } +// GetDiscountAmount returns the DiscountAmount field. +func (e *EnterpriseAggregatedUsageItem) GetDiscountAmount() float64 { + if e == nil { + return 0 + } + return e.DiscountAmount +} + +// GetDiscountQuantity returns the DiscountQuantity field. +func (e *EnterpriseAggregatedUsageItem) GetDiscountQuantity() float64 { + if e == nil { + return 0 + } + return e.DiscountQuantity +} + +// GetGrossAmount returns the GrossAmount field. +func (e *EnterpriseAggregatedUsageItem) GetGrossAmount() float64 { + if e == nil { + return 0 + } + return e.GrossAmount +} + +// GetGrossQuantity returns the GrossQuantity field. +func (e *EnterpriseAggregatedUsageItem) GetGrossQuantity() float64 { + if e == nil { + return 0 + } + return e.GrossQuantity +} + +// GetModel returns the Model field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageItem) GetModel() string { + if e == nil || e.Model == nil { + return "" + } + return *e.Model +} + +// GetNetAmount returns the NetAmount field. +func (e *EnterpriseAggregatedUsageItem) GetNetAmount() float64 { + if e == nil { + return 0 + } + return e.NetAmount +} + +// GetNetQuantity returns the NetQuantity field. +func (e *EnterpriseAggregatedUsageItem) GetNetQuantity() float64 { + if e == nil { + return 0 + } + return e.NetQuantity +} + +// GetPricePerUnit returns the PricePerUnit field. +func (e *EnterpriseAggregatedUsageItem) GetPricePerUnit() float64 { + if e == nil { + return 0 + } + return e.PricePerUnit +} + +// GetProduct returns the Product field. +func (e *EnterpriseAggregatedUsageItem) GetProduct() string { + if e == nil { + return "" + } + return e.Product +} + +// GetSKU returns the SKU field. +func (e *EnterpriseAggregatedUsageItem) GetSKU() string { + if e == nil { + return "" + } + return e.SKU +} + +// GetUnitType returns the UnitType field. +func (e *EnterpriseAggregatedUsageItem) GetUnitType() string { + if e == nil { + return "" + } + return e.UnitType +} + +// GetCostCenter returns the CostCenter field. +func (e *EnterpriseAggregatedUsageReport) GetCostCenter() *BillingCostCenter { + if e == nil { + return nil + } + return e.CostCenter +} + +// GetEnterprise returns the Enterprise field. +func (e *EnterpriseAggregatedUsageReport) GetEnterprise() string { + if e == nil { + return "" + } + return e.Enterprise +} + +// GetModel returns the Model field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageReport) GetModel() string { + if e == nil || e.Model == nil { + return "" + } + return *e.Model +} + +// GetOrganization returns the Organization field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageReport) GetOrganization() string { + if e == nil || e.Organization == nil { + return "" + } + return *e.Organization +} + +// GetProduct returns the Product field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageReport) GetProduct() string { + if e == nil || e.Product == nil { + return "" + } + return *e.Product +} + +// GetRepository returns the Repository field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageReport) GetRepository() string { + if e == nil || e.Repository == nil { + return "" + } + return *e.Repository +} + +// GetTimePeriod returns the TimePeriod field. +func (e *EnterpriseAggregatedUsageReport) GetTimePeriod() EnterpriseUsageTimePeriod { + if e == nil { + return EnterpriseUsageTimePeriod{} + } + return e.TimePeriod +} + +// GetUsageItems returns the UsageItems slice if it's non-nil, nil otherwise. +func (e *EnterpriseAggregatedUsageReport) GetUsageItems() []*EnterpriseAggregatedUsageItem { + if e == nil || e.UsageItems == nil { + return nil + } + return e.UsageItems +} + +// GetUser returns the User field if it's non-nil, zero value otherwise. +func (e *EnterpriseAggregatedUsageReport) GetUser() string { + if e == nil || e.User == nil { + return "" + } + return *e.User +} + // GetBudgetAlerting returns the BudgetAlerting field. func (e *EnterpriseBudget) GetBudgetAlerting() *EnterpriseBudgetAlerting { if e == nil { @@ -14798,6 +14974,70 @@ func (e *EnterpriseListBudgets) GetTotalCount() int { return *e.TotalCount } +// GetCostCenterID returns the CostCenterID field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetCostCenterID() string { + if e == nil { + return "" + } + return e.CostCenterID +} + +// GetDay returns the Day field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetDay() int { + if e == nil { + return 0 + } + return e.Day +} + +// GetModel returns the Model field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetModel() string { + if e == nil { + return "" + } + return e.Model +} + +// GetMonth returns the Month field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetMonth() int { + if e == nil { + return 0 + } + return e.Month +} + +// GetOrganization returns the Organization field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetOrganization() string { + if e == nil { + return "" + } + return e.Organization +} + +// GetProduct returns the Product field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetProduct() string { + if e == nil { + return "" + } + return e.Product +} + +// GetUser returns the User field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetUser() string { + if e == nil { + return "" + } + return e.User +} + +// GetYear returns the Year field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetYear() int { + if e == nil { + return 0 + } + return e.Year +} + // GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. func (e *EnterpriseRunnerGroup) GetAllowsPublicRepositories() bool { if e == nil || e.AllowsPublicRepositories == nil { @@ -15134,6 +15374,222 @@ func (e *EnterpriseUpdateBudget) GetPreventFurtherUsage() bool { return *e.PreventFurtherUsage } +// GetDate returns the Date field. +func (e *EnterpriseUsageItem) GetDate() string { + if e == nil { + return "" + } + return e.Date +} + +// GetDiscountAmount returns the DiscountAmount field. +func (e *EnterpriseUsageItem) GetDiscountAmount() float64 { + if e == nil { + return 0 + } + return e.DiscountAmount +} + +// GetGrossAmount returns the GrossAmount field. +func (e *EnterpriseUsageItem) GetGrossAmount() float64 { + if e == nil { + return 0 + } + return e.GrossAmount +} + +// GetNetAmount returns the NetAmount field. +func (e *EnterpriseUsageItem) GetNetAmount() float64 { + if e == nil { + return 0 + } + return e.NetAmount +} + +// GetOrganizationName returns the OrganizationName field. +func (e *EnterpriseUsageItem) GetOrganizationName() string { + if e == nil { + return "" + } + return e.OrganizationName +} + +// GetPricePerUnit returns the PricePerUnit field. +func (e *EnterpriseUsageItem) GetPricePerUnit() float64 { + if e == nil { + return 0 + } + return e.PricePerUnit +} + +// GetProduct returns the Product field. +func (e *EnterpriseUsageItem) GetProduct() string { + if e == nil { + return "" + } + return e.Product +} + +// GetQuantity returns the Quantity field. +func (e *EnterpriseUsageItem) GetQuantity() float64 { + if e == nil { + return 0 + } + return e.Quantity +} + +// GetRepositoryName returns the RepositoryName field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageItem) GetRepositoryName() string { + if e == nil || e.RepositoryName == nil { + return "" + } + return *e.RepositoryName +} + +// GetSKU returns the SKU field. +func (e *EnterpriseUsageItem) GetSKU() string { + if e == nil { + return "" + } + return e.SKU +} + +// GetUnitType returns the UnitType field. +func (e *EnterpriseUsageItem) GetUnitType() string { + if e == nil { + return "" + } + return e.UnitType +} + +// GetUsageItems returns the UsageItems slice if it's non-nil, nil otherwise. +func (e *EnterpriseUsageReport) GetUsageItems() []*EnterpriseUsageItem { + if e == nil || e.UsageItems == nil { + return nil + } + return e.UsageItems +} + +// GetCostCenterID returns the CostCenterID field. +func (e *EnterpriseUsageReportOptions) GetCostCenterID() string { + if e == nil { + return "" + } + return e.CostCenterID +} + +// GetDay returns the Day field. +func (e *EnterpriseUsageReportOptions) GetDay() int { + if e == nil { + return 0 + } + return e.Day +} + +// GetMonth returns the Month field. +func (e *EnterpriseUsageReportOptions) GetMonth() int { + if e == nil { + return 0 + } + return e.Month +} + +// GetYear returns the Year field. +func (e *EnterpriseUsageReportOptions) GetYear() int { + if e == nil { + return 0 + } + return e.Year +} + +// GetCostCenterID returns the CostCenterID field. +func (e *EnterpriseUsageSummaryOptions) GetCostCenterID() string { + if e == nil { + return "" + } + return e.CostCenterID +} + +// GetDay returns the Day field. +func (e *EnterpriseUsageSummaryOptions) GetDay() int { + if e == nil { + return 0 + } + return e.Day +} + +// GetMonth returns the Month field. +func (e *EnterpriseUsageSummaryOptions) GetMonth() int { + if e == nil { + return 0 + } + return e.Month +} + +// GetOrganization returns the Organization field. +func (e *EnterpriseUsageSummaryOptions) GetOrganization() string { + if e == nil { + return "" + } + return e.Organization +} + +// GetProduct returns the Product field. +func (e *EnterpriseUsageSummaryOptions) GetProduct() string { + if e == nil { + return "" + } + return e.Product +} + +// GetRepository returns the Repository field. +func (e *EnterpriseUsageSummaryOptions) GetRepository() string { + if e == nil { + return "" + } + return e.Repository +} + +// GetSKU returns the SKU field. +func (e *EnterpriseUsageSummaryOptions) GetSKU() string { + if e == nil { + return "" + } + return e.SKU +} + +// GetYear returns the Year field. +func (e *EnterpriseUsageSummaryOptions) GetYear() int { + if e == nil { + return 0 + } + return e.Year +} + +// GetDay returns the Day field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageTimePeriod) GetDay() int { + if e == nil || e.Day == nil { + return 0 + } + return *e.Day +} + +// GetMonth returns the Month field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageTimePeriod) GetMonth() int { + if e == nil || e.Month == nil { + return 0 + } + return *e.Month +} + +// GetYear returns the Year field. +func (e *EnterpriseUsageTimePeriod) GetYear() int { + if e == nil { + return 0 + } + return e.Year +} + // GetCanAdminsBypass returns the CanAdminsBypass field if it's non-nil, zero value otherwise. func (e *Environment) GetCanAdminsBypass() bool { if e == nil || e.CanAdminsBypass == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c9ced173fe0..1ed9219362d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -3637,6 +3637,22 @@ func TestBasicAuthTransport_GetUsername(tt *testing.T) { b.GetUsername() } +func TestBillingCostCenter_GetID(tt *testing.T) { + tt.Parallel() + b := &BillingCostCenter{} + b.GetID() + b = nil + b.GetID() +} + +func TestBillingCostCenter_GetName(tt *testing.T) { + tt.Parallel() + b := &BillingCostCenter{} + b.GetName() + b = nil + b.GetName() +} + func TestBlob_GetContent(tt *testing.T) { tt.Parallel() var zeroValue string @@ -18195,6 +18211,187 @@ func TestEnterprise_GetWebsiteURL(tt *testing.T) { e.GetWebsiteURL() } +func TestEnterpriseAggregatedUsageItem_GetDiscountAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetDiscountAmount() + e = nil + e.GetDiscountAmount() +} + +func TestEnterpriseAggregatedUsageItem_GetDiscountQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetDiscountQuantity() + e = nil + e.GetDiscountQuantity() +} + +func TestEnterpriseAggregatedUsageItem_GetGrossAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetGrossAmount() + e = nil + e.GetGrossAmount() +} + +func TestEnterpriseAggregatedUsageItem_GetGrossQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetGrossQuantity() + e = nil + e.GetGrossQuantity() +} + +func TestEnterpriseAggregatedUsageItem_GetModel(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageItem{Model: &zeroValue} + e.GetModel() + e = &EnterpriseAggregatedUsageItem{} + e.GetModel() + e = nil + e.GetModel() +} + +func TestEnterpriseAggregatedUsageItem_GetNetAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetNetAmount() + e = nil + e.GetNetAmount() +} + +func TestEnterpriseAggregatedUsageItem_GetNetQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetNetQuantity() + e = nil + e.GetNetQuantity() +} + +func TestEnterpriseAggregatedUsageItem_GetPricePerUnit(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetPricePerUnit() + e = nil + e.GetPricePerUnit() +} + +func TestEnterpriseAggregatedUsageItem_GetProduct(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseAggregatedUsageItem_GetSKU(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetSKU() + e = nil + e.GetSKU() +} + +func TestEnterpriseAggregatedUsageItem_GetUnitType(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageItem{} + e.GetUnitType() + e = nil + e.GetUnitType() +} + +func TestEnterpriseAggregatedUsageReport_GetCostCenter(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageReport{} + e.GetCostCenter() + e = nil + e.GetCostCenter() +} + +func TestEnterpriseAggregatedUsageReport_GetEnterprise(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageReport{} + e.GetEnterprise() + e = nil + e.GetEnterprise() +} + +func TestEnterpriseAggregatedUsageReport_GetModel(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageReport{Model: &zeroValue} + e.GetModel() + e = &EnterpriseAggregatedUsageReport{} + e.GetModel() + e = nil + e.GetModel() +} + +func TestEnterpriseAggregatedUsageReport_GetOrganization(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageReport{Organization: &zeroValue} + e.GetOrganization() + e = &EnterpriseAggregatedUsageReport{} + e.GetOrganization() + e = nil + e.GetOrganization() +} + +func TestEnterpriseAggregatedUsageReport_GetProduct(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageReport{Product: &zeroValue} + e.GetProduct() + e = &EnterpriseAggregatedUsageReport{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseAggregatedUsageReport_GetRepository(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageReport{Repository: &zeroValue} + e.GetRepository() + e = &EnterpriseAggregatedUsageReport{} + e.GetRepository() + e = nil + e.GetRepository() +} + +func TestEnterpriseAggregatedUsageReport_GetTimePeriod(tt *testing.T) { + tt.Parallel() + e := &EnterpriseAggregatedUsageReport{} + e.GetTimePeriod() + e = nil + e.GetTimePeriod() +} + +func TestEnterpriseAggregatedUsageReport_GetUsageItems(tt *testing.T) { + tt.Parallel() + zeroValue := []*EnterpriseAggregatedUsageItem{} + e := &EnterpriseAggregatedUsageReport{UsageItems: zeroValue} + e.GetUsageItems() + e = &EnterpriseAggregatedUsageReport{} + e.GetUsageItems() + e = nil + e.GetUsageItems() +} + +func TestEnterpriseAggregatedUsageReport_GetUser(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseAggregatedUsageReport{User: &zeroValue} + e.GetUser() + e = &EnterpriseAggregatedUsageReport{} + e.GetUser() + e = nil + e.GetUser() +} + func TestEnterpriseBudget_GetBudgetAlerting(tt *testing.T) { tt.Parallel() e := &EnterpriseBudget{} @@ -18729,6 +18926,70 @@ func TestEnterpriseListBudgets_GetTotalCount(tt *testing.T) { e.GetTotalCount() } +func TestEnterprisePremiumRequestUsageReportOptions_GetCostCenterID(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetCostCenterID() + e = nil + e.GetCostCenterID() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetDay(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetDay() + e = nil + e.GetDay() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetModel(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetModel() + e = nil + e.GetModel() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetMonth(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetMonth() + e = nil + e.GetMonth() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetOrganization(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetOrganization() + e = nil + e.GetOrganization() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetProduct(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetUser(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetUser() + e = nil + e.GetUser() +} + +func TestEnterprisePremiumRequestUsageReportOptions_GetYear(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetYear() + e = nil + e.GetYear() +} + func TestEnterpriseRunnerGroup_GetAllowsPublicRepositories(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -19158,6 +19419,234 @@ func TestEnterpriseUpdateBudget_GetPreventFurtherUsage(tt *testing.T) { e.GetPreventFurtherUsage() } +func TestEnterpriseUsageItem_GetDate(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetDate() + e = nil + e.GetDate() +} + +func TestEnterpriseUsageItem_GetDiscountAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetDiscountAmount() + e = nil + e.GetDiscountAmount() +} + +func TestEnterpriseUsageItem_GetGrossAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetGrossAmount() + e = nil + e.GetGrossAmount() +} + +func TestEnterpriseUsageItem_GetNetAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetNetAmount() + e = nil + e.GetNetAmount() +} + +func TestEnterpriseUsageItem_GetOrganizationName(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetOrganizationName() + e = nil + e.GetOrganizationName() +} + +func TestEnterpriseUsageItem_GetPricePerUnit(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetPricePerUnit() + e = nil + e.GetPricePerUnit() +} + +func TestEnterpriseUsageItem_GetProduct(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseUsageItem_GetQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetQuantity() + e = nil + e.GetQuantity() +} + +func TestEnterpriseUsageItem_GetRepositoryName(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseUsageItem{RepositoryName: &zeroValue} + e.GetRepositoryName() + e = &EnterpriseUsageItem{} + e.GetRepositoryName() + e = nil + e.GetRepositoryName() +} + +func TestEnterpriseUsageItem_GetSKU(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetSKU() + e = nil + e.GetSKU() +} + +func TestEnterpriseUsageItem_GetUnitType(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageItem{} + e.GetUnitType() + e = nil + e.GetUnitType() +} + +func TestEnterpriseUsageReport_GetUsageItems(tt *testing.T) { + tt.Parallel() + zeroValue := []*EnterpriseUsageItem{} + e := &EnterpriseUsageReport{UsageItems: zeroValue} + e.GetUsageItems() + e = &EnterpriseUsageReport{} + e.GetUsageItems() + e = nil + e.GetUsageItems() +} + +func TestEnterpriseUsageReportOptions_GetCostCenterID(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageReportOptions{} + e.GetCostCenterID() + e = nil + e.GetCostCenterID() +} + +func TestEnterpriseUsageReportOptions_GetDay(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageReportOptions{} + e.GetDay() + e = nil + e.GetDay() +} + +func TestEnterpriseUsageReportOptions_GetMonth(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageReportOptions{} + e.GetMonth() + e = nil + e.GetMonth() +} + +func TestEnterpriseUsageReportOptions_GetYear(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageReportOptions{} + e.GetYear() + e = nil + e.GetYear() +} + +func TestEnterpriseUsageSummaryOptions_GetCostCenterID(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetCostCenterID() + e = nil + e.GetCostCenterID() +} + +func TestEnterpriseUsageSummaryOptions_GetDay(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetDay() + e = nil + e.GetDay() +} + +func TestEnterpriseUsageSummaryOptions_GetMonth(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetMonth() + e = nil + e.GetMonth() +} + +func TestEnterpriseUsageSummaryOptions_GetOrganization(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetOrganization() + e = nil + e.GetOrganization() +} + +func TestEnterpriseUsageSummaryOptions_GetProduct(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseUsageSummaryOptions_GetRepository(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetRepository() + e = nil + e.GetRepository() +} + +func TestEnterpriseUsageSummaryOptions_GetSKU(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetSKU() + e = nil + e.GetSKU() +} + +func TestEnterpriseUsageSummaryOptions_GetYear(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryOptions{} + e.GetYear() + e = nil + e.GetYear() +} + +func TestEnterpriseUsageTimePeriod_GetDay(tt *testing.T) { + tt.Parallel() + var zeroValue int + e := &EnterpriseUsageTimePeriod{Day: &zeroValue} + e.GetDay() + e = &EnterpriseUsageTimePeriod{} + e.GetDay() + e = nil + e.GetDay() +} + +func TestEnterpriseUsageTimePeriod_GetMonth(tt *testing.T) { + tt.Parallel() + var zeroValue int + e := &EnterpriseUsageTimePeriod{Month: &zeroValue} + e.GetMonth() + e = &EnterpriseUsageTimePeriod{} + e.GetMonth() + e = nil + e.GetMonth() +} + +func TestEnterpriseUsageTimePeriod_GetYear(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageTimePeriod{} + e.GetYear() + e = nil + e.GetYear() +} + func TestEnvironment_GetCanAdminsBypass(tt *testing.T) { tt.Parallel() var zeroValue bool From dc880428e29b3c9a4f92d6b654930a4831fc2b35 Mon Sep 17 00:00:00 2001 From: maishivamhoo123 Date: Tue, 9 Jun 2026 11:59:20 +0000 Subject: [PATCH 4/5] Added all the Recommended changes Signed-off-by: maishivamhoo123 --- github/enterprise_billing.go | 16 +- github/enterprise_billing_test.go | 498 ++++++++++++++++++++++++++++-- 2 files changed, 472 insertions(+), 42 deletions(-) diff --git a/github/enterprise_billing.go b/github/enterprise_billing.go index ac9f2f89160..7cb457a498d 100644 --- a/github/enterprise_billing.go +++ b/github/enterprise_billing.go @@ -103,12 +103,12 @@ type EnterpriseUsageReport struct { UsageItems []*EnterpriseUsageItem `json:"usageItems,omitempty"` } -// GetEnterpriseUsageReport returns a report of the total usage for an enterprise using the enhanced billing platform. +// GetUsageReport returns a report of the total usage for an enterprise using the enhanced billing platform. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-report-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/settings/billing/usage -func (s *BillingService) GetEnterpriseUsageReport(ctx context.Context, enterprise string, opts *EnterpriseUsageReportOptions) (*EnterpriseUsageReport, *Response, error) { +func (s *EnterpriseService) GetUsageReport(ctx context.Context, enterprise string, opts *EnterpriseUsageReportOptions) (*EnterpriseUsageReport, *Response, error) { u := fmt.Sprintf("enterprises/%v/settings/billing/usage", enterprise) u, err := addOptions(u, opts) if err != nil { @@ -129,12 +129,12 @@ func (s *BillingService) GetEnterpriseUsageReport(ctx context.Context, enterpris return report, resp, nil } -// GetEnterpriseUsageSummary returns a summary report of usage for an enterprise. +// GetUsageSummary returns a summary report of usage for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-summary-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/settings/billing/usage/summary -func (s *BillingService) GetEnterpriseUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { +func (s *EnterpriseService) GetUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { u := fmt.Sprintf("enterprises/%v/settings/billing/usage/summary", enterprise) u, err := addOptions(u, opts) if err != nil { @@ -155,12 +155,12 @@ func (s *BillingService) GetEnterpriseUsageSummary(ctx context.Context, enterpri return report, resp, nil } -// GetEnterprisePremiumRequestUsageReport returns a report of the premium request usage for an enterprise. +// GetPremiumRequestUsageReport returns a report of the premium request usage for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-premium-request-usage-report-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/settings/billing/premium_request/usage -func (s *BillingService) GetEnterprisePremiumRequestUsageReport(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { +func (s *EnterpriseService) GetPremiumRequestUsageReport(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { u := fmt.Sprintf("enterprises/%v/settings/billing/premium_request/usage", enterprise) u, err := addOptions(u, opts) if err != nil { @@ -181,12 +181,12 @@ func (s *BillingService) GetEnterprisePremiumRequestUsageReport(ctx context.Cont return report, resp, nil } -// GetEnterpriseAICreditUsage returns a report of the AI credit usage for an enterprise. +// GetAICreditUsage returns a report of the AI credit usage for an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/settings/billing/ai_credit/usage -func (s *BillingService) GetEnterpriseAICreditUsage(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { +func (s *EnterpriseService) GetAICreditUsage(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { u := fmt.Sprintf("enterprises/%v/settings/billing/ai_credit/usage", enterprise) u, err := addOptions(u, opts) if err != nil { diff --git a/github/enterprise_billing_test.go b/github/enterprise_billing_test.go index 2a6a4f021e7..af993613ff5 100644 --- a/github/enterprise_billing_test.go +++ b/github/enterprise_billing_test.go @@ -6,6 +6,7 @@ package github import ( + "context" "fmt" "net/http" "testing" @@ -13,7 +14,7 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestBillingService_GetEnterpriseUsageReport(t *testing.T) { +func TestEnterpriseService_GetUsageReport(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -47,9 +48,13 @@ func TestBillingService_GetEnterpriseUsageReport(t *testing.T) { Year: 2023, Month: 8, } - report, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseUsageReport returned error: %v", err) + t.Errorf("GetUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageReport returned nil response") } want := &EnterpriseUsageReport{ @@ -70,11 +75,11 @@ func TestBillingService_GetEnterpriseUsageReport(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("GetEnterpriseUsageReport returned %+v, want %+v", report, want) + t.Errorf("GetUsageReport returned %+v, want %+v", report, want) } } -func TestBillingService_GetEnterpriseUsageReport_WithCostCenter(t *testing.T) { +func TestEnterpriseService_GetUsageReport_WithCostCenter(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -107,9 +112,13 @@ func TestBillingService_GetEnterpriseUsageReport_WithCostCenter(t *testing.T) { Year: 2023, CostCenterID: "cc-123", } - report, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseUsageReport returned error: %v", err) + t.Errorf("GetUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageReport returned nil response") } if len(report.UsageItems) != 1 { @@ -120,16 +129,74 @@ func TestBillingService_GetEnterpriseUsageReport_WithCostCenter(t *testing.T) { } } -func TestBillingService_GetEnterpriseUsageReport_InvalidEnterprise(t *testing.T) { +func TestEnterpriseService_GetUsageReport_InvalidEnterprise(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Billing.GetEnterpriseUsageReport(ctx, "%", nil) + _, _, err := client.Enterprise.GetUsageReport(ctx, "%", nil) testURLParseError(t, err) } -func TestBillingService_GetEnterpriseUsageSummary(t *testing.T) { +func TestEnterpriseService_GetUsageReport_NoOptions(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"usageItems": []}`) + }) + + ctx := t.Context() + report, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", nil) + if err != nil { + t.Errorf("GetUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageReport returned nil response") + } + + if report == nil || len(report.UsageItems) != 0 { + t.Error("Expected empty usage items") + } +} + +func TestEnterpriseService_GetUsageReport_APIError(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusForbidden) + fmt.Fprint(w, `{"message": "Forbidden"}`) + }) + + ctx := t.Context() + _, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetUsageReport should return error on 403 response") + } + if resp == nil { + t.Error("GetUsageReport should return response even on error") + } +} + +func TestEnterpriseService_GetUsageReport_CanceledContext(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx, cancel := context.WithCancel(t.Context()) + cancel() + + _, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetUsageReport should return error with canceled context") + } + _ = resp +} + +func TestEnterpriseService_GetUsageSummary(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -166,9 +233,13 @@ func TestBillingService_GetEnterpriseUsageSummary(t *testing.T) { Year: 2025, Product: "Actions", } - report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + t.Errorf("GetUsageSummary returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageSummary returned nil response") } want := &EnterpriseAggregatedUsageReport{ @@ -192,11 +263,11 @@ func TestBillingService_GetEnterpriseUsageSummary(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("GetEnterpriseUsageSummary returned %+v, want %+v", report, want) + t.Errorf("GetUsageSummary returned %+v, want %+v", report, want) } } -func TestBillingService_GetEnterpriseUsageSummary_MultipleItems(t *testing.T) { +func TestEnterpriseService_GetUsageSummary_MultipleItems(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -243,9 +314,13 @@ func TestBillingService_GetEnterpriseUsageSummary_MultipleItems(t *testing.T) { opts := &EnterpriseUsageSummaryOptions{ Year: 2025, } - report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + t.Errorf("GetUsageSummary returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageSummary returned nil response") } if len(report.UsageItems) != 2 { @@ -259,7 +334,7 @@ func TestBillingService_GetEnterpriseUsageSummary_MultipleItems(t *testing.T) { } } -func TestBillingService_GetEnterpriseUsageSummary_WithRepository(t *testing.T) { +func TestEnterpriseService_GetUsageSummary_WithRepository(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -273,6 +348,7 @@ func TestBillingService_GetEnterpriseUsageSummary_WithRepository(t *testing.T) { "year": 2025 }, "enterprise": "GitHub", + "repository": "acme/api", "usageItems": [ { "product": "Actions", @@ -294,9 +370,13 @@ func TestBillingService_GetEnterpriseUsageSummary_WithRepository(t *testing.T) { opts := &EnterpriseUsageSummaryOptions{ Repository: "acme/api", } - report, _, err := client.Billing.GetEnterpriseUsageSummary(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseUsageSummary returned error: %v", err) + t.Errorf("GetUsageSummary returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageSummary returned nil response") } if len(report.UsageItems) != 1 { @@ -304,7 +384,105 @@ func TestBillingService_GetEnterpriseUsageSummary_WithRepository(t *testing.T) { } } -func TestBillingService_GetEnterprisePremiumRequestUsageReport(t *testing.T) { +func TestEnterpriseService_GetUsageSummary_WithAllFilters(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "6", + "day": "15", + "organization": "acme", + "repository": "acme/api", + "product": "Actions", + "sku": "actions_linux", + "cost_center_id": "cc-001", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 6, + "day": 15 + }, + "enterprise": "GitHub", + "organization": "acme", + "repository": "acme/api", + "product": "Actions", + "usageItems": [] + }`) + }) + + ctx := t.Context() + opts := &EnterpriseUsageSummaryOptions{ + Year: 2025, + Month: 6, + Day: 15, + Organization: "acme", + Repository: "acme/api", + Product: "Actions", + SKU: "actions_linux", + CostCenterID: "cc-001", + } + report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetUsageSummary returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageSummary returned nil response") + } + + if report == nil { + t.Error("Expected non-nil report") + } +} + +func TestEnterpriseService_GetUsageSummary_InvalidEnterprise(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Enterprise.GetUsageSummary(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestEnterpriseService_GetUsageSummary_APIError(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusNotFound) + fmt.Fprint(w, `{"message": "Not Found"}`) + }) + + ctx := t.Context() + _, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetUsageSummary should return error on 404 response") + } + if resp == nil { + t.Error("GetUsageSummary should return response even on error") + } +} + +func TestEnterpriseService_GetUsageSummary_CanceledContext(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx, cancel := context.WithCancel(t.Context()) + cancel() + + _, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetUsageSummary should return error with canceled context") + } + _ = resp +} + +func TestEnterpriseService_GetPremiumRequestUsageReport(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -349,9 +527,13 @@ func TestBillingService_GetEnterprisePremiumRequestUsageReport(t *testing.T) { Month: 10, User: "testuser", } - report, _, err := client.Billing.GetEnterprisePremiumRequestUsageReport(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterprisePremiumRequestUsageReport returned error: %v", err) + t.Errorf("GetPremiumRequestUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetPremiumRequestUsageReport returned nil response") } if report.Enterprise != "GitHub" { @@ -365,7 +547,106 @@ func TestBillingService_GetEnterprisePremiumRequestUsageReport(t *testing.T) { } } -func TestBillingService_GetEnterpriseAICreditUsage(t *testing.T) { +func TestEnterpriseService_GetPremiumRequestUsageReport_WithAllOptions(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "5", + "day": "10", + "organization": "acme-org", + "user": "alice", + "model": "GPT-4", + "product": "Copilot", + "cost_center_id": "cc-sales", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 5, + "day": 10 + }, + "enterprise": "GitHub", + "organization": "acme-org", + "user": "alice", + "product": "Copilot", + "model": "GPT-4", + "usageItems": [] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Year: 2025, + Month: 5, + Day: 10, + Organization: "acme-org", + User: "alice", + Model: "GPT-4", + Product: "Copilot", + CostCenterID: "cc-sales", + } + report, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetPremiumRequestUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetPremiumRequestUsageReport returned nil response") + } + + if report == nil { + t.Error("Expected non-nil report") + } +} + +func TestEnterpriseService_GetPremiumRequestUsageReport_InvalidEnterprise(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestEnterpriseService_GetPremiumRequestUsageReport_APIError(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusUnauthorized) + fmt.Fprint(w, `{"message": "Unauthorized"}`) + }) + + ctx := t.Context() + _, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetPremiumRequestUsageReport should return error on 401 response") + } + if resp == nil { + t.Error("GetPremiumRequestUsageReport should return response even on error") + } +} + +func TestEnterpriseService_GetPremiumRequestUsageReport_CanceledContext(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx, cancel := context.WithCancel(t.Context()) + cancel() + + _, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetPremiumRequestUsageReport should return error with canceled context") + } + _ = resp +} + +func TestEnterpriseService_GetAICreditUsage(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -410,9 +691,13 @@ func TestBillingService_GetEnterpriseAICreditUsage(t *testing.T) { Month: 6, User: "testuser", } - report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + t.Errorf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") } if report.Enterprise != "GitHub" { @@ -429,7 +714,7 @@ func TestBillingService_GetEnterpriseAICreditUsage(t *testing.T) { } } -func TestBillingService_GetEnterpriseAICreditUsage_FloatQuantities(t *testing.T) { +func TestEnterpriseService_GetAICreditUsage_FloatQuantities(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -471,9 +756,13 @@ func TestBillingService_GetEnterpriseAICreditUsage_FloatQuantities(t *testing.T) Month: 3, Day: 15, } - report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { - t.Fatalf("GetEnterpriseAICreditUsage returned error: %v", err) + t.Fatalf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") } if report.UsageItems[0].GrossQuantity != 1500.5 { @@ -484,7 +773,7 @@ func TestBillingService_GetEnterpriseAICreditUsage_FloatQuantities(t *testing.T) } } -func TestBillingService_GetEnterpriseAICreditUsage_WithCostCenter(t *testing.T) { +func TestEnterpriseService_GetAICreditUsage_WithCostCenter(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -524,9 +813,13 @@ func TestBillingService_GetEnterpriseAICreditUsage_WithCostCenter(t *testing.T) opts := &EnterprisePremiumRequestUsageReportOptions{ CostCenterID: "cc-engineering", } - report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + t.Errorf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") } if report.CostCenter == nil { @@ -540,7 +833,7 @@ func TestBillingService_GetEnterpriseAICreditUsage_WithCostCenter(t *testing.T) } } -func TestBillingService_GetEnterpriseAICreditUsage_WithOrganization(t *testing.T) { +func TestEnterpriseService_GetAICreditUsage_WithOrganization(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -577,12 +870,149 @@ func TestBillingService_GetEnterpriseAICreditUsage_WithOrganization(t *testing.T opts := &EnterprisePremiumRequestUsageReportOptions{ Organization: "acme-corp", } - report, _, err := client.Billing.GetEnterpriseAICreditUsage(ctx, "test-enterprise", opts) + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { - t.Errorf("GetEnterpriseAICreditUsage returned error: %v", err) + t.Errorf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") } if report.Organization == nil || *report.Organization != "acme-corp" { t.Errorf("Expected organization acme-corp, got %v", report.Organization) } } + +func TestEnterpriseService_GetAICreditUsage_InvalidEnterprise(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Enterprise.GetAICreditUsage(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestEnterpriseService_GetAICreditUsage_APIError(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusBadRequest) + fmt.Fprint(w, `{"message": "Bad Request"}`) + }) + + ctx := t.Context() + _, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetAICreditUsage should return error on 400 response") + } + if resp == nil { + t.Error("GetAICreditUsage should return response even on error") + } +} + +func TestEnterpriseService_GetAICreditUsage_NoItems(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025 + }, + "enterprise": "GitHub", + "usageItems": [] + }`) + }) + + ctx := t.Context() + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", nil) + if err != nil { + t.Errorf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") + } + + if len(report.UsageItems) != 0 { + t.Errorf("Expected 0 usage items, got %v", len(report.UsageItems)) + } +} + +func TestEnterpriseService_GetAICreditUsage_CanceledContext(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx, cancel := context.WithCancel(t.Context()) + cancel() + + _, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", nil) + if err == nil { + t.Error("GetAICreditUsage should return error with canceled context") + } + _ = resp +} + +func TestEnterpriseService_GetAICreditUsage_WithAllOptions(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/test-enterprise/settings/billing/ai_credit/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "month": "2", + "day": "28", + "organization": "tech-org", + "user": "bob", + "model": "GPT-4", + "product": "Copilot", + "cost_center_id": "cc-dev", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "month": 2, + "day": 28 + }, + "enterprise": "GitHub", + "organization": "tech-org", + "user": "bob", + "product": "Copilot", + "model": "GPT-4", + "costCenter": { + "id": "cc-dev", + "name": "Development Team" + }, + "usageItems": [] + }`) + }) + + ctx := t.Context() + opts := &EnterprisePremiumRequestUsageReportOptions{ + Year: 2025, + Month: 2, + Day: 28, + Organization: "tech-org", + User: "bob", + Model: "GPT-4", + Product: "Copilot", + CostCenterID: "cc-dev", + } + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") + } + + if report == nil { + t.Error("Expected non-nil report") + } +} From e942927e9ebbd46c9420fe08381b6c1e06d68a30 Mon Sep 17 00:00:00 2001 From: maishivamhoo123 Date: Wed, 10 Jun 2026 11:58:12 +0000 Subject: [PATCH 5/5] Added all the recommended chnages Signed-off-by: maishivamhoo123 --- github/enterprise_billing.go | 51 +++++--- github/enterprise_billing_test.go | 106 +++++----------- github/github-accessors.go | 180 ++++++++++++++++++-------- github/github-accessors_test.go | 202 +++++++++++++++++++++--------- 4 files changed, 333 insertions(+), 206 deletions(-) diff --git a/github/enterprise_billing.go b/github/enterprise_billing.go index 7cb457a498d..7f02a0343f7 100644 --- a/github/enterprise_billing.go +++ b/github/enterprise_billing.go @@ -10,7 +10,7 @@ import ( "fmt" ) -// EnterpriseUsageReportOptions specifies optional parameters for the BillingService.GetEnterpriseUsageReport method. +// EnterpriseUsageReportOptions specifies optional parameters for the EnterpriseService.GetUsageReport method. type EnterpriseUsageReportOptions struct { Year int `url:"year,omitempty"` Month int `url:"month,omitempty"` @@ -18,28 +18,22 @@ type EnterpriseUsageReportOptions struct { CostCenterID string `url:"cost_center_id,omitempty"` } -// EnterprisePremiumRequestUsageReportOptions specifies optional parameters for the BillingService.GetEnterprisePremiumRequestUsageReport and BillingService.GetEnterpriseAICreditUsage methods. +// EnterprisePremiumRequestUsageReportOptions specifies optional parameters for the EnterpriseService.GetPremiumRequestUsageReport and EnterpriseService.GetAICreditUsage methods. type EnterprisePremiumRequestUsageReportOptions struct { - Year int `url:"year,omitempty"` - Month int `url:"month,omitempty"` - Day int `url:"day,omitempty"` + EnterpriseUsageReportOptions Organization string `url:"organization,omitempty"` User string `url:"user,omitempty"` Model string `url:"model,omitempty"` Product string `url:"product,omitempty"` - CostCenterID string `url:"cost_center_id,omitempty"` } -// EnterpriseUsageSummaryOptions specifies optional parameters for the BillingService.GetEnterpriseUsageSummary method. +// EnterpriseUsageSummaryOptions specifies optional parameters for the EnterpriseService.GetUsageSummary method. type EnterpriseUsageSummaryOptions struct { - Year int `url:"year,omitempty"` - Month int `url:"month,omitempty"` - Day int `url:"day,omitempty"` + EnterpriseUsageReportOptions Organization string `url:"organization,omitempty"` Repository string `url:"repository,omitempty"` Product string `url:"product,omitempty"` SKU string `url:"sku,omitempty"` - CostCenterID string `url:"cost_center_id,omitempty"` } // EnterpriseUsageTimePeriod represents a time period used in aggregated enterprise billing reports. @@ -49,7 +43,7 @@ type EnterpriseUsageTimePeriod struct { Day *int `json:"day,omitempty"` } -// EnterpriseAggregatedUsageItem represents a single usage line item in aggregated enterprise reports (premium request, AI credit, summary). +// EnterpriseAggregatedUsageItem represents a single usage line item in an enterprise billing premium request or AI credit report. type EnterpriseAggregatedUsageItem struct { Product string `json:"product"` SKU string `json:"sku"` @@ -64,12 +58,11 @@ type EnterpriseAggregatedUsageItem struct { NetAmount float64 `json:"netAmount"` } -// EnterpriseAggregatedUsageReport represents the aggregated billing usage report response for premium request, AI credit, and summary endpoints. +// EnterpriseAggregatedUsageReport represents the aggregated billing usage report response for the premium request and AI credit endpoints. type EnterpriseAggregatedUsageReport struct { TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` Enterprise string `json:"enterprise"` Organization *string `json:"organization,omitempty"` - Repository *string `json:"repository,omitempty"` User *string `json:"user,omitempty"` Product *string `json:"product,omitempty"` Model *string `json:"model,omitempty"` @@ -77,6 +70,32 @@ type EnterpriseAggregatedUsageReport struct { UsageItems []*EnterpriseAggregatedUsageItem `json:"usageItems"` } +// EnterpriseUsageSummaryItem represents a single usage line item in an enterprise billing usage summary report. +type EnterpriseUsageSummaryItem struct { + Product string `json:"product"` + SKU string `json:"sku"` + UnitType string `json:"unitType"` + PricePerUnit float64 `json:"pricePerUnit"` + GrossQuantity float64 `json:"grossQuantity"` + GrossAmount float64 `json:"grossAmount"` + DiscountQuantity float64 `json:"discountQuantity"` + DiscountAmount float64 `json:"discountAmount"` + NetQuantity float64 `json:"netQuantity"` + NetAmount float64 `json:"netAmount"` +} + +// EnterpriseUsageSummaryReport represents the billing usage summary report response for the EnterpriseService.GetUsageSummary endpoint. +type EnterpriseUsageSummaryReport struct { + TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` + Enterprise string `json:"enterprise"` + Organization *string `json:"organization,omitempty"` + Repository *string `json:"repository,omitempty"` + Product *string `json:"product,omitempty"` + SKU *string `json:"sku,omitempty"` + CostCenter *BillingCostCenter `json:"costCenter,omitempty"` + UsageItems []*EnterpriseUsageSummaryItem `json:"usageItems"` +} + // BillingCostCenter represents a cost center reference embedded in enterprise billing usage reports. type BillingCostCenter struct { ID string `json:"id"` @@ -134,7 +153,7 @@ func (s *EnterpriseService) GetUsageReport(ctx context.Context, enterprise strin // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-summary-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/settings/billing/usage/summary -func (s *EnterpriseService) GetUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { +func (s *EnterpriseService) GetUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseUsageSummaryReport, *Response, error) { u := fmt.Sprintf("enterprises/%v/settings/billing/usage/summary", enterprise) u, err := addOptions(u, opts) if err != nil { @@ -146,7 +165,7 @@ func (s *EnterpriseService) GetUsageSummary(ctx context.Context, enterprise stri return nil, nil, err } - var report *EnterpriseAggregatedUsageReport + var report *EnterpriseUsageSummaryReport resp, err := s.client.Do(req, &report) if err != nil { return nil, resp, err diff --git a/github/enterprise_billing_test.go b/github/enterprise_billing_test.go index af993613ff5..596eb849b96 100644 --- a/github/enterprise_billing_test.go +++ b/github/enterprise_billing_test.go @@ -230,8 +230,8 @@ func TestEnterpriseService_GetUsageSummary(t *testing.T) { ctx := t.Context() opts := &EnterpriseUsageSummaryOptions{ - Year: 2025, - Product: "Actions", + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025}, + Product: "Actions", } report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { @@ -242,12 +242,12 @@ func TestEnterpriseService_GetUsageSummary(t *testing.T) { t.Error("GetUsageSummary returned nil response") } - want := &EnterpriseAggregatedUsageReport{ + want := &EnterpriseUsageSummaryReport{ TimePeriod: EnterpriseUsageTimePeriod{ Year: 2025, }, Enterprise: "GitHub", - UsageItems: []*EnterpriseAggregatedUsageItem{ + UsageItems: []*EnterpriseUsageSummaryItem{ { Product: "Actions", SKU: "actions_linux", @@ -312,7 +312,7 @@ func TestEnterpriseService_GetUsageSummary_MultipleItems(t *testing.T) { ctx := t.Context() opts := &EnterpriseUsageSummaryOptions{ - Year: 2025, + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025}, } report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { @@ -334,56 +334,6 @@ func TestEnterpriseService_GetUsageSummary_MultipleItems(t *testing.T) { } } -func TestEnterpriseService_GetUsageSummary_WithRepository(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/test-enterprise/settings/billing/usage/summary", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - testFormValues(t, r, values{ - "repository": "acme/api", - }) - fmt.Fprint(w, `{ - "timePeriod": { - "year": 2025 - }, - "enterprise": "GitHub", - "repository": "acme/api", - "usageItems": [ - { - "product": "Actions", - "sku": "actions_linux", - "unitType": "minutes", - "pricePerUnit": 0.008, - "grossQuantity": 500, - "grossAmount": 4.0, - "discountQuantity": 0, - "discountAmount": 0, - "netQuantity": 500, - "netAmount": 4.0 - } - ] - }`) - }) - - ctx := t.Context() - opts := &EnterpriseUsageSummaryOptions{ - Repository: "acme/api", - } - report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) - if err != nil { - t.Errorf("GetUsageSummary returned error: %v", err) - } - - if resp == nil { - t.Error("GetUsageSummary returned nil response") - } - - if len(report.UsageItems) != 1 { - t.Errorf("Expected 1 usage item, got %v", len(report.UsageItems)) - } -} - func TestEnterpriseService_GetUsageSummary_WithAllFilters(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -416,14 +366,16 @@ func TestEnterpriseService_GetUsageSummary_WithAllFilters(t *testing.T) { ctx := t.Context() opts := &EnterpriseUsageSummaryOptions{ - Year: 2025, - Month: 6, - Day: 15, + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 6, + Day: 15, + CostCenterID: "cc-001", + }, Organization: "acme", Repository: "acme/api", Product: "Actions", SKU: "actions_linux", - CostCenterID: "cc-001", } report, resp, err := client.Enterprise.GetUsageSummary(ctx, "test-enterprise", opts) if err != nil { @@ -523,9 +475,8 @@ func TestEnterpriseService_GetPremiumRequestUsageReport(t *testing.T) { ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - Year: 2025, - Month: 10, - User: "testuser", + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 10}, + User: "testuser", } report, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", opts) if err != nil { @@ -580,14 +531,16 @@ func TestEnterpriseService_GetPremiumRequestUsageReport_WithAllOptions(t *testin ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - Year: 2025, - Month: 5, - Day: 10, + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 5, + Day: 10, + CostCenterID: "cc-sales", + }, Organization: "acme-org", User: "alice", Model: "GPT-4", Product: "Copilot", - CostCenterID: "cc-sales", } report, resp, err := client.Enterprise.GetPremiumRequestUsageReport(ctx, "test-enterprise", opts) if err != nil { @@ -687,9 +640,8 @@ func TestEnterpriseService_GetAICreditUsage(t *testing.T) { ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - Year: 2025, - Month: 6, - User: "testuser", + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 6}, + User: "testuser", } report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { @@ -752,9 +704,7 @@ func TestEnterpriseService_GetAICreditUsage_FloatQuantities(t *testing.T) { ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - Year: 2025, - Month: 3, - Day: 15, + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 3, Day: 15}, } report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { @@ -811,7 +761,7 @@ func TestEnterpriseService_GetAICreditUsage_WithCostCenter(t *testing.T) { ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - CostCenterID: "cc-engineering", + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{CostCenterID: "cc-engineering"}, } report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { @@ -994,14 +944,16 @@ func TestEnterpriseService_GetAICreditUsage_WithAllOptions(t *testing.T) { ctx := t.Context() opts := &EnterprisePremiumRequestUsageReportOptions{ - Year: 2025, - Month: 2, - Day: 28, + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 2, + Day: 28, + CostCenterID: "cc-dev", + }, Organization: "tech-org", User: "bob", Model: "GPT-4", Product: "Copilot", - CostCenterID: "cc-dev", } report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) if err != nil { diff --git a/github/github-accessors.go b/github/github-accessors.go index 483b3ddfd95..ba4389f3bbd 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -14510,14 +14510,6 @@ func (e *EnterpriseAggregatedUsageReport) GetProduct() string { return *e.Product } -// GetRepository returns the Repository field if it's non-nil, zero value otherwise. -func (e *EnterpriseAggregatedUsageReport) GetRepository() string { - if e == nil || e.Repository == nil { - return "" - } - return *e.Repository -} - // GetTimePeriod returns the TimePeriod field. func (e *EnterpriseAggregatedUsageReport) GetTimePeriod() EnterpriseUsageTimePeriod { if e == nil { @@ -14974,22 +14966,6 @@ func (e *EnterpriseListBudgets) GetTotalCount() int { return *e.TotalCount } -// GetCostCenterID returns the CostCenterID field. -func (e *EnterprisePremiumRequestUsageReportOptions) GetCostCenterID() string { - if e == nil { - return "" - } - return e.CostCenterID -} - -// GetDay returns the Day field. -func (e *EnterprisePremiumRequestUsageReportOptions) GetDay() int { - if e == nil { - return 0 - } - return e.Day -} - // GetModel returns the Model field. func (e *EnterprisePremiumRequestUsageReportOptions) GetModel() string { if e == nil { @@ -14998,14 +14974,6 @@ func (e *EnterprisePremiumRequestUsageReportOptions) GetModel() string { return e.Model } -// GetMonth returns the Month field. -func (e *EnterprisePremiumRequestUsageReportOptions) GetMonth() int { - if e == nil { - return 0 - } - return e.Month -} - // GetOrganization returns the Organization field. func (e *EnterprisePremiumRequestUsageReportOptions) GetOrganization() string { if e == nil { @@ -15030,14 +14998,6 @@ func (e *EnterprisePremiumRequestUsageReportOptions) GetUser() string { return e.User } -// GetYear returns the Year field. -func (e *EnterprisePremiumRequestUsageReportOptions) GetYear() int { - if e == nil { - return 0 - } - return e.Year -} - // GetAllowsPublicRepositories returns the AllowsPublicRepositories field if it's non-nil, zero value otherwise. func (e *EnterpriseRunnerGroup) GetAllowsPublicRepositories() bool { if e == nil || e.AllowsPublicRepositories == nil { @@ -15502,28 +15462,84 @@ func (e *EnterpriseUsageReportOptions) GetYear() int { return e.Year } -// GetCostCenterID returns the CostCenterID field. -func (e *EnterpriseUsageSummaryOptions) GetCostCenterID() string { +// GetDiscountAmount returns the DiscountAmount field. +func (e *EnterpriseUsageSummaryItem) GetDiscountAmount() float64 { if e == nil { - return "" + return 0 } - return e.CostCenterID + return e.DiscountAmount } -// GetDay returns the Day field. -func (e *EnterpriseUsageSummaryOptions) GetDay() int { +// GetDiscountQuantity returns the DiscountQuantity field. +func (e *EnterpriseUsageSummaryItem) GetDiscountQuantity() float64 { if e == nil { return 0 } - return e.Day + return e.DiscountQuantity } -// GetMonth returns the Month field. -func (e *EnterpriseUsageSummaryOptions) GetMonth() int { +// GetGrossAmount returns the GrossAmount field. +func (e *EnterpriseUsageSummaryItem) GetGrossAmount() float64 { if e == nil { return 0 } - return e.Month + return e.GrossAmount +} + +// GetGrossQuantity returns the GrossQuantity field. +func (e *EnterpriseUsageSummaryItem) GetGrossQuantity() float64 { + if e == nil { + return 0 + } + return e.GrossQuantity +} + +// GetNetAmount returns the NetAmount field. +func (e *EnterpriseUsageSummaryItem) GetNetAmount() float64 { + if e == nil { + return 0 + } + return e.NetAmount +} + +// GetNetQuantity returns the NetQuantity field. +func (e *EnterpriseUsageSummaryItem) GetNetQuantity() float64 { + if e == nil { + return 0 + } + return e.NetQuantity +} + +// GetPricePerUnit returns the PricePerUnit field. +func (e *EnterpriseUsageSummaryItem) GetPricePerUnit() float64 { + if e == nil { + return 0 + } + return e.PricePerUnit +} + +// GetProduct returns the Product field. +func (e *EnterpriseUsageSummaryItem) GetProduct() string { + if e == nil { + return "" + } + return e.Product +} + +// GetSKU returns the SKU field. +func (e *EnterpriseUsageSummaryItem) GetSKU() string { + if e == nil { + return "" + } + return e.SKU +} + +// GetUnitType returns the UnitType field. +func (e *EnterpriseUsageSummaryItem) GetUnitType() string { + if e == nil { + return "" + } + return e.UnitType } // GetOrganization returns the Organization field. @@ -15558,12 +15574,68 @@ func (e *EnterpriseUsageSummaryOptions) GetSKU() string { return e.SKU } -// GetYear returns the Year field. -func (e *EnterpriseUsageSummaryOptions) GetYear() int { +// GetCostCenter returns the CostCenter field. +func (e *EnterpriseUsageSummaryReport) GetCostCenter() *BillingCostCenter { if e == nil { - return 0 + return nil } - return e.Year + return e.CostCenter +} + +// GetEnterprise returns the Enterprise field. +func (e *EnterpriseUsageSummaryReport) GetEnterprise() string { + if e == nil { + return "" + } + return e.Enterprise +} + +// GetOrganization returns the Organization field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageSummaryReport) GetOrganization() string { + if e == nil || e.Organization == nil { + return "" + } + return *e.Organization +} + +// GetProduct returns the Product field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageSummaryReport) GetProduct() string { + if e == nil || e.Product == nil { + return "" + } + return *e.Product +} + +// GetRepository returns the Repository field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageSummaryReport) GetRepository() string { + if e == nil || e.Repository == nil { + return "" + } + return *e.Repository +} + +// GetSKU returns the SKU field if it's non-nil, zero value otherwise. +func (e *EnterpriseUsageSummaryReport) GetSKU() string { + if e == nil || e.SKU == nil { + return "" + } + return *e.SKU +} + +// GetTimePeriod returns the TimePeriod field. +func (e *EnterpriseUsageSummaryReport) GetTimePeriod() EnterpriseUsageTimePeriod { + if e == nil { + return EnterpriseUsageTimePeriod{} + } + return e.TimePeriod +} + +// GetUsageItems returns the UsageItems slice if it's non-nil, nil otherwise. +func (e *EnterpriseUsageSummaryReport) GetUsageItems() []*EnterpriseUsageSummaryItem { + if e == nil || e.UsageItems == nil { + return nil + } + return e.UsageItems } // GetDay returns the Day field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1ed9219362d..894cff53af1 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -18351,17 +18351,6 @@ func TestEnterpriseAggregatedUsageReport_GetProduct(tt *testing.T) { e.GetProduct() } -func TestEnterpriseAggregatedUsageReport_GetRepository(tt *testing.T) { - tt.Parallel() - var zeroValue string - e := &EnterpriseAggregatedUsageReport{Repository: &zeroValue} - e.GetRepository() - e = &EnterpriseAggregatedUsageReport{} - e.GetRepository() - e = nil - e.GetRepository() -} - func TestEnterpriseAggregatedUsageReport_GetTimePeriod(tt *testing.T) { tt.Parallel() e := &EnterpriseAggregatedUsageReport{} @@ -18926,22 +18915,6 @@ func TestEnterpriseListBudgets_GetTotalCount(tt *testing.T) { e.GetTotalCount() } -func TestEnterprisePremiumRequestUsageReportOptions_GetCostCenterID(tt *testing.T) { - tt.Parallel() - e := &EnterprisePremiumRequestUsageReportOptions{} - e.GetCostCenterID() - e = nil - e.GetCostCenterID() -} - -func TestEnterprisePremiumRequestUsageReportOptions_GetDay(tt *testing.T) { - tt.Parallel() - e := &EnterprisePremiumRequestUsageReportOptions{} - e.GetDay() - e = nil - e.GetDay() -} - func TestEnterprisePremiumRequestUsageReportOptions_GetModel(tt *testing.T) { tt.Parallel() e := &EnterprisePremiumRequestUsageReportOptions{} @@ -18950,14 +18923,6 @@ func TestEnterprisePremiumRequestUsageReportOptions_GetModel(tt *testing.T) { e.GetModel() } -func TestEnterprisePremiumRequestUsageReportOptions_GetMonth(tt *testing.T) { - tt.Parallel() - e := &EnterprisePremiumRequestUsageReportOptions{} - e.GetMonth() - e = nil - e.GetMonth() -} - func TestEnterprisePremiumRequestUsageReportOptions_GetOrganization(tt *testing.T) { tt.Parallel() e := &EnterprisePremiumRequestUsageReportOptions{} @@ -18982,14 +18947,6 @@ func TestEnterprisePremiumRequestUsageReportOptions_GetUser(tt *testing.T) { e.GetUser() } -func TestEnterprisePremiumRequestUsageReportOptions_GetYear(tt *testing.T) { - tt.Parallel() - e := &EnterprisePremiumRequestUsageReportOptions{} - e.GetYear() - e = nil - e.GetYear() -} - func TestEnterpriseRunnerGroup_GetAllowsPublicRepositories(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -19553,28 +19510,84 @@ func TestEnterpriseUsageReportOptions_GetYear(tt *testing.T) { e.GetYear() } -func TestEnterpriseUsageSummaryOptions_GetCostCenterID(tt *testing.T) { +func TestEnterpriseUsageSummaryItem_GetDiscountAmount(tt *testing.T) { tt.Parallel() - e := &EnterpriseUsageSummaryOptions{} - e.GetCostCenterID() + e := &EnterpriseUsageSummaryItem{} + e.GetDiscountAmount() e = nil - e.GetCostCenterID() + e.GetDiscountAmount() } -func TestEnterpriseUsageSummaryOptions_GetDay(tt *testing.T) { +func TestEnterpriseUsageSummaryItem_GetDiscountQuantity(tt *testing.T) { tt.Parallel() - e := &EnterpriseUsageSummaryOptions{} - e.GetDay() + e := &EnterpriseUsageSummaryItem{} + e.GetDiscountQuantity() e = nil - e.GetDay() + e.GetDiscountQuantity() } -func TestEnterpriseUsageSummaryOptions_GetMonth(tt *testing.T) { +func TestEnterpriseUsageSummaryItem_GetGrossAmount(tt *testing.T) { tt.Parallel() - e := &EnterpriseUsageSummaryOptions{} - e.GetMonth() + e := &EnterpriseUsageSummaryItem{} + e.GetGrossAmount() e = nil - e.GetMonth() + e.GetGrossAmount() +} + +func TestEnterpriseUsageSummaryItem_GetGrossQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetGrossQuantity() + e = nil + e.GetGrossQuantity() +} + +func TestEnterpriseUsageSummaryItem_GetNetAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetNetAmount() + e = nil + e.GetNetAmount() +} + +func TestEnterpriseUsageSummaryItem_GetNetQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetNetQuantity() + e = nil + e.GetNetQuantity() +} + +func TestEnterpriseUsageSummaryItem_GetPricePerUnit(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetPricePerUnit() + e = nil + e.GetPricePerUnit() +} + +func TestEnterpriseUsageSummaryItem_GetProduct(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseUsageSummaryItem_GetSKU(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetSKU() + e = nil + e.GetSKU() +} + +func TestEnterpriseUsageSummaryItem_GetUnitType(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetUnitType() + e = nil + e.GetUnitType() } func TestEnterpriseUsageSummaryOptions_GetOrganization(tt *testing.T) { @@ -19609,12 +19622,83 @@ func TestEnterpriseUsageSummaryOptions_GetSKU(tt *testing.T) { e.GetSKU() } -func TestEnterpriseUsageSummaryOptions_GetYear(tt *testing.T) { +func TestEnterpriseUsageSummaryReport_GetCostCenter(tt *testing.T) { tt.Parallel() - e := &EnterpriseUsageSummaryOptions{} - e.GetYear() + e := &EnterpriseUsageSummaryReport{} + e.GetCostCenter() e = nil - e.GetYear() + e.GetCostCenter() +} + +func TestEnterpriseUsageSummaryReport_GetEnterprise(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryReport{} + e.GetEnterprise() + e = nil + e.GetEnterprise() +} + +func TestEnterpriseUsageSummaryReport_GetOrganization(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseUsageSummaryReport{Organization: &zeroValue} + e.GetOrganization() + e = &EnterpriseUsageSummaryReport{} + e.GetOrganization() + e = nil + e.GetOrganization() +} + +func TestEnterpriseUsageSummaryReport_GetProduct(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseUsageSummaryReport{Product: &zeroValue} + e.GetProduct() + e = &EnterpriseUsageSummaryReport{} + e.GetProduct() + e = nil + e.GetProduct() +} + +func TestEnterpriseUsageSummaryReport_GetRepository(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseUsageSummaryReport{Repository: &zeroValue} + e.GetRepository() + e = &EnterpriseUsageSummaryReport{} + e.GetRepository() + e = nil + e.GetRepository() +} + +func TestEnterpriseUsageSummaryReport_GetSKU(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseUsageSummaryReport{SKU: &zeroValue} + e.GetSKU() + e = &EnterpriseUsageSummaryReport{} + e.GetSKU() + e = nil + e.GetSKU() +} + +func TestEnterpriseUsageSummaryReport_GetTimePeriod(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryReport{} + e.GetTimePeriod() + e = nil + e.GetTimePeriod() +} + +func TestEnterpriseUsageSummaryReport_GetUsageItems(tt *testing.T) { + tt.Parallel() + zeroValue := []*EnterpriseUsageSummaryItem{} + e := &EnterpriseUsageSummaryReport{UsageItems: zeroValue} + e.GetUsageItems() + e = &EnterpriseUsageSummaryReport{} + e.GetUsageItems() + e = nil + e.GetUsageItems() } func TestEnterpriseUsageTimePeriod_GetDay(tt *testing.T) {