From 34ba363435d6e5d1e7f7882da04577ef1e5e62eb Mon Sep 17 00:00:00 2001 From: Guillaume Winter <8502556+DocEmmetBrown@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:09:15 +0200 Subject: [PATCH 1/2] fix: quantity being a float and not an int The API doc is not consistent with the actual output from the api. The quantity is not an int, but a float. --- github/billing.go | 2 +- github/billing_test.go | 4 +- github/github-accessors.go | 120 +++++++++++++++++++++++++ github/github-accessors_test.go | 153 -------------------------------- 4 files changed, 123 insertions(+), 156 deletions(-) diff --git a/github/billing.go b/github/billing.go index 2ce595d3349..0776358cdb2 100644 --- a/github/billing.go +++ b/github/billing.go @@ -87,7 +87,7 @@ type UsageItem struct { Date *string `json:"date"` Product *string `json:"product"` SKU *string `json:"sku"` - Quantity *int `json:"quantity"` + Quantity *float64 `json:"quantity"` UnitType *string `json:"unitType"` PricePerUnit *float64 `json:"pricePerUnit"` GrossAmount *float64 `json:"grossAmount"` diff --git a/github/billing_test.go b/github/billing_test.go index 3e9c9e7fc42..3c29054840b 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -556,7 +556,7 @@ func TestBillingService_GetUsageReportOrg(t *testing.T) { Date: Ptr("2023-08-01"), Product: Ptr("Actions"), SKU: Ptr("Actions Linux"), - Quantity: Ptr(100), + Quantity: Ptr(100.0), UnitType: Ptr("minutes"), PricePerUnit: Ptr(0.008), GrossAmount: Ptr(0.8), @@ -637,7 +637,7 @@ func TestBillingService_GetUsageReportUser(t *testing.T) { Date: Ptr("2023-08-15"), Product: Ptr("Codespaces"), SKU: Ptr("Codespaces Linux"), - Quantity: Ptr(50), + Quantity: Ptr(50.0), UnitType: Ptr("hours"), PricePerUnit: Ptr(0.18), GrossAmount: Ptr(9.0), diff --git a/github/github-accessors.go b/github/github-accessors.go index 2b832617c85..1515d47e545 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -27630,6 +27630,126 @@ func (u *UsageItem) GetProduct() string { return *u.Product } +// GetQuantity returns the Quantity field. +func (u *UsageItem) GetQuantity() *float64 { + if u == nil { + return nil + } + return u.Quantity +} + +// GetRepositoryName returns the RepositoryName field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetRepositoryName() string { + if u == nil || u.RepositoryName == nil { + return "" + } + return *u.RepositoryName +} + +// GetSKU returns the SKU field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetSKU() string { + if u == nil || u.SKU == nil { + return "" + } + return *u.SKU +} + +// GetUnitType returns the UnitType field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetUnitType() string { + if u == nil || u.UnitType == nil { + return "" + } + return *u.UnitType +} + +// GetDay returns the Day field if it's non-nil, zero value otherwise. +func (u *UsageReportOptions) GetDay() int { + if u == nil || u.Day == nil { + return 0 + } + return *u.Day +} + +// GetHour returns the Hour field if it's non-nil, zero value otherwise. +func (u *UsageReportOptions) GetHour() int { + if u == nil || u.Hour == nil { + return 0 + } + return *u.Hour +} + +// GetMonth returns the Month field if it's non-nil, zero value otherwise. +func (u *UsageReportOptions) GetMonth() int { + if u == nil || u.Month == nil { + return 0 + } + return *u.Month +} + +// GetYear returns the Year field if it's non-nil, zero value otherwise. +func (u *UsageReportOptions) GetYear() int { + if u == nil || u.Year == nil { + return 0 + } + return *u.Year +} + +// GetDate returns the Date field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetDate() string { + if u == nil || u.Date == nil { + return "" + } + return *u.Date +} + +// GetDiscountAmount returns the DiscountAmount field. +func (u *UsageItem) GetDiscountAmount() *float64 { + if u == nil { + return nil + } + return u.DiscountAmount +} + +// GetGrossAmount returns the GrossAmount field. +func (u *UsageItem) GetGrossAmount() *float64 { + if u == nil { + return nil + } + return u.GrossAmount +} + +// GetNetAmount returns the NetAmount field. +func (u *UsageItem) GetNetAmount() *float64 { + if u == nil { + return nil + } + return u.NetAmount +} + +// GetOrganizationName returns the OrganizationName field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetOrganizationName() string { + if u == nil || u.OrganizationName == nil { + return "" + } + return *u.OrganizationName +} + +// GetPricePerUnit returns the PricePerUnit field. +func (u *UsageItem) GetPricePerUnit() *float64 { + if u == nil { + return nil + } + return u.PricePerUnit +} + +// GetProduct returns the Product field if it's non-nil, zero value otherwise. +func (u *UsageItem) GetProduct() string { + if u == nil || u.Product == nil { + return "" + } + return *u.Product +} + // GetQuantity returns the Quantity field if it's non-nil, zero value otherwise. func (u *UsageItem) GetQuantity() int { if u == nil || u.Quantity == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c0b94a55148..ca2f10ffb92 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -35456,159 +35456,6 @@ func TestUpdateRunnerGroupRequest_GetVisibility(tt *testing.T) { u.GetVisibility() } -func TestUsageItem_GetDate(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{Date: &zeroValue} - u.GetDate() - u = &UsageItem{} - u.GetDate() - u = nil - u.GetDate() -} - -func TestUsageItem_GetDiscountAmount(tt *testing.T) { - tt.Parallel() - u := &UsageItem{} - u.GetDiscountAmount() - u = nil - u.GetDiscountAmount() -} - -func TestUsageItem_GetGrossAmount(tt *testing.T) { - tt.Parallel() - u := &UsageItem{} - u.GetGrossAmount() - u = nil - u.GetGrossAmount() -} - -func TestUsageItem_GetNetAmount(tt *testing.T) { - tt.Parallel() - u := &UsageItem{} - u.GetNetAmount() - u = nil - u.GetNetAmount() -} - -func TestUsageItem_GetOrganizationName(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{OrganizationName: &zeroValue} - u.GetOrganizationName() - u = &UsageItem{} - u.GetOrganizationName() - u = nil - u.GetOrganizationName() -} - -func TestUsageItem_GetPricePerUnit(tt *testing.T) { - tt.Parallel() - u := &UsageItem{} - u.GetPricePerUnit() - u = nil - u.GetPricePerUnit() -} - -func TestUsageItem_GetProduct(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{Product: &zeroValue} - u.GetProduct() - u = &UsageItem{} - u.GetProduct() - u = nil - u.GetProduct() -} - -func TestUsageItem_GetQuantity(tt *testing.T) { - tt.Parallel() - var zeroValue int - u := &UsageItem{Quantity: &zeroValue} - u.GetQuantity() - u = &UsageItem{} - u.GetQuantity() - u = nil - u.GetQuantity() -} - -func TestUsageItem_GetRepositoryName(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{RepositoryName: &zeroValue} - u.GetRepositoryName() - u = &UsageItem{} - u.GetRepositoryName() - u = nil - u.GetRepositoryName() -} - -func TestUsageItem_GetSKU(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{SKU: &zeroValue} - u.GetSKU() - u = &UsageItem{} - u.GetSKU() - u = nil - u.GetSKU() -} - -func TestUsageItem_GetUnitType(tt *testing.T) { - tt.Parallel() - var zeroValue string - u := &UsageItem{UnitType: &zeroValue} - u.GetUnitType() - u = &UsageItem{} - u.GetUnitType() - u = nil - u.GetUnitType() -} - -func TestUsageReportOptions_GetDay(tt *testing.T) { - tt.Parallel() - var zeroValue int - u := &UsageReportOptions{Day: &zeroValue} - u.GetDay() - u = &UsageReportOptions{} - u.GetDay() - u = nil - u.GetDay() -} - -func TestUsageReportOptions_GetHour(tt *testing.T) { - tt.Parallel() - var zeroValue int - u := &UsageReportOptions{Hour: &zeroValue} - u.GetHour() - u = &UsageReportOptions{} - u.GetHour() - u = nil - u.GetHour() -} - -func TestUsageReportOptions_GetMonth(tt *testing.T) { - tt.Parallel() - var zeroValue int - u := &UsageReportOptions{Month: &zeroValue} - u.GetMonth() - u = &UsageReportOptions{} - u.GetMonth() - u = nil - u.GetMonth() -} - -func TestUsageReportOptions_GetYear(tt *testing.T) { - tt.Parallel() - var zeroValue int - u := &UsageReportOptions{Year: &zeroValue} - u.GetYear() - u = &UsageReportOptions{} - u.GetYear() - u = nil - u.GetYear() -} - func TestUser_GetAssignment(tt *testing.T) { tt.Parallel() var zeroValue string From 972ed73b6af600f7c6c8b46856b195949101dfa8 Mon Sep 17 00:00:00 2001 From: Guillaume Winter <8502556+DocEmmetBrown@users.noreply.github.com> Date: Mon, 30 Jun 2025 09:12:27 +0200 Subject: [PATCH 2/2] fix generated files. Last iteration was incorrect --- github/github-accessors.go | 120 ------------------------- github/github-accessors_test.go | 150 ++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 120 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 1515d47e545..57e2d07dfc8 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -27694,126 +27694,6 @@ func (u *UsageReportOptions) GetYear() int { return *u.Year } -// GetDate returns the Date field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetDate() string { - if u == nil || u.Date == nil { - return "" - } - return *u.Date -} - -// GetDiscountAmount returns the DiscountAmount field. -func (u *UsageItem) GetDiscountAmount() *float64 { - if u == nil { - return nil - } - return u.DiscountAmount -} - -// GetGrossAmount returns the GrossAmount field. -func (u *UsageItem) GetGrossAmount() *float64 { - if u == nil { - return nil - } - return u.GrossAmount -} - -// GetNetAmount returns the NetAmount field. -func (u *UsageItem) GetNetAmount() *float64 { - if u == nil { - return nil - } - return u.NetAmount -} - -// GetOrganizationName returns the OrganizationName field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetOrganizationName() string { - if u == nil || u.OrganizationName == nil { - return "" - } - return *u.OrganizationName -} - -// GetPricePerUnit returns the PricePerUnit field. -func (u *UsageItem) GetPricePerUnit() *float64 { - if u == nil { - return nil - } - return u.PricePerUnit -} - -// GetProduct returns the Product field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetProduct() string { - if u == nil || u.Product == nil { - return "" - } - return *u.Product -} - -// GetQuantity returns the Quantity field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetQuantity() int { - if u == nil || u.Quantity == nil { - return 0 - } - return *u.Quantity -} - -// GetRepositoryName returns the RepositoryName field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetRepositoryName() string { - if u == nil || u.RepositoryName == nil { - return "" - } - return *u.RepositoryName -} - -// GetSKU returns the SKU field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetSKU() string { - if u == nil || u.SKU == nil { - return "" - } - return *u.SKU -} - -// GetUnitType returns the UnitType field if it's non-nil, zero value otherwise. -func (u *UsageItem) GetUnitType() string { - if u == nil || u.UnitType == nil { - return "" - } - return *u.UnitType -} - -// GetDay returns the Day field if it's non-nil, zero value otherwise. -func (u *UsageReportOptions) GetDay() int { - if u == nil || u.Day == nil { - return 0 - } - return *u.Day -} - -// GetHour returns the Hour field if it's non-nil, zero value otherwise. -func (u *UsageReportOptions) GetHour() int { - if u == nil || u.Hour == nil { - return 0 - } - return *u.Hour -} - -// GetMonth returns the Month field if it's non-nil, zero value otherwise. -func (u *UsageReportOptions) GetMonth() int { - if u == nil || u.Month == nil { - return 0 - } - return *u.Month -} - -// GetYear returns the Year field if it's non-nil, zero value otherwise. -func (u *UsageReportOptions) GetYear() int { - if u == nil || u.Year == nil { - return 0 - } - return *u.Year -} - // GetAssignment returns the Assignment field if it's non-nil, zero value otherwise. func (u *User) GetAssignment() string { if u == nil || u.Assignment == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index ca2f10ffb92..1e66350a1d7 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -35456,6 +35456,156 @@ func TestUpdateRunnerGroupRequest_GetVisibility(tt *testing.T) { u.GetVisibility() } +func TestUsageItem_GetDate(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{Date: &zeroValue} + u.GetDate() + u = &UsageItem{} + u.GetDate() + u = nil + u.GetDate() +} + +func TestUsageItem_GetDiscountAmount(tt *testing.T) { + tt.Parallel() + u := &UsageItem{} + u.GetDiscountAmount() + u = nil + u.GetDiscountAmount() +} + +func TestUsageItem_GetGrossAmount(tt *testing.T) { + tt.Parallel() + u := &UsageItem{} + u.GetGrossAmount() + u = nil + u.GetGrossAmount() +} + +func TestUsageItem_GetNetAmount(tt *testing.T) { + tt.Parallel() + u := &UsageItem{} + u.GetNetAmount() + u = nil + u.GetNetAmount() +} + +func TestUsageItem_GetOrganizationName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{OrganizationName: &zeroValue} + u.GetOrganizationName() + u = &UsageItem{} + u.GetOrganizationName() + u = nil + u.GetOrganizationName() +} + +func TestUsageItem_GetPricePerUnit(tt *testing.T) { + tt.Parallel() + u := &UsageItem{} + u.GetPricePerUnit() + u = nil + u.GetPricePerUnit() +} + +func TestUsageItem_GetProduct(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{Product: &zeroValue} + u.GetProduct() + u = &UsageItem{} + u.GetProduct() + u = nil + u.GetProduct() +} + +func TestUsageItem_GetQuantity(tt *testing.T) { + tt.Parallel() + u := &UsageItem{} + u.GetQuantity() + u = nil + u.GetQuantity() +} + +func TestUsageItem_GetRepositoryName(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{RepositoryName: &zeroValue} + u.GetRepositoryName() + u = &UsageItem{} + u.GetRepositoryName() + u = nil + u.GetRepositoryName() +} + +func TestUsageItem_GetSKU(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{SKU: &zeroValue} + u.GetSKU() + u = &UsageItem{} + u.GetSKU() + u = nil + u.GetSKU() +} + +func TestUsageItem_GetUnitType(tt *testing.T) { + tt.Parallel() + var zeroValue string + u := &UsageItem{UnitType: &zeroValue} + u.GetUnitType() + u = &UsageItem{} + u.GetUnitType() + u = nil + u.GetUnitType() +} + +func TestUsageReportOptions_GetDay(tt *testing.T) { + tt.Parallel() + var zeroValue int + u := &UsageReportOptions{Day: &zeroValue} + u.GetDay() + u = &UsageReportOptions{} + u.GetDay() + u = nil + u.GetDay() +} + +func TestUsageReportOptions_GetHour(tt *testing.T) { + tt.Parallel() + var zeroValue int + u := &UsageReportOptions{Hour: &zeroValue} + u.GetHour() + u = &UsageReportOptions{} + u.GetHour() + u = nil + u.GetHour() +} + +func TestUsageReportOptions_GetMonth(tt *testing.T) { + tt.Parallel() + var zeroValue int + u := &UsageReportOptions{Month: &zeroValue} + u.GetMonth() + u = &UsageReportOptions{} + u.GetMonth() + u = nil + u.GetMonth() +} + +func TestUsageReportOptions_GetYear(tt *testing.T) { + tt.Parallel() + var zeroValue int + u := &UsageReportOptions{Year: &zeroValue} + u.GetYear() + u = &UsageReportOptions{} + u.GetYear() + u = nil + u.GetYear() +} + func TestUser_GetAssignment(tt *testing.T) { tt.Parallel() var zeroValue string