Skip to content

feat: Add enterprise billing usage endpoints and response types#4288

Open
maishivamhoo123 wants to merge 7 commits into
google:masterfrom
maishivamhoo123:refactor/enterprise-billing-merge-structs
Open

feat: Add enterprise billing usage endpoints and response types#4288
maishivamhoo123 wants to merge 7 commits into
google:masterfrom
maishivamhoo123:refactor/enterprise-billing-merge-structs

Conversation

@maishivamhoo123

@maishivamhoo123 maishivamhoo123 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds support for the GitHub Enterprise billing usage API endpoints.
#4262

New methods on BillingService

GetEnterpriseUsageReport
GetEnterpriseUsageSummary
GetEnterprisePremiumRequestUsageReport
GetEnterpriseAICreditUsage

And added test for all the new End points .

Comment thread github/enterprise_billing.go Outdated
@gmlewis gmlewis changed the title Add enterprise billing usage endpoints and response types feat: Add enterprise billing usage endpoints and response types Jun 8, 2026
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.47%. Comparing base (946bd71) to head (dc88042).

Files with missing lines Patch % Lines
github/enterprise_billing.go 84.61% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4288      +/-   ##
==========================================
- Coverage   97.49%   97.47%   -0.03%     
==========================================
  Files         192      193       +1     
  Lines       19256    19308      +52     
==========================================
+ Hits        18774    18820      +46     
- Misses        267      269       +2     
- Partials      215      219       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: maishivamhoo123 <maishivamhoo@gmail.com>
@maishivamhoo123

Copy link
Copy Markdown
Contributor Author

@alexandear @gmlewis @Not-Dhananjay-Mishra i made all the changes can you please review it ?
Thank you.

Comment on lines +14 to +34
type EnterpriseUsageReportOptions struct {
Year int `url:"year,omitempty"`
Month int `url:"month,omitempty"`
Day int `url:"day,omitempty"`
CostCenterID string `url:"cost_center_id,omitempty"`
}

// EnterprisePremiumRequestUsageReportOptions specifies optional parameters for the BillingService.GetEnterprisePremiumRequestUsageReport and BillingService.GetEnterpriseAICreditUsage methods.
type EnterprisePremiumRequestUsageReportOptions struct {
Year int `url:"year,omitempty"`
Month int `url:"month,omitempty"`
Day int `url:"day,omitempty"`
Organization string `url:"organization,omitempty"`
User string `url:"user,omitempty"`
Model string `url:"model,omitempty"`
Product string `url:"product,omitempty"`
CostCenterID string `url:"cost_center_id,omitempty"`
}

// EnterpriseUsageSummaryOptions specifies optional parameters for the BillingService.GetEnterpriseUsageSummary method.
type EnterpriseUsageSummaryOptions struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these option structs have similar fields:
Image

I think we can embed EnterpriseUsageReportOptions into EnterprisePremiumRequestUsageReportOptions and EnterpriseUsageSummaryOptions.

}
}

func TestEnterpriseService_GetUsageSummary_WithRepository(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this test? It duplicates TestEnterpriseService_GetUsageSummary_WithAllFilters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review all tests and try not adding redundant tests that check the same functionality.

// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-summary-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/settings/billing/usage/summary
func (s *EnterpriseService) GetUsageSummary(ctx context.Context, enterprise string, opts *EnterpriseUsageSummaryOptions) (*EnterpriseAggregatedUsageReport, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response schema of GetUsageSummary is little bit different from GetPremiumRequestUsageReport and GetAICreditUsage. Its response schema doesn't contain user and model, In my opinion we should make a new struct for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants