From f3141fa51bb6e292a1bd644af0aff741c3a0fbb3 Mon Sep 17 00:00:00 2001 From: Manas Sivakumar Date: Wed, 27 Aug 2025 20:44:49 +0530 Subject: [PATCH 1/4] Remove BillingActions for User and Organisation Actions is now supported in enhanced billing only convert struct fields to pass by value from pointers for easier processing --- github/billing.go | 67 ++++--------- github/billing_test.go | 209 +++++------------------------------------ 2 files changed, 40 insertions(+), 236 deletions(-) diff --git a/github/billing.go b/github/billing.go index 0776358cdb2..c0c06e8c1ec 100644 --- a/github/billing.go +++ b/github/billing.go @@ -16,14 +16,6 @@ import ( // GitHub API docs: https://docs.github.com/rest/billing type BillingService service -// ActionBilling represents a GitHub Action billing. -type ActionBilling struct { - TotalMinutesUsed float64 `json:"total_minutes_used"` - TotalPaidMinutesUsed float64 `json:"total_paid_minutes_used"` - IncludedMinutes float64 `json:"included_minutes"` - MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"` -} - // MinutesUsedBreakdown counts the actions minutes used by machine type (e.g. UBUNTU, WINDOWS, MACOS). type MinutesUsedBreakdown = map[string]int @@ -52,50 +44,50 @@ type ActiveCommitters struct { // RepositoryActiveCommitters represents active committers on each repository. type RepositoryActiveCommitters struct { - Name *string `json:"name,omitempty"` - AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"` + Name string `json:"name,omitempty"` + AdvancedSecurityCommitters int `json:"advanced_security_committers,omitempty"` AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"` } // AdvancedSecurityCommittersBreakdown represents the user activity breakdown for ActiveCommitters. type AdvancedSecurityCommittersBreakdown struct { - UserLogin *string `json:"user_login,omitempty"` - LastPushedDate *string `json:"last_pushed_date,omitempty"` + UserLogin string `json:"user_login,omitempty"` + LastPushedDate string `json:"last_pushed_date,omitempty"` } // UsageReportOptions specifies optional parameters for the enhanced billing platform usage report. type UsageReportOptions struct { // 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"` + 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. // If no year is specified the default year is used. - Month *int `url:"month,omitempty"` + 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"` + Day int `url:"day,omitempty"` // If specified, only return results for a single hour. The value of hour is an integer between 0 and 23. // If no year, month, or day is specified, the default year, month, and day are used. - Hour *int `url:"hour,omitempty"` + Hour int `url:"hour,omitempty"` } // UsageItem represents a single usage item in the enhanced billing platform report. type UsageItem 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"` - RepositoryName *string `json:"repositoryName,omitempty"` + 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"` + RepositoryName string `json:"repositoryName,omitempty"` // Organization name is only used for organization-level reports. - OrganizationName *string `json:"organizationName,omitempty"` + OrganizationName string `json:"organizationName,omitempty"` } // UsageReport represents the enhanced billing platform usage report response. @@ -103,27 +95,6 @@ type UsageReport struct { UsageItems []*UsageItem `json:"usageItems,omitempty"` } -// GetActionsBillingOrg returns the summary of the free and paid GitHub Actions minutes used for an Org. -// -// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-an-organization -// -//meta:operation GET /orgs/{org}/settings/billing/actions -func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (*ActionBilling, *Response, error) { - u := fmt.Sprintf("orgs/%v/settings/billing/actions", org) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - actionsOrgBilling := new(ActionBilling) - resp, err := s.client.Do(ctx, req, actionsOrgBilling) - if err != nil { - return nil, resp, err - } - - return actionsOrgBilling, resp, nil -} - // 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 diff --git a/github/billing_test.go b/github/billing_test.go index 3c29054840b..c0772dd949c 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -14,111 +14,6 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestBillingService_GetActionsBillingOrg(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/orgs/o/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "total_minutes_used": 305.0, - "total_paid_minutes_used": 0.0, - "included_minutes": 3000.0, - "minutes_used_breakdown": { - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90 - } - }`) - }) - - ctx := context.Background() - hook, _, err := client.Billing.GetActionsBillingOrg(ctx, "o") - if err != nil { - t.Errorf("Billing.GetActionsBillingOrg returned error: %v", err) - } - - want := &ActionBilling{ - TotalMinutesUsed: 305.0, - TotalPaidMinutesUsed: 0.0, - IncludedMinutes: 3000.0, - MinutesUsedBreakdown: MinutesUsedBreakdown{ - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90, - }, - } - if !cmp.Equal(hook, want) { - t.Errorf("Billing.GetActionsBillingOrg returned %+v, want %+v", hook, want) - } - - const methodName = "GetActionsBillingOrg" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetActionsBillingOrg(ctx, "o") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestBillingService_GetActionsBillingOrg_invalidOrg(t *testing.T) { - t.Parallel() - client, _, _ := setup(t) - - ctx := context.Background() - _, _, err := client.Billing.GetActionsBillingOrg(ctx, "%") - testURLParseError(t, err) -} - -func TestBillingService_GetPackagesBillingOrg(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/orgs/o/settings/billing/packages", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "total_gigabytes_bandwidth_used": 50, - "total_paid_gigabytes_bandwidth_used": 40, - "included_gigabytes_bandwidth": 10 - }`) - }) - - ctx := context.Background() - hook, _, err := client.Billing.GetPackagesBillingOrg(ctx, "o") - if err != nil { - t.Errorf("Billing.GetPackagesBillingOrg returned error: %v", err) - } - - want := &PackageBilling{ - TotalGigabytesBandwidthUsed: 50, - TotalPaidGigabytesBandwidthUsed: 40, - IncludedGigabytesBandwidth: 10, - } - if !cmp.Equal(hook, want) { - t.Errorf("Billing.GetPackagesBillingOrg returned %+v, want %+v", hook, want) - } - - const methodName = "GetPackagesBillingOrg" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetPackagesBillingOrg(ctx, "\n") - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetPackagesBillingOrg(ctx, "o") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - func TestBillingService_GetPackagesBillingOrg_invalidOrg(t *testing.T) { t.Parallel() client, _, _ := setup(t) @@ -180,68 +75,6 @@ func TestBillingService_GetStorageBillingOrg_invalidOrg(t *testing.T) { testURLParseError(t, err) } -func TestBillingService_GetActionsBillingUser(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/users/u/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "total_minutes_used": 10, - "total_paid_minutes_used": 0, - "included_minutes": 3000, - "minutes_used_breakdown": { - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90 - } - }`) - }) - - ctx := context.Background() - hook, _, err := client.Billing.GetActionsBillingUser(ctx, "u") - if err != nil { - t.Errorf("Billing.GetActionsBillingUser returned error: %v", err) - } - - want := &ActionBilling{ - TotalMinutesUsed: 10, - TotalPaidMinutesUsed: 0, - IncludedMinutes: 3000, - MinutesUsedBreakdown: MinutesUsedBreakdown{ - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90, - }, - } - if !cmp.Equal(hook, want) { - t.Errorf("Billing.GetActionsBillingUser returned %+v, want %+v", hook, want) - } - - const methodName = "GetActionsBillingUser" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetActionsBillingUser(ctx, "o") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestBillingService_GetActionsBillingUser_invalidUser(t *testing.T) { - t.Parallel() - client, _, _ := setup(t) - - ctx := context.Background() - _, _, err := client.Billing.GetActionsBillingUser(ctx, "%") - testURLParseError(t, err) -} - func TestBillingService_GetPackagesBillingUser(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -553,17 +386,17 @@ func TestBillingService_GetUsageReportOrg(t *testing.T) { want := &UsageReport{ UsageItems: []*UsageItem{ { - Date: Ptr("2023-08-01"), - Product: Ptr("Actions"), - SKU: Ptr("Actions Linux"), - Quantity: Ptr(100.0), - UnitType: Ptr("minutes"), - PricePerUnit: Ptr(0.008), - GrossAmount: Ptr(0.8), - DiscountAmount: Ptr(0.0), - NetAmount: Ptr(0.8), - OrganizationName: Ptr("GitHub"), - RepositoryName: Ptr("github/example"), + 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: "github/example", }, }, } @@ -634,16 +467,16 @@ func TestBillingService_GetUsageReportUser(t *testing.T) { want := &UsageReport{ UsageItems: []*UsageItem{ { - Date: Ptr("2023-08-15"), - Product: Ptr("Codespaces"), - SKU: Ptr("Codespaces Linux"), - Quantity: Ptr(50.0), - UnitType: Ptr("hours"), - PricePerUnit: Ptr(0.18), - GrossAmount: Ptr(9.0), - DiscountAmount: Ptr(1.0), - NetAmount: Ptr(8.0), - RepositoryName: Ptr("user/example"), + Date: "2023-08-15", + Product: "Codespaces", + SKU: "Codespaces Linux", + Quantity: 50.0, + UnitType: "hours", + PricePerUnit: 0.18, + GrossAmount: 9.0, + DiscountAmount: 1.0, + NetAmount: 8.0, + RepositoryName: "user/example", }, }, } From 17c8904107197b56b95bc088b50393ede1950279 Mon Sep 17 00:00:00 2001 From: Manas Sivakumar Date: Wed, 27 Aug 2025 21:23:24 +0530 Subject: [PATCH 2/4] undo dereferenceing stuff --- github/billing.go | 53 ++++------- github/billing_test.go | 211 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 205 insertions(+), 59 deletions(-) diff --git a/github/billing.go b/github/billing.go index c0c06e8c1ec..2820ab9e457 100644 --- a/github/billing.go +++ b/github/billing.go @@ -39,20 +39,20 @@ type ActiveCommitters struct { TotalCount int `json:"total_count"` MaximumAdvancedSecurityCommitters int `json:"maximum_advanced_security_committers"` PurchasedAdvancedSecurityCommitters int `json:"purchased_advanced_security_committers"` - Repositories []*RepositoryActiveCommitters `json:"repositories,omitempty"` + Repositories []RepositoryActiveCommitters `json:"repositories,omitempty"` } // RepositoryActiveCommitters represents active committers on each repository. type RepositoryActiveCommitters struct { - Name string `json:"name,omitempty"` - AdvancedSecurityCommitters int `json:"advanced_security_committers,omitempty"` + Name *string `json:"name,omitempty"` + AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"` AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"` } // AdvancedSecurityCommittersBreakdown represents the user activity breakdown for ActiveCommitters. type AdvancedSecurityCommittersBreakdown struct { - UserLogin string `json:"user_login,omitempty"` - LastPushedDate string `json:"last_pushed_date,omitempty"` + UserLogin *string `json:"user_login,omitempty"` + LastPushedDate *string `json:"last_pushed_date,omitempty"` } // UsageReportOptions specifies optional parameters for the enhanced billing platform usage report. @@ -76,18 +76,18 @@ type UsageReportOptions struct { // UsageItem represents a single usage item in the enhanced billing platform report. type UsageItem 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"` - RepositoryName string `json:"repositoryName,omitempty"` + 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"` + RepositoryName *string `json:"repositoryName,omitempty"` // Organization name is only used for organization-level reports. - OrganizationName string `json:"organizationName,omitempty"` + OrganizationName *string `json:"organizationName,omitempty"` } // UsageReport represents the enhanced billing platform usage report response. @@ -164,27 +164,6 @@ func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Cont return activeOrgCommitters, resp, nil } -// GetActionsBillingUser returns the summary of the free and paid GitHub Actions minutes used for a user. -// -// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-actions-billing-for-a-user -// -//meta:operation GET /users/{username}/settings/billing/actions -func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string) (*ActionBilling, *Response, error) { - u := fmt.Sprintf("users/%v/settings/billing/actions", user) - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - actionsUserBilling := new(ActionBilling) - resp, err := s.client.Do(ctx, req, actionsUserBilling) - if err != nil { - return nil, resp, err - } - - return actionsUserBilling, resp, nil -} - // GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user. // // GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-a-user diff --git a/github/billing_test.go b/github/billing_test.go index c0772dd949c..0eb3c188c91 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -14,6 +14,111 @@ import ( "github.com/google/go-cmp/cmp" ) +func TestBillingService_GetActionsBillingOrg(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "total_minutes_used": 305.0, + "total_paid_minutes_used": 0.0, + "included_minutes": 3000.0, + "minutes_used_breakdown": { + "UBUNTU": 205, + "MACOS": 10, + "WINDOWS": 90 + } + }`) + }) + + ctx := context.Background() + hook, _, err := client.Billing.GetActionsBillingOrg(ctx, "o") + if err != nil { + t.Errorf("Billing.GetActionsBillingOrg returned error: %v", err) + } + + want := &ActionBilling{ + TotalMinutesUsed: 305.0, + TotalPaidMinutesUsed: 0.0, + IncludedMinutes: 3000.0, + MinutesUsedBreakdown: MinutesUsedBreakdown{ + "UBUNTU": 205, + "MACOS": 10, + "WINDOWS": 90, + }, + } + if !cmp.Equal(hook, want) { + t.Errorf("Billing.GetActionsBillingOrg returned %+v, want %+v", hook, want) + } + + const methodName = "GetActionsBillingOrg" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetActionsBillingOrg(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetActionsBillingOrg_invalidOrg(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := context.Background() + _, _, err := client.Billing.GetActionsBillingOrg(ctx, "%") + testURLParseError(t, err) +} + +func TestBillingService_GetPackagesBillingOrg(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/settings/billing/packages", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "total_gigabytes_bandwidth_used": 50, + "total_paid_gigabytes_bandwidth_used": 40, + "included_gigabytes_bandwidth": 10 + }`) + }) + + ctx := context.Background() + hook, _, err := client.Billing.GetPackagesBillingOrg(ctx, "o") + if err != nil { + t.Errorf("Billing.GetPackagesBillingOrg returned error: %v", err) + } + + want := &PackageBilling{ + TotalGigabytesBandwidthUsed: 50, + TotalPaidGigabytesBandwidthUsed: 40, + IncludedGigabytesBandwidth: 10, + } + if !cmp.Equal(hook, want) { + t.Errorf("Billing.GetPackagesBillingOrg returned %+v, want %+v", hook, want) + } + + const methodName = "GetPackagesBillingOrg" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetPackagesBillingOrg(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetPackagesBillingOrg(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + func TestBillingService_GetPackagesBillingOrg_invalidOrg(t *testing.T) { t.Parallel() client, _, _ := setup(t) @@ -75,6 +180,68 @@ func TestBillingService_GetStorageBillingOrg_invalidOrg(t *testing.T) { testURLParseError(t, err) } +func TestBillingService_GetActionsBillingUser(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/users/u/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "total_minutes_used": 10, + "total_paid_minutes_used": 0, + "included_minutes": 3000, + "minutes_used_breakdown": { + "UBUNTU": 205, + "MACOS": 10, + "WINDOWS": 90 + } + }`) + }) + + ctx := context.Background() + hook, _, err := client.Billing.GetActionsBillingUser(ctx, "u") + if err != nil { + t.Errorf("Billing.GetActionsBillingUser returned error: %v", err) + } + + want := &ActionBilling{ + TotalMinutesUsed: 10, + TotalPaidMinutesUsed: 0, + IncludedMinutes: 3000, + MinutesUsedBreakdown: MinutesUsedBreakdown{ + "UBUNTU": 205, + "MACOS": 10, + "WINDOWS": 90, + }, + } + if !cmp.Equal(hook, want) { + t.Errorf("Billing.GetActionsBillingUser returned %+v, want %+v", hook, want) + } + + const methodName = "GetActionsBillingUser" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetActionsBillingUser(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetActionsBillingUser_invalidUser(t *testing.T) { + t.Parallel() + client, _, _ := setup(t) + + ctx := context.Background() + _, _, err := client.Billing.GetActionsBillingUser(ctx, "%") + testURLParseError(t, err) +} + func TestBillingService_GetPackagesBillingUser(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -386,17 +553,17 @@ func TestBillingService_GetUsageReportOrg(t *testing.T) { want := &UsageReport{ UsageItems: []*UsageItem{ { - 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: "github/example", + Date: Ptr("2023-08-01"), + Product: Ptr("Actions"), + SKU: Ptr("Actions Linux"), + Quantity: Ptr(100.0), + UnitType: Ptr("minutes"), + PricePerUnit: Ptr(0.008), + GrossAmount: Ptr(0.8), + DiscountAmount: Ptr(0.0), + NetAmount: Ptr(0.8), + OrganizationName: Ptr("GitHub"), + RepositoryName: Ptr("github/example"), }, }, } @@ -467,16 +634,16 @@ func TestBillingService_GetUsageReportUser(t *testing.T) { want := &UsageReport{ UsageItems: []*UsageItem{ { - Date: "2023-08-15", - Product: "Codespaces", - SKU: "Codespaces Linux", - Quantity: 50.0, - UnitType: "hours", - PricePerUnit: 0.18, - GrossAmount: 9.0, - DiscountAmount: 1.0, - NetAmount: 8.0, - RepositoryName: "user/example", + Date: Ptr("2023-08-15"), + Product: Ptr("Codespaces"), + SKU: Ptr("Codespaces Linux"), + Quantity: Ptr(50.0), + UnitType: Ptr("hours"), + PricePerUnit: Ptr(0.18), + GrossAmount: Ptr(9.0), + DiscountAmount: Ptr(1.0), + NetAmount: Ptr(8.0), + RepositoryName: Ptr("user/example"), }, }, } @@ -506,4 +673,4 @@ func TestBillingService_GetUsageReportUser_invalidUser(t *testing.T) { ctx := context.Background() _, _, err := client.Billing.GetUsageReportUser(ctx, "%", nil) testURLParseError(t, err) -} +} \ No newline at end of file From 532a82a6382b116af698019d1293112514ae1a8c Mon Sep 17 00:00:00 2001 From: Manas Sivakumar Date: Wed, 27 Aug 2025 21:24:55 +0530 Subject: [PATCH 3/4] remove tests for actionsbilling --- github/billing_test.go | 124 ----------------------------------------- 1 file changed, 124 deletions(-) diff --git a/github/billing_test.go b/github/billing_test.go index 0eb3c188c91..784d324541d 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -14,68 +14,6 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestBillingService_GetActionsBillingOrg(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/orgs/o/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "total_minutes_used": 305.0, - "total_paid_minutes_used": 0.0, - "included_minutes": 3000.0, - "minutes_used_breakdown": { - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90 - } - }`) - }) - - ctx := context.Background() - hook, _, err := client.Billing.GetActionsBillingOrg(ctx, "o") - if err != nil { - t.Errorf("Billing.GetActionsBillingOrg returned error: %v", err) - } - - want := &ActionBilling{ - TotalMinutesUsed: 305.0, - TotalPaidMinutesUsed: 0.0, - IncludedMinutes: 3000.0, - MinutesUsedBreakdown: MinutesUsedBreakdown{ - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90, - }, - } - if !cmp.Equal(hook, want) { - t.Errorf("Billing.GetActionsBillingOrg returned %+v, want %+v", hook, want) - } - - const methodName = "GetActionsBillingOrg" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetActionsBillingOrg(ctx, "o") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestBillingService_GetActionsBillingOrg_invalidOrg(t *testing.T) { - t.Parallel() - client, _, _ := setup(t) - - ctx := context.Background() - _, _, err := client.Billing.GetActionsBillingOrg(ctx, "%") - testURLParseError(t, err) -} - func TestBillingService_GetPackagesBillingOrg(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -180,68 +118,6 @@ func TestBillingService_GetStorageBillingOrg_invalidOrg(t *testing.T) { testURLParseError(t, err) } -func TestBillingService_GetActionsBillingUser(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/users/u/settings/billing/actions", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "total_minutes_used": 10, - "total_paid_minutes_used": 0, - "included_minutes": 3000, - "minutes_used_breakdown": { - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90 - } - }`) - }) - - ctx := context.Background() - hook, _, err := client.Billing.GetActionsBillingUser(ctx, "u") - if err != nil { - t.Errorf("Billing.GetActionsBillingUser returned error: %v", err) - } - - want := &ActionBilling{ - TotalMinutesUsed: 10, - TotalPaidMinutesUsed: 0, - IncludedMinutes: 3000, - MinutesUsedBreakdown: MinutesUsedBreakdown{ - "UBUNTU": 205, - "MACOS": 10, - "WINDOWS": 90, - }, - } - if !cmp.Equal(hook, want) { - t.Errorf("Billing.GetActionsBillingUser returned %+v, want %+v", hook, want) - } - - const methodName = "GetActionsBillingUser" - testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Billing.GetActionsBillingOrg(ctx, "\n") - return err - }) - - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Billing.GetActionsBillingUser(ctx, "o") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestBillingService_GetActionsBillingUser_invalidUser(t *testing.T) { - t.Parallel() - client, _, _ := setup(t) - - ctx := context.Background() - _, _, err := client.Billing.GetActionsBillingUser(ctx, "%") - testURLParseError(t, err) -} - func TestBillingService_GetPackagesBillingUser(t *testing.T) { t.Parallel() client, mux, _ := setup(t) From 3eafbf7c24d8ff324680201bbcbe82e625b7fe1e Mon Sep 17 00:00:00 2001 From: Manas Sivakumar Date: Wed, 27 Aug 2025 21:33:28 +0530 Subject: [PATCH 4/4] run contributing scripts --- github/billing.go | 14 +++++++------- github/billing_test.go | 31 +------------------------------ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/github/billing.go b/github/billing.go index 2820ab9e457..b98af40a398 100644 --- a/github/billing.go +++ b/github/billing.go @@ -39,13 +39,13 @@ type ActiveCommitters struct { TotalCount int `json:"total_count"` MaximumAdvancedSecurityCommitters int `json:"maximum_advanced_security_committers"` PurchasedAdvancedSecurityCommitters int `json:"purchased_advanced_security_committers"` - Repositories []RepositoryActiveCommitters `json:"repositories,omitempty"` + Repositories []*RepositoryActiveCommitters `json:"repositories,omitempty"` } // RepositoryActiveCommitters represents active committers on each repository. type RepositoryActiveCommitters struct { - Name *string `json:"name,omitempty"` - AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"` + Name *string `json:"name,omitempty"` + AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"` AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"` } @@ -59,19 +59,19 @@ type AdvancedSecurityCommittersBreakdown struct { type UsageReportOptions struct { // 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"` + 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. // If no year is specified the default year is used. - Month int `url:"month,omitempty"` + 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"` + Day *int `url:"day,omitempty"` // If specified, only return results for a single hour. The value of hour is an integer between 0 and 23. // If no year, month, or day is specified, the default year, month, and day are used. - Hour int `url:"hour,omitempty"` + Hour *int `url:"hour,omitempty"` } // UsageItem represents a single usage item in the enhanced billing platform report. diff --git a/github/billing_test.go b/github/billing_test.go index 784d324541d..62325f9c123 100644 --- a/github/billing_test.go +++ b/github/billing_test.go @@ -241,35 +241,6 @@ func TestMinutesUsedBreakdown_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } -func TestActionBilling_Marshal(t *testing.T) { - t.Parallel() - testJSONMarshal(t, &MinutesUsedBreakdown{}, "{}") - - u := &ActionBilling{ - TotalMinutesUsed: 1, - TotalPaidMinutesUsed: 1, - IncludedMinutes: 1, - MinutesUsedBreakdown: MinutesUsedBreakdown{ - "UBUNTU": 1, - "MACOS": 1, - "WINDOWS": 1, - }, - } - - want := `{ - "total_minutes_used": 1, - "total_paid_minutes_used": 1, - "included_minutes": 1, - "minutes_used_breakdown": { - "UBUNTU": 1, - "MACOS": 1, - "WINDOWS": 1 - } - }` - - testJSONMarshal(t, u, want) -} - func TestPackageBilling_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &PackageBilling{}, "{}") @@ -549,4 +520,4 @@ func TestBillingService_GetUsageReportUser_invalidUser(t *testing.T) { ctx := context.Background() _, _, err := client.Billing.GetUsageReportUser(ctx, "%", nil) testURLParseError(t, err) -} \ No newline at end of file +}