Skip to content

Commit 06b8b3a

Browse files
authored
refactor!: Adjust function names and field types for billing API (#3770)
BREAKING CHANGE: Billing-related methods are renamed to <verb><scope><subject> pattern, and required fields are changed to value types.
1 parent 8fd1cb9 commit 06b8b3a

File tree

4 files changed

+296
-393
lines changed

4 files changed

+296
-393
lines changed

github/billing.go

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,54 @@ type BillingService service
1919
// MinutesUsedBreakdown counts the actions minutes used by machine type (e.g. UBUNTU, WINDOWS, MACOS).
2020
type MinutesUsedBreakdown = map[string]int
2121

22-
// PackageBilling represents a GitHub Package billing.
23-
type PackageBilling struct {
24-
TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
25-
TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
26-
IncludedGigabytesBandwidth float64 `json:"included_gigabytes_bandwidth"`
22+
// PackagesBilling represents billing of GitHub Packages .
23+
type PackagesBilling struct {
24+
TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
25+
TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
26+
IncludedGigabytesBandwidth int `json:"included_gigabytes_bandwidth"`
2727
}
2828

2929
// StorageBilling represents a GitHub Storage billing.
3030
type StorageBilling struct {
31-
DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
32-
EstimatedPaidStorageForMonth float64 `json:"estimated_paid_storage_for_month"`
33-
EstimatedStorageForMonth float64 `json:"estimated_storage_for_month"`
31+
DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
32+
EstimatedPaidStorageForMonth int `json:"estimated_paid_storage_for_month"`
33+
EstimatedStorageForMonth int `json:"estimated_storage_for_month"`
34+
}
35+
36+
// ActiveCommittersListOptions specifies optional parameters to the
37+
// BillingService.GetAdvancedSecurityActiveCommittersOrg method.
38+
type ActiveCommittersListOptions struct {
39+
// The security product to get GitHub Advanced Security active committers for. For standalone
40+
// Code Scanning or Secret Protection products, this parameter is required to specify which
41+
// product you want committer information for. For other plans this parameter cannot be used.
42+
//
43+
// Can be one of: "code_security", "secret_protection".
44+
AdvancedSecurityProduct *string `url:"advanced_security_product,omitempty"`
45+
46+
ListOptions
3447
}
3548

3649
// ActiveCommitters represents the total active committers across all repositories in an Organization.
3750
type ActiveCommitters struct {
38-
TotalAdvancedSecurityCommitters int `json:"total_advanced_security_committers"`
39-
TotalCount int `json:"total_count"`
40-
MaximumAdvancedSecurityCommitters int `json:"maximum_advanced_security_committers"`
41-
PurchasedAdvancedSecurityCommitters int `json:"purchased_advanced_security_committers"`
42-
Repositories []*RepositoryActiveCommitters `json:"repositories,omitempty"`
51+
TotalAdvancedSecurityCommitters *int `json:"total_advanced_security_committers,omitempty"`
52+
TotalCount *int `json:"total_count,omitempty"`
53+
MaximumAdvancedSecurityCommitters *int `json:"maximum_advanced_security_committers,omitempty"`
54+
PurchasedAdvancedSecurityCommitters *int `json:"purchased_advanced_security_committers,omitempty"`
55+
Repositories []*RepositoryActiveCommitters `json:"repositories"`
4356
}
4457

4558
// RepositoryActiveCommitters represents active committers on each repository.
4659
type RepositoryActiveCommitters struct {
47-
Name *string `json:"name,omitempty"`
48-
AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"`
49-
AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"`
60+
Name string `json:"name"`
61+
AdvancedSecurityCommitters int `json:"advanced_security_committers"`
62+
AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown"`
5063
}
5164

5265
// AdvancedSecurityCommittersBreakdown represents the user activity breakdown for ActiveCommitters.
5366
type AdvancedSecurityCommittersBreakdown struct {
54-
UserLogin *string `json:"user_login,omitempty"`
55-
LastPushedDate *string `json:"last_pushed_date,omitempty"`
67+
UserLogin string `json:"user_login"`
68+
LastPushedDate string `json:"last_pushed_date"`
69+
LastPushedEmail string `json:"last_pushed_email"`
5670
}
5771

5872
// UsageReportOptions specifies optional parameters for the enhanced billing platform usage report.
@@ -104,16 +118,16 @@ type PremiumRequestUsageReportOptions struct {
104118

105119
// UsageItem represents a single usage item in the enhanced billing platform report.
106120
type UsageItem struct {
107-
Date *string `json:"date"`
108-
Product *string `json:"product"`
109-
SKU *string `json:"sku"`
110-
Quantity *float64 `json:"quantity"`
111-
UnitType *string `json:"unitType"`
112-
PricePerUnit *float64 `json:"pricePerUnit"`
113-
GrossAmount *float64 `json:"grossAmount"`
114-
DiscountAmount *float64 `json:"discountAmount"`
115-
NetAmount *float64 `json:"netAmount"`
116-
RepositoryName *string `json:"repositoryName,omitempty"`
121+
Date string `json:"date"`
122+
Product string `json:"product"`
123+
SKU string `json:"sku"`
124+
Quantity int `json:"quantity"`
125+
UnitType string `json:"unitType"`
126+
PricePerUnit float64 `json:"pricePerUnit"`
127+
GrossAmount float64 `json:"grossAmount"`
128+
DiscountAmount float64 `json:"discountAmount"`
129+
NetAmount float64 `json:"netAmount"`
130+
RepositoryName *string `json:"repositoryName,omitempty"`
117131
// Organization name is only used for organization-level reports.
118132
OrganizationName *string `json:"organizationName,omitempty"`
119133
}
@@ -147,63 +161,65 @@ type PremiumRequestUsageTimePeriod struct {
147161

148162
// PremiumRequestUsageReport represents the premium request usage report response.
149163
type PremiumRequestUsageReport struct {
150-
TimePeriod PremiumRequestUsageTimePeriod `json:"timePeriod"`
151-
Organization string `json:"organization"`
152-
User *string `json:"user,omitempty"`
153-
Product *string `json:"product,omitempty"`
154-
Model *string `json:"model,omitempty"`
155-
UsageItems []*PremiumRequestUsageItem `json:"usageItems"`
164+
TimePeriod PremiumRequestUsageTimePeriod `json:"timePeriod"`
165+
// Organization is only set for organization-level reports.
166+
Organization *string `json:"organization,omitempty"`
167+
// User is only set for user-level reports.
168+
User *string `json:"user,omitempty"`
169+
Product *string `json:"product,omitempty"`
170+
Model *string `json:"model,omitempty"`
171+
UsageItems []*PremiumRequestUsageItem `json:"usageItems"`
156172
}
157173

158-
// GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
174+
// GetOrganizationPackagesBilling returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
159175
//
160176
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-an-organization
161177
//
162178
//meta:operation GET /orgs/{org}/settings/billing/packages
163-
func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string) (*PackageBilling, *Response, error) {
179+
func (s *BillingService) GetOrganizationPackagesBilling(ctx context.Context, org string) (*PackagesBilling, *Response, error) {
164180
u := fmt.Sprintf("orgs/%v/settings/billing/packages", org)
165181
req, err := s.client.NewRequest("GET", u, nil)
166182
if err != nil {
167183
return nil, nil, err
168184
}
169185

170-
packagesOrgBilling := new(PackageBilling)
171-
resp, err := s.client.Do(ctx, req, packagesOrgBilling)
186+
result := new(PackagesBilling)
187+
resp, err := s.client.Do(ctx, req, result)
172188
if err != nil {
173189
return nil, resp, err
174190
}
175191

176-
return packagesOrgBilling, resp, nil
192+
return result, resp, nil
177193
}
178194

179-
// GetStorageBillingOrg returns the estimated paid and estimated total storage used for GitHub Actions
195+
// GetOrganizationStorageBilling returns the estimated paid and estimated total storage used for GitHub Actions
180196
// and GitHub Packages in gigabytes for an Org.
181197
//
182198
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-an-organization
183199
//
184200
//meta:operation GET /orgs/{org}/settings/billing/shared-storage
185-
func (s *BillingService) GetStorageBillingOrg(ctx context.Context, org string) (*StorageBilling, *Response, error) {
201+
func (s *BillingService) GetOrganizationStorageBilling(ctx context.Context, org string) (*StorageBilling, *Response, error) {
186202
u := fmt.Sprintf("orgs/%v/settings/billing/shared-storage", org)
187203
req, err := s.client.NewRequest("GET", u, nil)
188204
if err != nil {
189205
return nil, nil, err
190206
}
191207

192-
storageOrgBilling := new(StorageBilling)
193-
resp, err := s.client.Do(ctx, req, storageOrgBilling)
208+
result := new(StorageBilling)
209+
resp, err := s.client.Do(ctx, req, result)
194210
if err != nil {
195211
return nil, resp, err
196212
}
197213

198-
return storageOrgBilling, resp, nil
214+
return result, resp, nil
199215
}
200216

201-
// GetAdvancedSecurityActiveCommittersOrg returns the GitHub Advanced Security active committers for an organization per repository.
217+
// GetOrganizationAdvancedSecurityActiveCommitters returns the GitHub Advanced Security active committers for an organization per repository.
202218
//
203219
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/billing#get-github-advanced-security-active-committers-for-an-organization
204220
//
205221
//meta:operation GET /orgs/{org}/settings/billing/advanced-security
206-
func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Context, org string, opts *ListOptions) (*ActiveCommitters, *Response, error) {
222+
func (s *BillingService) GetOrganizationAdvancedSecurityActiveCommitters(ctx context.Context, org string, opts *ActiveCommittersListOptions) (*ActiveCommitters, *Response, error) {
207223
u := fmt.Sprintf("orgs/%v/settings/billing/advanced-security", org)
208224
u, err := addOptions(u, opts)
209225
if err != nil {
@@ -215,28 +231,28 @@ func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Cont
215231
return nil, nil, err
216232
}
217233

218-
activeOrgCommitters := new(ActiveCommitters)
219-
resp, err := s.client.Do(ctx, req, activeOrgCommitters)
234+
result := new(ActiveCommitters)
235+
resp, err := s.client.Do(ctx, req, result)
220236
if err != nil {
221237
return nil, resp, err
222238
}
223239

224-
return activeOrgCommitters, resp, nil
240+
return result, resp, nil
225241
}
226242

227-
// GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
243+
// GetPackagesBilling returns the free and paid storage used for GitHub Packages in gigabytes for a user.
228244
//
229245
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-github-packages-billing-for-a-user
230246
//
231247
//meta:operation GET /users/{username}/settings/billing/packages
232-
func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string) (*PackageBilling, *Response, error) {
248+
func (s *BillingService) GetPackagesBilling(ctx context.Context, user string) (*PackagesBilling, *Response, error) {
233249
u := fmt.Sprintf("users/%v/settings/billing/packages", user)
234250
req, err := s.client.NewRequest("GET", u, nil)
235251
if err != nil {
236252
return nil, nil, err
237253
}
238254

239-
packagesUserBilling := new(PackageBilling)
255+
packagesUserBilling := new(PackagesBilling)
240256
resp, err := s.client.Do(ctx, req, packagesUserBilling)
241257
if err != nil {
242258
return nil, resp, err
@@ -245,13 +261,13 @@ func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string
245261
return packagesUserBilling, resp, nil
246262
}
247263

248-
// GetStorageBillingUser returns the estimated paid and estimated total storage used for GitHub Actions
264+
// GetStorageBilling returns the estimated paid and estimated total storage used for GitHub Actions
249265
// and GitHub Packages in gigabytes for a user.
250266
//
251267
// GitHub API docs: https://docs.github.com/rest/billing/billing#get-shared-storage-billing-for-a-user
252268
//
253269
//meta:operation GET /users/{username}/settings/billing/shared-storage
254-
func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string) (*StorageBilling, *Response, error) {
270+
func (s *BillingService) GetStorageBilling(ctx context.Context, user string) (*StorageBilling, *Response, error) {
255271
u := fmt.Sprintf("users/%v/settings/billing/shared-storage", user)
256272
req, err := s.client.NewRequest("GET", u, nil)
257273
if err != nil {
@@ -267,14 +283,14 @@ func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string)
267283
return storageUserBilling, resp, nil
268284
}
269285

270-
// GetUsageReportOrg returns a report of the total usage for an organization using the enhanced billing platform.
286+
// GetOrganizationUsageReport returns a report of the total usage for an organization using the enhanced billing platform.
271287
//
272288
// Note: This endpoint is only available to organizations with access to the enhanced billing platform.
273289
//
274290
// GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-an-organization
275291
//
276292
//meta:operation GET /organizations/{org}/settings/billing/usage
277-
func (s *BillingService) GetUsageReportOrg(ctx context.Context, org string, opts *UsageReportOptions) (*UsageReport, *Response, error) {
293+
func (s *BillingService) GetOrganizationUsageReport(ctx context.Context, org string, opts *UsageReportOptions) (*UsageReport, *Response, error) {
278294
u := fmt.Sprintf("organizations/%v/settings/billing/usage", org)
279295
u, err := addOptions(u, opts)
280296
if err != nil {
@@ -295,14 +311,14 @@ func (s *BillingService) GetUsageReportOrg(ctx context.Context, org string, opts
295311
return usageReport, resp, nil
296312
}
297313

298-
// GetUsageReportUser returns a report of the total usage for a user using the enhanced billing platform.
314+
// GetUsageReport returns a report of the total usage for a user using the enhanced billing platform.
299315
//
300316
// Note: This endpoint is only available to users with access to the enhanced billing platform.
301317
//
302318
// GitHub API docs: https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-a-user
303319
//
304320
//meta:operation GET /users/{username}/settings/billing/usage
305-
func (s *BillingService) GetUsageReportUser(ctx context.Context, user string, opts *UsageReportOptions) (*UsageReport, *Response, error) {
321+
func (s *BillingService) GetUsageReport(ctx context.Context, user string, opts *UsageReportOptions) (*UsageReport, *Response, error) {
306322
u := fmt.Sprintf("users/%v/settings/billing/usage", user)
307323
u, err := addOptions(u, opts)
308324
if err != nil {

0 commit comments

Comments
 (0)