-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add enterprise billing usage endpoints and response types #4288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maishivamhoo123
wants to merge
9
commits into
google:master
Choose a base branch
from
maishivamhoo123:refactor/enterprise-billing-merge-structs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,298
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
586c067
billing: add GetAICreditUsage endpoint for organization AI credits
maishivamhoo123 629121b
Merge branch 'master' into billing/ai-credit-usage
maishivamhoo123 67ed937
Merge branch 'master' into billing/ai-credit-usage
maishivamhoo123 30c0797
Added GetUserAICreditUsage and added test for this
maishivamhoo123 2136437
refactor: merge duplicate enterprise billing structs
maishivamhoo123 2aa7ca2
Merge branch 'master' into refactor/enterprise-billing-merge-structs
maishivamhoo123 dc88042
Added all the Recommended changes
maishivamhoo123 e942927
Added all the recommended chnages
maishivamhoo123 90f9f9e
Merge branch 'master' into refactor/enterprise-billing-merge-structs
maishivamhoo123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| // Copyright 2026 The go-github AUTHORS. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // EnterpriseUsageReportOptions specifies optional parameters for the EnterpriseService.GetUsageReport method. | ||
| 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 EnterpriseService.GetPremiumRequestUsageReport and EnterpriseService.GetAICreditUsage methods. | ||
| type EnterprisePremiumRequestUsageReportOptions struct { | ||
| EnterpriseUsageReportOptions | ||
| Organization string `url:"organization,omitempty"` | ||
| User string `url:"user,omitempty"` | ||
| Model string `url:"model,omitempty"` | ||
| Product string `url:"product,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseUsageSummaryOptions specifies optional parameters for the EnterpriseService.GetUsageSummary method. | ||
| type EnterpriseUsageSummaryOptions struct { | ||
| EnterpriseUsageReportOptions | ||
| Organization string `url:"organization,omitempty"` | ||
| Repository string `url:"repository,omitempty"` | ||
| Product string `url:"product,omitempty"` | ||
| SKU string `url:"sku,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseUsageTimePeriod represents a time period used in aggregated enterprise billing reports. | ||
| type EnterpriseUsageTimePeriod struct { | ||
| Year int `json:"year"` | ||
| Month *int `json:"month,omitempty"` | ||
| Day *int `json:"day,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseAggregatedUsageItem represents a single usage line item in an enterprise billing premium request or AI credit report. | ||
| type EnterpriseAggregatedUsageItem struct { | ||
| Product string `json:"product"` | ||
| SKU string `json:"sku"` | ||
| Model *string `json:"model,omitempty"` | ||
| UnitType string `json:"unitType"` | ||
| PricePerUnit float64 `json:"pricePerUnit"` | ||
| GrossQuantity float64 `json:"grossQuantity"` | ||
| GrossAmount float64 `json:"grossAmount"` | ||
| DiscountQuantity float64 `json:"discountQuantity"` | ||
| DiscountAmount float64 `json:"discountAmount"` | ||
| NetQuantity float64 `json:"netQuantity"` | ||
| NetAmount float64 `json:"netAmount"` | ||
| } | ||
|
|
||
| // EnterpriseAggregatedUsageReport represents the aggregated billing usage report response for the premium request and AI credit endpoints. | ||
| type EnterpriseAggregatedUsageReport struct { | ||
| TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` | ||
| Enterprise string `json:"enterprise"` | ||
| Organization *string `json:"organization,omitempty"` | ||
| User *string `json:"user,omitempty"` | ||
| Product *string `json:"product,omitempty"` | ||
| Model *string `json:"model,omitempty"` | ||
| CostCenter *BillingCostCenter `json:"costCenter,omitempty"` | ||
| UsageItems []*EnterpriseAggregatedUsageItem `json:"usageItems"` | ||
| } | ||
|
|
||
| // EnterpriseUsageSummaryItem represents a single usage line item in an enterprise billing usage summary report. | ||
| type EnterpriseUsageSummaryItem struct { | ||
| Product string `json:"product"` | ||
| SKU string `json:"sku"` | ||
| UnitType string `json:"unitType"` | ||
| PricePerUnit float64 `json:"pricePerUnit"` | ||
| GrossQuantity float64 `json:"grossQuantity"` | ||
| GrossAmount float64 `json:"grossAmount"` | ||
| DiscountQuantity float64 `json:"discountQuantity"` | ||
| DiscountAmount float64 `json:"discountAmount"` | ||
| NetQuantity float64 `json:"netQuantity"` | ||
| NetAmount float64 `json:"netAmount"` | ||
| } | ||
|
|
||
| // EnterpriseUsageSummaryReport represents the billing usage summary report response for the EnterpriseService.GetUsageSummary endpoint. | ||
| type EnterpriseUsageSummaryReport struct { | ||
| TimePeriod EnterpriseUsageTimePeriod `json:"timePeriod"` | ||
| Enterprise string `json:"enterprise"` | ||
| Organization *string `json:"organization,omitempty"` | ||
| Repository *string `json:"repository,omitempty"` | ||
| Product *string `json:"product,omitempty"` | ||
| SKU *string `json:"sku,omitempty"` | ||
| CostCenter *BillingCostCenter `json:"costCenter,omitempty"` | ||
| UsageItems []*EnterpriseUsageSummaryItem `json:"usageItems"` | ||
| } | ||
|
|
||
| // BillingCostCenter represents a cost center reference embedded in enterprise billing usage reports. | ||
| type BillingCostCenter struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| // EnterpriseUsageItem represents a single usage line item in an enterprise billing platform report. | ||
| type EnterpriseUsageItem 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"` | ||
| OrganizationName string `json:"organizationName"` | ||
| RepositoryName *string `json:"repositoryName,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseUsageReport represents the enterprise billing usage report response. | ||
| type EnterpriseUsageReport struct { | ||
| UsageItems []*EnterpriseUsageItem `json:"usageItems,omitempty"` | ||
| } | ||
|
|
||
| // GetUsageReport returns a report of the total usage for an enterprise using the enhanced billing platform. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-usage-report-for-an-enterprise | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/settings/billing/usage | ||
| func (s *EnterpriseService) GetUsageReport(ctx context.Context, enterprise string, opts *EnterpriseUsageReportOptions) (*EnterpriseUsageReport, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/usage", enterprise) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var report *EnterpriseUsageReport | ||
| resp, err := s.client.Do(req, &report) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return report, resp, nil | ||
| } | ||
|
|
||
| // GetUsageSummary returns a summary report of usage for an enterprise. | ||
| // | ||
| // 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) (*EnterpriseUsageSummaryReport, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/usage/summary", enterprise) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var report *EnterpriseUsageSummaryReport | ||
| resp, err := s.client.Do(req, &report) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return report, resp, nil | ||
| } | ||
|
|
||
| // GetPremiumRequestUsageReport returns a report of the premium request usage for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-premium-request-usage-report-for-an-enterprise | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/settings/billing/premium_request/usage | ||
| func (s *EnterpriseService) GetPremiumRequestUsageReport(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/premium_request/usage", enterprise) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var report *EnterpriseAggregatedUsageReport | ||
| resp, err := s.client.Do(req, &report) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return report, resp, nil | ||
| } | ||
|
|
||
| // GetAICreditUsage returns a report of the AI credit usage for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/usage?apiVersion=2022-11-28#get-billing-ai-credit-usage-report-for-an-enterprise | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/settings/billing/ai_credit/usage | ||
| func (s *EnterpriseService) GetAICreditUsage(ctx context.Context, enterprise string, opts *EnterprisePremiumRequestUsageReportOptions) (*EnterpriseAggregatedUsageReport, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/ai_credit/usage", enterprise) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var report *EnterpriseAggregatedUsageReport | ||
| resp, err := s.client.Do(req, &report) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return report, resp, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.