Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 74 additions & 58 deletions github/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,54 @@ type BillingService service
// MinutesUsedBreakdown counts the actions minutes used by machine type (e.g. UBUNTU, WINDOWS, MACOS).
type MinutesUsedBreakdown = map[string]int

// PackageBilling represents a GitHub Package billing.
type PackageBilling struct {
TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
IncludedGigabytesBandwidth float64 `json:"included_gigabytes_bandwidth"`
// PackagesBilling represents billing of GitHub Packages .
type PackagesBilling struct {
TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
IncludedGigabytesBandwidth int `json:"included_gigabytes_bandwidth"`
}

// StorageBilling represents a GitHub Storage billing.
type StorageBilling struct {
DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
EstimatedPaidStorageForMonth float64 `json:"estimated_paid_storage_for_month"`
EstimatedStorageForMonth float64 `json:"estimated_storage_for_month"`
DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
EstimatedPaidStorageForMonth int `json:"estimated_paid_storage_for_month"`
EstimatedStorageForMonth int `json:"estimated_storage_for_month"`
}

// ActiveCommittersListOptions specifies optional parameters to the
// BillingService.GetAdvancedSecurityActiveCommittersOrg method.
type ActiveCommittersListOptions struct {
// The security product to get GitHub Advanced Security active committers for. For standalone
// Code Scanning or Secret Protection products, this parameter is required to specify which
// product you want committer information for. For other plans this parameter cannot be used.
//
// Can be one of: "code_security", "secret_protection".
AdvancedSecurityProduct *string `url:"advanced_security_product,omitempty"`

ListOptions
}

// ActiveCommitters represents the total active committers across all repositories in an Organization.
type ActiveCommitters struct {
TotalAdvancedSecurityCommitters int `json:"total_advanced_security_committers"`
TotalCount int `json:"total_count"`
MaximumAdvancedSecurityCommitters int `json:"maximum_advanced_security_committers"`
PurchasedAdvancedSecurityCommitters int `json:"purchased_advanced_security_committers"`
Repositories []*RepositoryActiveCommitters `json:"repositories,omitempty"`
TotalAdvancedSecurityCommitters *int `json:"total_advanced_security_committers,omitempty"`
TotalCount *int `json:"total_count,omitempty"`
MaximumAdvancedSecurityCommitters *int `json:"maximum_advanced_security_committers,omitempty"`
PurchasedAdvancedSecurityCommitters *int `json:"purchased_advanced_security_committers,omitempty"`
Repositories []*RepositoryActiveCommitters `json:"repositories"`
}

// RepositoryActiveCommitters represents active committers on each repository.
type RepositoryActiveCommitters struct {
Name *string `json:"name,omitempty"`
AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"`
AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"`
Name string `json:"name"`
AdvancedSecurityCommitters int `json:"advanced_security_committers"`
AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown"`
}

// 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"`
LastPushedDate string `json:"last_pushed_date"`
LastPushedEmail string `json:"last_pushed_email"`
}

// UsageReportOptions specifies optional parameters for the enhanced billing platform usage report.
Expand Down Expand Up @@ -104,16 +118,16 @@ type PremiumRequestUsageReportOptions 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 int `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"`
}
Expand Down Expand Up @@ -147,63 +161,65 @@ type PremiumRequestUsageTimePeriod struct {

// PremiumRequestUsageReport represents the premium request usage report response.
type PremiumRequestUsageReport struct {
TimePeriod PremiumRequestUsageTimePeriod `json:"timePeriod"`
Organization string `json:"organization"`
User *string `json:"user,omitempty"`
Product *string `json:"product,omitempty"`
Model *string `json:"model,omitempty"`
UsageItems []*PremiumRequestUsageItem `json:"usageItems"`
TimePeriod PremiumRequestUsageTimePeriod `json:"timePeriod"`
// Organization is only set for organization-level reports.
Organization *string `json:"organization,omitempty"`
// User is only set for user-level reports.
User *string `json:"user,omitempty"`
Product *string `json:"product,omitempty"`
Model *string `json:"model,omitempty"`
UsageItems []*PremiumRequestUsageItem `json:"usageItems"`
}

// GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
// GetOrganizationPackagesBilling 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
//
//meta:operation GET /orgs/{org}/settings/billing/packages
func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string) (*PackageBilling, *Response, error) {
func (s *BillingService) GetOrganizationPackagesBilling(ctx context.Context, org string) (*PackagesBilling, *Response, error) {
u := fmt.Sprintf("orgs/%v/settings/billing/packages", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

packagesOrgBilling := new(PackageBilling)
resp, err := s.client.Do(ctx, req, packagesOrgBilling)
result := new(PackagesBilling)
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}

return packagesOrgBilling, resp, nil
return result, resp, nil
}

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

storageOrgBilling := new(StorageBilling)
resp, err := s.client.Do(ctx, req, storageOrgBilling)
result := new(StorageBilling)
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}

return storageOrgBilling, resp, nil
return result, resp, nil
}

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

activeOrgCommitters := new(ActiveCommitters)
resp, err := s.client.Do(ctx, req, activeOrgCommitters)
result := new(ActiveCommitters)
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}

return activeOrgCommitters, resp, nil
return result, resp, nil
}

// GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
// GetPackagesBilling 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
//
//meta:operation GET /users/{username}/settings/billing/packages
func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string) (*PackageBilling, *Response, error) {
func (s *BillingService) GetPackagesBilling(ctx context.Context, user string) (*PackagesBilling, *Response, error) {
u := fmt.Sprintf("users/%v/settings/billing/packages", user)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

packagesUserBilling := new(PackageBilling)
packagesUserBilling := new(PackagesBilling)
resp, err := s.client.Do(ctx, req, packagesUserBilling)
if err != nil {
return nil, resp, err
Expand All @@ -245,13 +261,13 @@ func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string
return packagesUserBilling, resp, nil
}

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

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

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