1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14
15
16
17 type BillingService service
18
19
20 type ActionBilling struct {
21 TotalMinutesUsed float64 `json:"total_minutes_used"`
22 TotalPaidMinutesUsed float64 `json:"total_paid_minutes_used"`
23 IncludedMinutes float64 `json:"included_minutes"`
24 MinutesUsedBreakdown MinutesUsedBreakdown `json:"minutes_used_breakdown"`
25 }
26
27
28 type MinutesUsedBreakdown = map[string]int
29
30
31 type PackageBilling struct {
32 TotalGigabytesBandwidthUsed int `json:"total_gigabytes_bandwidth_used"`
33 TotalPaidGigabytesBandwidthUsed int `json:"total_paid_gigabytes_bandwidth_used"`
34 IncludedGigabytesBandwidth float64 `json:"included_gigabytes_bandwidth"`
35 }
36
37
38 type StorageBilling struct {
39 DaysLeftInBillingCycle int `json:"days_left_in_billing_cycle"`
40 EstimatedPaidStorageForMonth float64 `json:"estimated_paid_storage_for_month"`
41 EstimatedStorageForMonth float64 `json:"estimated_storage_for_month"`
42 }
43
44
45 type ActiveCommitters struct {
46 TotalAdvancedSecurityCommitters int `json:"total_advanced_security_committers"`
47 Repositories []*RepositoryActiveCommitters `json:"repositories,omitempty"`
48 }
49
50
51 type RepositoryActiveCommitters struct {
52 Name *string `json:"name,omitempty"`
53 AdvancedSecurityCommitters *int `json:"advanced_security_committers,omitempty"`
54 AdvancedSecurityCommittersBreakdown []*AdvancedSecurityCommittersBreakdown `json:"advanced_security_committers_breakdown,omitempty"`
55 }
56
57
58 type AdvancedSecurityCommittersBreakdown struct {
59 UserLogin *string `json:"user_login,omitempty"`
60 LastPushedDate *string `json:"last_pushed_date,omitempty"`
61 }
62
63
64
65
66 func (s *BillingService) GetActionsBillingOrg(ctx context.Context, org string) (*ActionBilling, *Response, error) {
67 u := fmt.Sprintf("orgs/%v/settings/billing/actions", org)
68 req, err := s.client.NewRequest("GET", u, nil)
69 if err != nil {
70 return nil, nil, err
71 }
72
73 actionsOrgBilling := new(ActionBilling)
74 resp, err := s.client.Do(ctx, req, actionsOrgBilling)
75 if err != nil {
76 return nil, resp, err
77 }
78
79 return actionsOrgBilling, resp, nil
80 }
81
82
83
84
85 func (s *BillingService) GetPackagesBillingOrg(ctx context.Context, org string) (*PackageBilling, *Response, error) {
86 u := fmt.Sprintf("orgs/%v/settings/billing/packages", org)
87 req, err := s.client.NewRequest("GET", u, nil)
88 if err != nil {
89 return nil, nil, err
90 }
91
92 packagesOrgBilling := new(PackageBilling)
93 resp, err := s.client.Do(ctx, req, packagesOrgBilling)
94 if err != nil {
95 return nil, resp, err
96 }
97
98 return packagesOrgBilling, resp, nil
99 }
100
101
102
103
104
105 func (s *BillingService) GetStorageBillingOrg(ctx context.Context, org string) (*StorageBilling, *Response, error) {
106 u := fmt.Sprintf("orgs/%v/settings/billing/shared-storage", org)
107 req, err := s.client.NewRequest("GET", u, nil)
108 if err != nil {
109 return nil, nil, err
110 }
111
112 storageOrgBilling := new(StorageBilling)
113 resp, err := s.client.Do(ctx, req, storageOrgBilling)
114 if err != nil {
115 return nil, resp, err
116 }
117
118 return storageOrgBilling, resp, nil
119 }
120
121
122
123
124 func (s *BillingService) GetAdvancedSecurityActiveCommittersOrg(ctx context.Context, org string, opts *ListOptions) (*ActiveCommitters, *Response, error) {
125 u := fmt.Sprintf("orgs/%v/settings/billing/advanced-security", org)
126 u, err := addOptions(u, opts)
127 if err != nil {
128 return nil, nil, err
129 }
130
131 req, err := s.client.NewRequest("GET", u, nil)
132 if err != nil {
133 return nil, nil, err
134 }
135
136 activeOrgCommitters := new(ActiveCommitters)
137 resp, err := s.client.Do(ctx, req, activeOrgCommitters)
138 if err != nil {
139 return nil, resp, err
140 }
141
142 return activeOrgCommitters, resp, nil
143 }
144
145
146
147
148 func (s *BillingService) GetActionsBillingUser(ctx context.Context, user string) (*ActionBilling, *Response, error) {
149 u := fmt.Sprintf("users/%v/settings/billing/actions", user)
150 req, err := s.client.NewRequest("GET", u, nil)
151 if err != nil {
152 return nil, nil, err
153 }
154
155 actionsUserBilling := new(ActionBilling)
156 resp, err := s.client.Do(ctx, req, actionsUserBilling)
157 if err != nil {
158 return nil, resp, err
159 }
160
161 return actionsUserBilling, resp, nil
162 }
163
164
165
166
167 func (s *BillingService) GetPackagesBillingUser(ctx context.Context, user string) (*PackageBilling, *Response, error) {
168 u := fmt.Sprintf("users/%v/settings/billing/packages", user)
169 req, err := s.client.NewRequest("GET", u, nil)
170 if err != nil {
171 return nil, nil, err
172 }
173
174 packagesUserBilling := new(PackageBilling)
175 resp, err := s.client.Do(ctx, req, packagesUserBilling)
176 if err != nil {
177 return nil, resp, err
178 }
179
180 return packagesUserBilling, resp, nil
181 }
182
183
184
185
186
187 func (s *BillingService) GetStorageBillingUser(ctx context.Context, user string) (*StorageBilling, *Response, error) {
188 u := fmt.Sprintf("users/%v/settings/billing/shared-storage", user)
189 req, err := s.client.NewRequest("GET", u, nil)
190 if err != nil {
191 return nil, nil, err
192 }
193
194 storageUserBilling := new(StorageBilling)
195 resp, err := s.client.Do(ctx, req, storageUserBilling)
196 if err != nil {
197 return nil, resp, err
198 }
199
200 return storageUserBilling, resp, nil
201 }
202
View as plain text