From 48dd55cc6c1b397a77cb0b1ab8d122fe368168a1 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Fri, 3 Oct 2025 13:59:06 +0900 Subject: [PATCH 1/6] feat: Add premium request usage report endpoints for organizations and users --- github/billing.go | 102 +++++++++++++++++++++ github/billing_test.go | 196 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+) diff --git a/github/billing.go b/github/billing.go index b98af40a398..49194275283 100644 --- a/github/billing.go +++ b/github/billing.go @@ -74,6 +74,21 @@ type UsageReportOptions struct { Hour *int `url:"hour,omitempty"` } +// PremiumRequestUsageReportOptions specifies optional parameters +// for the enhanced billing platform premiun request usage report. +type PremiumRequestUsageReportOptions struct { + UsageReportOptions + + // The user name to query usage for. The name is not case sensitive. + User *string `url:"user,omitempty"` + + // The model name to query usage for. The name is not case sensitive. + Model *string `url:"model,omitempty"` + + // The product name to query usage for. The name is not case sensitive. + Product *string `url:"product,omitempty"` +} + // UsageItem represents a single usage item in the enhanced billing platform report. type UsageItem struct { Date *string `json:"date"` @@ -95,6 +110,35 @@ type UsageReport struct { UsageItems []*UsageItem `json:"usageItems,omitempty"` } +// PremiumRequestUsageItem represents a single usage line item in premium request usage reports. +type PremiumRequestUsageItem struct { + Product string `json:"product"` + SKU string `json:"sku"` + Model string `json:"model"` + UnitType string `json:"unitType"` + PricePerUnit float64 `json:"pricePerUnit"` + GrossQuantity int `json:"grossQuantity"` + GrossAmount float64 `json:"grossAmount"` + DiscountQuantity int `json:"discountQuantity"` + DiscountAmount float64 `json:"discountAmount"` + NetQuantity int `json:"netQuantity"` + NetAmount float64 `json:"netAmount"` +} + +// PremiumRequestUsageReport represents the premium request usage report response. +type PremiumRequestUsageReport struct { + TimePeriod struct { + Year int `json:"year"` + Month *int `json:"month,omitempty"` + Day *int `json:"day,omitempty"` + } `json:"timePeriod"` + Organization string `json:"organization"` + User *string `json:"user,omitempty"` + Product *string `json:"product,omitempty"` + Model *string `json:"model,omitempty"` + UsageItems []*PremiumRequestUsageItem `json:"usageItems"` +} + // GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org. // // GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-an-organization @@ -262,3 +306,61 @@ func (s *BillingService) GetUsageReportUser(ctx context.Context, user string, op return usageReport, resp, nil } + +// GetPremiumRequestUsageReportOrg returns a report of the premium request +// usage for an organization using the enhanced billing platform. +// +// Note: This endpoint is only available to organizations with access to the enhanced billing platform. +// +// GitHub API docs: https://docs.github.com/rest/billing/billing#get-premium-request-usage-for-an-organization +// +//meta:operation GET /organizations/{org}/settings/billing/premium_request/usage +func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { + u := fmt.Sprintf("organizations/%v/settings/billing/premium_request/usage", org) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + premiumRequestUsageReport := new(PremiumRequestUsageReport) + resp, err := s.client.Do(ctx, req, premiumRequestUsageReport) + if err != nil { + return nil, resp, err + } + + return premiumRequestUsageReport, resp, nil +} + +// GetPremiumRequestUsageReportUser returns a report of the premium request +// usage for a user using the enhanced billing platform. +// +// Note: This endpoint is only available to users with access to the enhanced billing platform. +// +// GitHub API docs: https://docs.github.com/rest/billing/billing#get-premium-request-usage-for-a-user +// +//meta:operation GET /users/{username}/settings/billing/premium_request/usage +func (s *BillingService) GetPremiumRequestUsageReportUser(ctx context.Context, user string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { + u := fmt.Sprintf("users/%v/settings/billing/premium_request/usage", user) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + premiumRequestUsageReport := new(PremiumRequestUsageReport) + resp, err := s.client.Do(ctx, req, premiumRequestUsageReport) + if err != nil { + return nil, resp, err + } + + return premiumRequestUsageReport, resp, nil +} diff --git a/github/billing_test.go b/github/billing_test.go index 62325f9c123..95d8bdc801a 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -521,3 +521,199 @@ func TestBillingService_GetUsageReportUser_invalidUser(t *testing.T) { _, _, err := client.Billing.GetUsageReportUser(ctx, "%", nil) testURLParseError(t, err) } + +func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + mux.HandleFunc("/organizations/o/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 + }, + "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 := context.Background() + opts := &PremiumRequestUsageReportOptions{ + UsageReportOptions: UsageReportOptions{ + Year: Ptr(2025), + Month: Ptr(10), + }, + User: Ptr("testuser"), + } + report, _, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "o", opts) + if err != nil { + t.Errorf("Billing.GetPremiumRequestUsageReportOrg returned error: %v", err) + } + want := &PremiumRequestUsageReport{ + TimePeriod: TimePeriod{ + Year: 2025, + Month: Ptr(10), + }, + Organization: "GitHub", + User: Ptr("testuser"), + Product: Ptr("Copilot"), + Model: Ptr("GPT-5"), + UsageItems: []*PremiumRequestUsageItem{ + { + 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, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetPremiumRequestUsageReportOrg returned %+v, want %+v", report, want) + } + + const methodName = "GetPremiumRequestUsageReportOrg" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetPremiumRequestUsageReportOrg(ctx, "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "o", nil) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetPremiumRequestUsageReportOrg_invalidOrg(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := context.Background() + _, _, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "%", nil) + testURLParseError(t, err) +} + +func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + mux.HandleFunc("/users/u/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{ + "year": "2025", + "day": "15", + }) + fmt.Fprint(w, `{ + "timePeriod": { + "year": 2025, + "day": 15 + }, + "organization": "UserOrg", + "product": "Copilot", + "usageItems": [ + { + "product": "Copilot", + "sku": "Copilot Premium Request", + "model": "GPT-4", + "unitType": "requests", + "pricePerUnit": 0.02, + "grossQuantity": 50, + "grossAmount": 1.0, + "discountQuantity": 5, + "discountAmount": 0.1, + "netQuantity": 45, + "netAmount": 0.9 + } + ] + }`) + }) + ctx := context.Background() + opts := &PremiumRequestUsageReportOptions{ + UsageReportOptions: UsageReportOptions{ + Year: Ptr(2025), + Day: Ptr(15), + }, + } + report, _, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "u", opts) + if err != nil { + t.Errorf("Billing.GetPremiumRequestUsageReportUser returned error: %v", err) + } + want := &PremiumRequestUsageReport{ + TimePeriod: TimePeriod{ + Year: 2025, + Day: Ptr(15), + }, + Organization: "UserOrg", + Product: Ptr("Copilot"), + UsageItems: []*PremiumRequestUsageItem{ + { + Product: "Copilot", + SKU: "Copilot Premium Request", + Model: "GPT-4", + UnitType: "requests", + PricePerUnit: 0.02, + GrossQuantity: 50, + GrossAmount: 1.0, + DiscountQuantity: 5, + DiscountAmount: 0.1, + NetQuantity: 45, + NetAmount: 0.9, + }, + }, + } + if !cmp.Equal(report, want) { + t.Errorf("Billing.GetPremiumRequestUsageReportUser returned %+v, want %+v", report, want) + } + + const methodName = "GetPremiumRequestUsageReportUser" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetPremiumRequestUsageReportUser(ctx, "\n", opts) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "u", nil) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetPremiumRequestUsageReportUser_invalidUser(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := context.Background() + _, _, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "%", nil) + testURLParseError(t, err) +} From 0c4a7719b0a1d5610f8a65d2112f5b75635ecd98 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Fri, 3 Oct 2025 15:47:11 +0900 Subject: [PATCH 2/6] fix lint error --- github/billing.go | 27 +++++----- github/billing_test.go | 4 +- github/github-accessors.go | 64 ++++++++++++++++++++++++ github/github-accessors_test.go | 88 +++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 14 deletions(-) diff --git a/github/billing.go b/github/billing.go index 49194275283..109367f049f 100644 --- a/github/billing.go +++ b/github/billing.go @@ -125,18 +125,21 @@ type PremiumRequestUsageItem struct { NetAmount float64 `json:"netAmount"` } +// PremiumRequestUsageTimePeriod represents a time period for premium request usage reports. +type PremiumRequestUsageTimePeriod struct { + Year int `json:"year"` + Month *int `json:"month,omitempty"` + Day *int `json:"day,omitempty"` +} + // PremiumRequestUsageReport represents the premium request usage report response. type PremiumRequestUsageReport struct { - TimePeriod struct { - Year int `json:"year"` - Month *int `json:"month,omitempty"` - Day *int `json:"day,omitempty"` - } `json:"timePeriod"` - Organization string `json:"organization"` - User *string `json:"user,omitempty"` - Product *string `json:"product,omitempty"` - Model *string `json:"model,omitempty"` - UsageItems []*PremiumRequestUsageItem `json:"usageItems"` + TimePeriod PremiumRequestUsageTimePeriod `json:"timePeriod"` + Organization string `json:"organization"` + User *string `json:"user,omitempty"` + Product *string `json:"product,omitempty"` + Model *string `json:"model,omitempty"` + UsageItems []*PremiumRequestUsageItem `json:"usageItems"` } // GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org. @@ -312,7 +315,7 @@ func (s *BillingService) GetUsageReportUser(ctx context.Context, user string, op // // Note: This endpoint is only available to organizations with access to the enhanced billing platform. // -// GitHub API docs: https://docs.github.com/rest/billing/billing#get-premium-request-usage-for-an-organization +// GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-premium-request-usage-report-for-an-organization // //meta:operation GET /organizations/{org}/settings/billing/premium_request/usage func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { @@ -341,7 +344,7 @@ func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, or // // Note: This endpoint is only available to users with access to the enhanced billing platform. // -// GitHub API docs: https://docs.github.com/rest/billing/billing#get-premium-request-usage-for-a-user +// GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-premium-request-usage-report-for-a-user // //meta:operation GET /users/{username}/settings/billing/premium_request/usage func (s *BillingService) GetPremiumRequestUsageReportUser(ctx context.Context, user string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { diff --git a/github/billing_test.go b/github/billing_test.go index 95d8bdc801a..814e704d9fd 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -571,7 +571,7 @@ func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { t.Errorf("Billing.GetPremiumRequestUsageReportOrg returned error: %v", err) } want := &PremiumRequestUsageReport{ - TimePeriod: TimePeriod{ + TimePeriod: PremiumRequestUsageTimePeriod{ Year: 2025, Month: Ptr(10), }, @@ -668,7 +668,7 @@ func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { t.Errorf("Billing.GetPremiumRequestUsageReportUser returned error: %v", err) } want := &PremiumRequestUsageReport{ - TimePeriod: TimePeriod{ + TimePeriod: PremiumRequestUsageTimePeriod{ Year: 2025, Day: Ptr(15), }, diff --git a/github/github-accessors.go b/github/github-accessors.go index 0a8f83ee2e1..ed42bbe6a1d 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -18422,6 +18422,70 @@ func (p *Plan) GetSpace() int { return *p.Space } +// GetModel returns the Model field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReport) GetModel() string { + if p == nil || p.Model == nil { + return "" + } + return *p.Model +} + +// GetProduct returns the Product field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReport) GetProduct() string { + if p == nil || p.Product == nil { + return "" + } + return *p.Product +} + +// GetUser returns the User field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReport) GetUser() string { + if p == nil || p.User == nil { + return "" + } + return *p.User +} + +// GetModel returns the Model field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetModel() string { + if p == nil || p.Model == nil { + return "" + } + return *p.Model +} + +// GetProduct returns the Product field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetProduct() string { + if p == nil || p.Product == nil { + return "" + } + return *p.Product +} + +// GetUser returns the User field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetUser() string { + if p == nil || p.User == nil { + return "" + } + return *p.User +} + +// GetDay returns the Day field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageTimePeriod) GetDay() int { + if p == nil || p.Day == nil { + return 0 + } + return *p.Day +} + +// GetMonth returns the Month field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageTimePeriod) GetMonth() int { + if p == nil || p.Month == nil { + return 0 + } + return *p.Month +} + // GetConfigURL returns the ConfigURL field if it's non-nil, zero value otherwise. func (p *PreReceiveHook) GetConfigURL() string { if p == nil || p.ConfigURL == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 3c78a1436b8..1908876062b 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -23934,6 +23934,94 @@ func TestPlan_GetSpace(tt *testing.T) { p.GetSpace() } +func TestPremiumRequestUsageReport_GetModel(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReport{Model: &zeroValue} + p.GetModel() + p = &PremiumRequestUsageReport{} + p.GetModel() + p = nil + p.GetModel() +} + +func TestPremiumRequestUsageReport_GetProduct(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReport{Product: &zeroValue} + p.GetProduct() + p = &PremiumRequestUsageReport{} + p.GetProduct() + p = nil + p.GetProduct() +} + +func TestPremiumRequestUsageReport_GetUser(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReport{User: &zeroValue} + p.GetUser() + p = &PremiumRequestUsageReport{} + p.GetUser() + p = nil + p.GetUser() +} + +func TestPremiumRequestUsageReportOptions_GetModel(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReportOptions{Model: &zeroValue} + p.GetModel() + p = &PremiumRequestUsageReportOptions{} + p.GetModel() + p = nil + p.GetModel() +} + +func TestPremiumRequestUsageReportOptions_GetProduct(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReportOptions{Product: &zeroValue} + p.GetProduct() + p = &PremiumRequestUsageReportOptions{} + p.GetProduct() + p = nil + p.GetProduct() +} + +func TestPremiumRequestUsageReportOptions_GetUser(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PremiumRequestUsageReportOptions{User: &zeroValue} + p.GetUser() + p = &PremiumRequestUsageReportOptions{} + p.GetUser() + p = nil + p.GetUser() +} + +func TestPremiumRequestUsageTimePeriod_GetDay(tt *testing.T) { + tt.Parallel() + var zeroValue int + p := &PremiumRequestUsageTimePeriod{Day: &zeroValue} + p.GetDay() + p = &PremiumRequestUsageTimePeriod{} + p.GetDay() + p = nil + p.GetDay() +} + +func TestPremiumRequestUsageTimePeriod_GetMonth(tt *testing.T) { + tt.Parallel() + var zeroValue int + p := &PremiumRequestUsageTimePeriod{Month: &zeroValue} + p.GetMonth() + p = &PremiumRequestUsageTimePeriod{} + p.GetMonth() + p = nil + p.GetMonth() +} + func TestPreReceiveHook_GetConfigURL(tt *testing.T) { tt.Parallel() var zeroValue string From d0694702149a066e112a4b944f48806fbf61aa39 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Fri, 3 Oct 2025 22:39:48 +0900 Subject: [PATCH 3/6] fix typo --- github/billing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/billing.go b/github/billing.go index 109367f049f..aa384198947 100644 --- a/github/billing.go +++ b/github/billing.go @@ -75,7 +75,7 @@ type UsageReportOptions struct { } // PremiumRequestUsageReportOptions specifies optional parameters -// for the enhanced billing platform premiun request usage report. +// for the enhanced billing platform premium request usage report. type PremiumRequestUsageReportOptions struct { UsageReportOptions From a7f93a911a37e17a91959d61d2e722ba100fedbb Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Fri, 3 Oct 2025 22:49:15 +0900 Subject: [PATCH 4/6] use `t.Context()` for test context --- github/billing_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/billing_test.go b/github/billing_test.go index 074de4b01f7..a0262805e92 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -557,7 +557,7 @@ func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { ] }`) }) - ctx := context.Background() + ctx := t.Context() opts := &PremiumRequestUsageReportOptions{ UsageReportOptions: UsageReportOptions{ Year: Ptr(2025), @@ -617,7 +617,7 @@ func TestBillingService_GetPremiumRequestUsageReportOrg_invalidOrg(t *testing.T) t.Parallel() client, _, _ := setup(t) - ctx := context.Background() + ctx := t.Context() _, _, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "%", nil) testURLParseError(t, err) } @@ -655,7 +655,7 @@ func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { ] }`) }) - ctx := context.Background() + ctx := t.Context() opts := &PremiumRequestUsageReportOptions{ UsageReportOptions: UsageReportOptions{ Year: Ptr(2025), @@ -712,7 +712,7 @@ func TestBillingService_GetPremiumRequestUsageReportUser_invalidUser(t *testing. t.Parallel() client, _, _ := setup(t) - ctx := context.Background() + ctx := t.Context() _, _, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "%", nil) testURLParseError(t, err) } From ac9b715b5a001be02581bf296a91e91232a243dd Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 7 Oct 2025 16:18:52 +0900 Subject: [PATCH 5/6] adjust struct fields and rename functions --- github/billing.go | 23 ++++++++++++++----- github/billing_test.go | 50 +++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/github/billing.go b/github/billing.go index aa384198947..ae3d3b50475 100644 --- a/github/billing.go +++ b/github/billing.go @@ -77,7 +77,20 @@ type UsageReportOptions struct { // PremiumRequestUsageReportOptions specifies optional parameters // for the enhanced billing platform premium request usage report. type PremiumRequestUsageReportOptions struct { - UsageReportOptions + // If specified, only return results for a single year. + // The value of year is an integer with four digits representing a year. For example, 2025. + // Default value is the current year. + Year *int `url:"year,omitempty"` + + // If specified, only return results for a single month. + // The value of month is an integer between 1 and 12. Default value is the current month. + // If no year is specified the default year is used. + Month *int `url:"month,omitempty"` + + // If specified, only return results for a single day. + // The value of day is an integer between 1 and 31. + // If no year or month is specified, the default year and month are used. + Day *int `url:"day,omitempty"` // The user name to query usage for. The name is not case sensitive. User *string `url:"user,omitempty"` @@ -310,7 +323,7 @@ func (s *BillingService) GetUsageReportUser(ctx context.Context, user string, op return usageReport, resp, nil } -// GetPremiumRequestUsageReportOrg returns a report of the premium request +// GetOrganizationPremiumRequestUsageReport returns a report of the premium request // usage for an organization using the enhanced billing platform. // // Note: This endpoint is only available to organizations with access to the enhanced billing platform. @@ -318,7 +331,7 @@ func (s *BillingService) GetUsageReportUser(ctx context.Context, user string, op // GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-premium-request-usage-report-for-an-organization // //meta:operation GET /organizations/{org}/settings/billing/premium_request/usage -func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { +func (s *BillingService) GetOrganizationPremiumRequestUsageReport(ctx context.Context, org string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { u := fmt.Sprintf("organizations/%v/settings/billing/premium_request/usage", org) u, err := addOptions(u, opts) if err != nil { @@ -339,7 +352,7 @@ func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, or return premiumRequestUsageReport, resp, nil } -// GetPremiumRequestUsageReportUser returns a report of the premium request +// GetPremiumRequestUsageReport returns a report of the premium request // usage for a user using the enhanced billing platform. // // Note: This endpoint is only available to users with access to the enhanced billing platform. @@ -347,7 +360,7 @@ func (s *BillingService) GetPremiumRequestUsageReportOrg(ctx context.Context, or // GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-premium-request-usage-report-for-a-user // //meta:operation GET /users/{username}/settings/billing/premium_request/usage -func (s *BillingService) GetPremiumRequestUsageReportUser(ctx context.Context, user string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { +func (s *BillingService) GetPremiumRequestUsageReport(ctx context.Context, user string, opts *PremiumRequestUsageReportOptions) (*PremiumRequestUsageReport, *Response, error) { u := fmt.Sprintf("users/%v/settings/billing/premium_request/usage", user) u, err := addOptions(u, opts) if err != nil { diff --git a/github/billing_test.go b/github/billing_test.go index a0262805e92..d7bc6fa34e7 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -521,7 +521,7 @@ func TestBillingService_GetUsageReportUser_invalidUser(t *testing.T) { testURLParseError(t, err) } -func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { +func TestBillingService_GetOrganizationPremiumRequestUsageReport(t *testing.T) { t.Parallel() client, mux, _ := setup(t) mux.HandleFunc("/organizations/o/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { @@ -559,15 +559,13 @@ func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { }) ctx := t.Context() opts := &PremiumRequestUsageReportOptions{ - UsageReportOptions: UsageReportOptions{ - Year: Ptr(2025), - Month: Ptr(10), - }, - User: Ptr("testuser"), + Year: Ptr(2025), + Month: Ptr(10), + User: Ptr("testuser"), } - report, _, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "o", opts) + report, _, err := client.Billing.GetOrganizationPremiumRequestUsageReport(ctx, "o", opts) if err != nil { - t.Errorf("Billing.GetPremiumRequestUsageReportOrg returned error: %v", err) + t.Errorf("Billing.GetOrganizationPremiumRequestUsageReport returned error: %v", err) } want := &PremiumRequestUsageReport{ TimePeriod: PremiumRequestUsageTimePeriod{ @@ -595,17 +593,17 @@ func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("Billing.GetPremiumRequestUsageReportOrg returned %+v, want %+v", report, want) + t.Errorf("Billing.GetOrganizationPremiumRequestUsageReport returned %+v, want %+v", report, want) } - const methodName = "GetPremiumRequestUsageReportOrg" + const methodName = "GetOrganizationPremiumRequestUsageReport" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetPremiumRequestUsageReportOrg(ctx, "\n", opts) + _, _, err = client.Billing.GetOrganizationPremiumRequestUsageReport(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "o", nil) + got, resp, err := client.Billing.GetOrganizationPremiumRequestUsageReport(ctx, "o", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -613,16 +611,16 @@ func TestBillingService_GetPremiumRequestUsageReportOrg(t *testing.T) { }) } -func TestBillingService_GetPremiumRequestUsageReportOrg_invalidOrg(t *testing.T) { +func TestBillingService_GetOrganizationPremiumRequestUsageReport_invalidOrg(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Billing.GetPremiumRequestUsageReportOrg(ctx, "%", nil) + _, _, err := client.Billing.GetOrganizationPremiumRequestUsageReport(ctx, "%", nil) testURLParseError(t, err) } -func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { +func TestBillingService_GetPremiumRequestUsageReport(t *testing.T) { t.Parallel() client, mux, _ := setup(t) mux.HandleFunc("/users/u/settings/billing/premium_request/usage", func(w http.ResponseWriter, r *http.Request) { @@ -657,14 +655,12 @@ func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { }) ctx := t.Context() opts := &PremiumRequestUsageReportOptions{ - UsageReportOptions: UsageReportOptions{ - Year: Ptr(2025), - Day: Ptr(15), - }, + Year: Ptr(2025), + Day: Ptr(15), } - report, _, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "u", opts) + report, _, err := client.Billing.GetPremiumRequestUsageReport(ctx, "u", opts) if err != nil { - t.Errorf("Billing.GetPremiumRequestUsageReportUser returned error: %v", err) + t.Errorf("Billing.GetPremiumRequestUsageReport returned error: %v", err) } want := &PremiumRequestUsageReport{ TimePeriod: PremiumRequestUsageTimePeriod{ @@ -690,17 +686,17 @@ func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { }, } if !cmp.Equal(report, want) { - t.Errorf("Billing.GetPremiumRequestUsageReportUser returned %+v, want %+v", report, want) + t.Errorf("Billing.GetPremiumRequestUsageReport returned %+v, want %+v", report, want) } - const methodName = "GetPremiumRequestUsageReportUser" + const methodName = "GetPremiumRequestUsageReport" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetPremiumRequestUsageReportUser(ctx, "\n", opts) + _, _, err = client.Billing.GetPremiumRequestUsageReport(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "u", nil) + got, resp, err := client.Billing.GetPremiumRequestUsageReport(ctx, "u", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -708,11 +704,11 @@ func TestBillingService_GetPremiumRequestUsageReportUser(t *testing.T) { }) } -func TestBillingService_GetPremiumRequestUsageReportUser_invalidUser(t *testing.T) { +func TestBillingService_GetPremiumRequestUsageReport_invalidUser(t *testing.T) { t.Parallel() client, _, _ := setup(t) ctx := t.Context() - _, _, err := client.Billing.GetPremiumRequestUsageReportUser(ctx, "%", nil) + _, _, err := client.Billing.GetPremiumRequestUsageReport(ctx, "%", nil) testURLParseError(t, err) } From 35244a5aaca83331761dda4a9ffe02a7c33a524a Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Tue, 7 Oct 2025 16:30:03 +0900 Subject: [PATCH 6/6] update generated files --- github/github-accessors.go | 24 ++++++++++++++++++++++++ github/github-accessors_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index ed42bbe6a1d..a6e79e270f5 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -18446,6 +18446,14 @@ func (p *PremiumRequestUsageReport) GetUser() string { return *p.User } +// GetDay returns the Day field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetDay() int { + if p == nil || p.Day == nil { + return 0 + } + return *p.Day +} + // GetModel returns the Model field if it's non-nil, zero value otherwise. func (p *PremiumRequestUsageReportOptions) GetModel() string { if p == nil || p.Model == nil { @@ -18454,6 +18462,14 @@ func (p *PremiumRequestUsageReportOptions) GetModel() string { return *p.Model } +// GetMonth returns the Month field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetMonth() int { + if p == nil || p.Month == nil { + return 0 + } + return *p.Month +} + // GetProduct returns the Product field if it's non-nil, zero value otherwise. func (p *PremiumRequestUsageReportOptions) GetProduct() string { if p == nil || p.Product == nil { @@ -18470,6 +18486,14 @@ func (p *PremiumRequestUsageReportOptions) GetUser() string { return *p.User } +// GetYear returns the Year field if it's non-nil, zero value otherwise. +func (p *PremiumRequestUsageReportOptions) GetYear() int { + if p == nil || p.Year == nil { + return 0 + } + return *p.Year +} + // GetDay returns the Day field if it's non-nil, zero value otherwise. func (p *PremiumRequestUsageTimePeriod) GetDay() int { if p == nil || p.Day == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1908876062b..73a35b4641d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -23967,6 +23967,17 @@ func TestPremiumRequestUsageReport_GetUser(tt *testing.T) { p.GetUser() } +func TestPremiumRequestUsageReportOptions_GetDay(tt *testing.T) { + tt.Parallel() + var zeroValue int + p := &PremiumRequestUsageReportOptions{Day: &zeroValue} + p.GetDay() + p = &PremiumRequestUsageReportOptions{} + p.GetDay() + p = nil + p.GetDay() +} + func TestPremiumRequestUsageReportOptions_GetModel(tt *testing.T) { tt.Parallel() var zeroValue string @@ -23978,6 +23989,17 @@ func TestPremiumRequestUsageReportOptions_GetModel(tt *testing.T) { p.GetModel() } +func TestPremiumRequestUsageReportOptions_GetMonth(tt *testing.T) { + tt.Parallel() + var zeroValue int + p := &PremiumRequestUsageReportOptions{Month: &zeroValue} + p.GetMonth() + p = &PremiumRequestUsageReportOptions{} + p.GetMonth() + p = nil + p.GetMonth() +} + func TestPremiumRequestUsageReportOptions_GetProduct(tt *testing.T) { tt.Parallel() var zeroValue string @@ -24000,6 +24022,17 @@ func TestPremiumRequestUsageReportOptions_GetUser(tt *testing.T) { p.GetUser() } +func TestPremiumRequestUsageReportOptions_GetYear(tt *testing.T) { + tt.Parallel() + var zeroValue int + p := &PremiumRequestUsageReportOptions{Year: &zeroValue} + p.GetYear() + p = &PremiumRequestUsageReportOptions{} + p.GetYear() + p = nil + p.GetYear() +} + func TestPremiumRequestUsageTimePeriod_GetDay(tt *testing.T) { tt.Parallel() var zeroValue int