...

Source file src/github.com/google/go-github/v47/github/billing.go

Documentation: github.com/google/go-github/v47/github

     1  // Copyright 2021 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  )
    12  
    13  // BillingService provides access to the billing related functions
    14  // in the GitHub API.
    15  //
    16  // GitHub API docs: https://docs.github.com/en/rest/billing
    17  type BillingService service
    18  
    19  // ActionBilling represents a GitHub Action billing.
    20  type ActionBilling struct {
    21  	TotalMinutesUsed     int                  `json:"total_minutes_used"`
    22  	TotalPaidMinutesUsed float64              `json:"total_paid_minutes_used"`
    23  	IncludedMinutes      int                  `json:"included_minutes"`
    24  	MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
    25  }
    26  
    27  type MinutesUsedBreakdown struct {
    28  	Ubuntu  int `json:"UBUNTU"`
    29  	MacOS   int `json:"MACOS"`
    30  	Windows int `json:"WINDOWS"`
    31  }
    32  
    33  // PackageBilling represents a GitHub Package billing.
    34  type PackageBilling struct {
    35  	TotalGigabytesBandwidthUsed     int `json:"total_gigabytes_bandwidth_used"`
    36  	TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
    37  	IncludedGigabytesBandwidth      int `json:"included_gigabytes_bandwidth"`
    38  }
    39  
    40  // StorageBilling represents a GitHub Storage billing.
    41  type StorageBilling struct {
    42  	DaysLeftInBillingCycle       int     `json:"days_left_in_billing_cycle"`
    43  	EstimatedPaidStorageForMonth float64 `json:"estimated_paid_storage_for_month"`
    44  	EstimatedStorageForMonth     int     `json:"estimated_storage_for_month"`
    45  }
    46  
    47  // ActiveCommitters represents the total active committers across all repositories in an Organization.
    48  type ActiveCommitters struct {
    49  	TotalAdvancedSecurityCommitters int                           `json:"total_advanced_security_committers"`
    50  	Repositories                    []*RepositoryActiveCommitters `json:"repositories,omitempty"`
    51  }
    52  
    53  // RepositoryActiveCommitters represents active committers on each repository.
    54  type RepositoryActiveCommitters struct {
    55  	Name                                *string                                `json:"name,omitempty"`
    56  	AdvancedSecurityCommitters          *int                                   `json:"advanced_security_committers,omitempty"`
    57  	AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"`
    58  }
    59  
    60  // AdvancedSecurityCommittersBreakdown represents the user activity breakdown for ActiveCommitters.
    61  type AdvancedSecurityCommittersBreakdown struct {
    62  	UserLogin      *string `json:"user_login,omitempty"`
    63  	LastPushedDate *string `json:"last_pushed_date,omitempty"`
    64  }
    65  
    66  // GetActionsBillingOrg returns the summary of the free and paid GitHub Actions minutes used for an Org.
    67  //
    68  // GitHub API docs: https://docs.github.com/en/rest/billing#get-github-actions-billing-for-an-organization
    69  func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (*ActionBilling, *Response, error) {
    70  	u := fmt.Sprintf("orgs/%v/settings/billing/actions", org)
    71  	req, err := s.client.NewRequest("GET", u, nil)
    72  	if err != nil {
    73  		return nil, nil, err
    74  	}
    75  
    76  	actionsOrgBilling := new(ActionBilling)
    77  	resp, err := s.client.Do(ctx, req, actionsOrgBilling)
    78  	if err != nil {
    79  		return nil, resp, err
    80  	}
    81  
    82  	return actionsOrgBilling, resp, nil
    83  }
    84  
    85  // GetPackagesBillingOrg returns the free and paid storage used for GitHub Packages in gigabytes for an Org.
    86  //
    87  // GitHub API docs: https://docs.github.com/en/rest/billing#get-github-packages-billing-for-an-organization
    88  func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string) (*PackageBilling, *Response, error) {
    89  	u := fmt.Sprintf("orgs/%v/settings/billing/packages", org)
    90  	req, err := s.client.NewRequest("GET", u, nil)
    91  	if err != nil {
    92  		return nil, nil, err
    93  	}
    94  
    95  	packagesOrgBilling := new(PackageBilling)
    96  	resp, err := s.client.Do(ctx, req, packagesOrgBilling)
    97  	if err != nil {
    98  		return nil, resp, err
    99  	}
   100  
   101  	return packagesOrgBilling, resp, nil
   102  }
   103  
   104  // GetStorageBillingOrg returns the estimated paid and estimated total storage used for GitHub Actions
   105  // and GitHub Packages in gigabytes for an Org.
   106  //
   107  // GitHub API docs: https://docs.github.com/en/rest/billing#get-shared-storage-billing-for-an-organization
   108  func (s *BillingService) GetStorageBillingOrg(ctx context.Context, org string) (*StorageBilling, *Response, error) {
   109  	u := fmt.Sprintf("orgs/%v/settings/billing/shared-storage", org)
   110  	req, err := s.client.NewRequest("GET", u, nil)
   111  	if err != nil {
   112  		return nil, nil, err
   113  	}
   114  
   115  	storageOrgBilling := new(StorageBilling)
   116  	resp, err := s.client.Do(ctx, req, storageOrgBilling)
   117  	if err != nil {
   118  		return nil, resp, err
   119  	}
   120  
   121  	return storageOrgBilling, resp, nil
   122  }
   123  
   124  // GetAdvancedSecurityActiveCommittersOrg returns the GitHub Advanced Security active committers for an organization per repository.
   125  //
   126  // GitHub API docs: https://docs.github.com/en/rest/billing#get-github-advanced-security-active-committers-for-an-organization
   127  func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Context, org string) (*ActiveCommitters, *Response, error) {
   128  	u := fmt.Sprintf("orgs/%v/settings/billing/advanced-security", org)
   129  	req, err := s.client.NewRequest("GET", u, nil)
   130  	if err != nil {
   131  		return nil, nil, err
   132  	}
   133  
   134  	activeOrgCommitters := new(ActiveCommitters)
   135  	resp, err := s.client.Do(ctx, req, activeOrgCommitters)
   136  	if err != nil {
   137  		return nil, resp, err
   138  	}
   139  
   140  	return activeOrgCommitters, resp, nil
   141  }
   142  
   143  // GetActionsBillingUser returns the summary of the free and paid GitHub Actions minutes used for a user.
   144  //
   145  // GitHub API docs: https://docs.github.com/en/rest/billing#get-github-actions-billing-for-a-user
   146  func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string) (*ActionBilling, *Response, error) {
   147  	u := fmt.Sprintf("users/%v/settings/billing/actions", user)
   148  	req, err := s.client.NewRequest("GET", u, nil)
   149  	if err != nil {
   150  		return nil, nil, err
   151  	}
   152  
   153  	actionsUserBilling := new(ActionBilling)
   154  	resp, err := s.client.Do(ctx, req, actionsUserBilling)
   155  	if err != nil {
   156  		return nil, resp, err
   157  	}
   158  
   159  	return actionsUserBilling, resp, nil
   160  }
   161  
   162  // GetPackagesBillingUser returns the free and paid storage used for GitHub Packages in gigabytes for a user.
   163  //
   164  // GitHub API docs: https://docs.github.com/en/rest/billing#get-github-packages-billing-for-a-user
   165  func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string) (*PackageBilling, *Response, error) {
   166  	u := fmt.Sprintf("users/%v/settings/billing/packages", user)
   167  	req, err := s.client.NewRequest("GET", u, nil)
   168  	if err != nil {
   169  		return nil, nil, err
   170  	}
   171  
   172  	packagesUserBilling := new(PackageBilling)
   173  	resp, err := s.client.Do(ctx, req, packagesUserBilling)
   174  	if err != nil {
   175  		return nil, resp, err
   176  	}
   177  
   178  	return packagesUserBilling, resp, nil
   179  }
   180  
   181  // GetStorageBillingUser returns the estimated paid and estimated total storage used for GitHub Actions
   182  // and GitHub Packages in gigabytes for a user.
   183  //
   184  // GitHub API docs: https://docs.github.com/en/rest/billing#get-shared-storage-billing-for-a-user
   185  func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string) (*StorageBilling, *Response, error) {
   186  	u := fmt.Sprintf("users/%v/settings/billing/shared-storage", user)
   187  	req, err := s.client.NewRequest("GET", u, nil)
   188  	if err != nil {
   189  		return nil, nil, err
   190  	}
   191  
   192  	storageUserBilling := new(StorageBilling)
   193  	resp, err := s.client.Do(ctx, req, storageUserBilling)
   194  	if err != nil {
   195  		return nil, resp, err
   196  	}
   197  
   198  	return storageUserBilling, resp, nil
   199  }
   200  

View as plain text