diff --git a/github/enterprise_billing.go b/github/enterprise_billing.go new file mode 100644 index 00000000000..7f02a0343f7 --- /dev/null +++ b/github/enterprise_billing.go @@ -0,0 +1,227 @@ +// 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 EnterpriseService.GetUsageReport 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 EnterpriseService.GetPremiumRequestUsageReport and EnterpriseService.GetAICreditUsage methods. +type EnterprisePremiumRequestUsageReportOptions struct { + EnterpriseUsageReportOptions + Organization string `url:"organization,omitempty"` + User string `url:"user,omitempty"` + Model string `url:"model,omitempty"` + Product string `url:"product,omitempty"` +} + +// EnterpriseUsageSummaryOptions specifies optional parameters for the EnterpriseService.GetUsageSummary method. +type EnterpriseUsageSummaryOptions struct { + EnterpriseUsageReportOptions + Organization string `url:"organization,omitempty"` + Repository string `url:"repository,omitempty"` + Product string `url:"product,omitempty"` + SKU string `url:"sku,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 an enterprise billing premium request or AI credit report. +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 the premium request and AI credit endpoints. +type EnterpriseAggregatedUsageReport struct { + TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` + Enterprise string `json:"enterprise"` + Organization *string `json:"organization,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"` +} + +// 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"` + 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"` +} + +// 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 *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 { + 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 +} + +// 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 *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 { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, "GET", u, nil) + if err != nil { + return nil, nil, err + } + + var report *EnterpriseUsageSummaryReport + resp, err := s.client.Do(req, &report) + if err != nil { + return nil, resp, err + } + + return report, resp, nil +} + +// 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 *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 { + 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 +} + +// 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 *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 { + 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..596eb849b96 --- /dev/null +++ b/github/enterprise_billing_test.go @@ -0,0 +1,970 @@ +// 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" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestEnterpriseService_GetUsageReport(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, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageReport returned nil response") + } + + 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("GetUsageReport returned %+v, want %+v", report, want) + } +} + +func TestEnterpriseService_GetUsageReport_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, resp, err := client.Enterprise.GetUsageReport(ctx, "test-enterprise", opts) + if err != nil { + t.Errorf("GetUsageReport returned error: %v", err) + } + + if resp == nil { + t.Error("GetUsageReport returned nil response") + } + + 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 TestEnterpriseService_GetUsageReport_InvalidEnterprise(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := t.Context() + _, _, err := client.Enterprise.GetUsageReport(ctx, "%", nil) + testURLParseError(t, err) +} + +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) + + 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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025}, + Product: "Actions", + } + 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") + } + + want := &EnterpriseUsageSummaryReport{ + TimePeriod: EnterpriseUsageTimePeriod{ + Year: 2025, + }, + Enterprise: "GitHub", + UsageItems: []*EnterpriseUsageSummaryItem{ + { + 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("GetUsageSummary returned %+v, want %+v", report, want) + } +} + +func TestEnterpriseService_GetUsageSummary_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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025}, + } + 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) != 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 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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 6, + Day: 15, + CostCenterID: "cc-001", + }, + Organization: "acme", + Repository: "acme/api", + Product: "Actions", + SKU: "actions_linux", + } + 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) + + 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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 10}, + User: "testuser", + } + 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.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 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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 5, + Day: 10, + CostCenterID: "cc-sales", + }, + Organization: "acme-org", + User: "alice", + Model: "GPT-4", + Product: "Copilot", + } + 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) + + 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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 6}, + User: "testuser", + } + 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.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 TestEnterpriseService_GetAICreditUsage_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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{Year: 2025, Month: 3, Day: 15}, + } + report, resp, err := client.Enterprise.GetAICreditUsage(ctx, "test-enterprise", opts) + if err != nil { + t.Fatalf("GetAICreditUsage returned error: %v", err) + } + + if resp == nil { + t.Error("GetAICreditUsage returned nil response") + } + + 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 TestEnterpriseService_GetAICreditUsage_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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{CostCenterID: "cc-engineering"}, + } + 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.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 TestEnterpriseService_GetAICreditUsage_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, 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.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{ + EnterpriseUsageReportOptions: EnterpriseUsageReportOptions{ + Year: 2025, + Month: 2, + Day: 28, + CostCenterID: "cc-dev", + }, + Organization: "tech-org", + User: "bob", + Model: "GPT-4", + Product: "Copilot", + } + 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") + } +} diff --git a/github/github-accessors.go b/github/github-accessors.go index bc3194bc1b6..ba4389f3bbd 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,158 @@ 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 +} + +// 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 +14966,38 @@ func (e *EnterpriseListBudgets) GetTotalCount() int { return *e.TotalCount } +// GetModel returns the Model field. +func (e *EnterprisePremiumRequestUsageReportOptions) GetModel() string { + if e == nil { + return "" + } + return e.Model +} + +// 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 +} + // 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 +15334,334 @@ 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 +} + +// GetDiscountAmount returns the DiscountAmount field. +func (e *EnterpriseUsageSummaryItem) GetDiscountAmount() float64 { + if e == nil { + return 0 + } + return e.DiscountAmount +} + +// GetDiscountQuantity returns the DiscountQuantity field. +func (e *EnterpriseUsageSummaryItem) GetDiscountQuantity() float64 { + if e == nil { + return 0 + } + return e.DiscountQuantity +} + +// GetGrossAmount returns the GrossAmount field. +func (e *EnterpriseUsageSummaryItem) GetGrossAmount() float64 { + if e == nil { + return 0 + } + 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. +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 +} + +// GetCostCenter returns the CostCenter field. +func (e *EnterpriseUsageSummaryReport) GetCostCenter() *BillingCostCenter { + if e == nil { + return nil + } + 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. +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..894cff53af1 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,176 @@ 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_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 +18915,38 @@ func TestEnterpriseListBudgets_GetTotalCount(tt *testing.T) { e.GetTotalCount() } +func TestEnterprisePremiumRequestUsageReportOptions_GetModel(tt *testing.T) { + tt.Parallel() + e := &EnterprisePremiumRequestUsageReportOptions{} + e.GetModel() + e = nil + e.GetModel() +} + +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 TestEnterpriseRunnerGroup_GetAllowsPublicRepositories(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -19158,6 +19376,361 @@ 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 TestEnterpriseUsageSummaryItem_GetDiscountAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetDiscountAmount() + e = nil + e.GetDiscountAmount() +} + +func TestEnterpriseUsageSummaryItem_GetDiscountQuantity(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetDiscountQuantity() + e = nil + e.GetDiscountQuantity() +} + +func TestEnterpriseUsageSummaryItem_GetGrossAmount(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryItem{} + e.GetGrossAmount() + e = nil + 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) { + 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 TestEnterpriseUsageSummaryReport_GetCostCenter(tt *testing.T) { + tt.Parallel() + e := &EnterpriseUsageSummaryReport{} + e.GetCostCenter() + e = nil + 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) { + 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