-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathbilling_budgets.go
More file actions
126 lines (109 loc) · 4.55 KB
/
billing_budgets.go
File metadata and controls
126 lines (109 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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"
)
// Budget represents a GitHub budget.
type Budget struct {
ID *string `json:"id,omitempty"`
BudgetName *string `json:"budget_name,omitempty"`
TargetSubAccount *string `json:"target_sub_account,omitempty"`
TargetType *string `json:"target_type,omitempty"`
TargetID *int64 `json:"target_id,omitempty"`
TargetName *string `json:"target_name,omitempty"`
PricingModel *string `json:"pricing_model,omitempty"`
PricingModelID *string `json:"pricing_model_id,omitempty"`
PricingModelDisplayName *string `json:"pricing_model_display_name,omitempty"`
BudgetType *string `json:"budget_type,omitempty"`
LimitAmount *float64 `json:"limit_amount,omitempty"`
CurrentAmount *float64 `json:"current_amount,omitempty"`
Currency *string `json:"currency,omitempty"`
ExcludeCostCenterUsage *bool `json:"exclude_cost_center_usage,omitempty"`
BudgetAlerting *BudgetAlerting `json:"budget_alerting,omitempty"`
}
// BudgetAlerting represents the alerting configuration for a budget.
type BudgetAlerting struct {
WillAlert *bool `json:"will_alert,omitempty"`
AlertRecipients []string `json:"alert_recipients,omitempty"`
}
// BudgetList represents a list of budgets.
type BudgetList struct {
Budgets []*Budget `json:"budgets"`
HasNextPage *bool `json:"has_next_page,omitempty"`
}
// BudgetResponse represents the response when updating a budget.
type BudgetResponse struct {
Budget *Budget `json:"budget"`
Message *string `json:"message,omitempty"`
}
// ListOrganizationBudgets lists all budgets for an organization.
//
// GitHub API docs: https://docs.github.com/rest/billing/budgets#get-all-budgets-for-an-organization
//
//meta:operation GET /organizations/{org}/settings/billing/budgets
func (s *BillingService) ListOrganizationBudgets(ctx context.Context, org string) (*BudgetList, *Response, error) {
u := fmt.Sprintf("organizations/%v/settings/billing/budgets", org)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
budgets := new(BudgetList)
resp, err := s.client.Do(ctx, req, budgets)
if err != nil {
return nil, resp, err
}
return budgets, resp, nil
}
// GetOrganizationBudget gets a specific budget for an organization.
//
// GitHub API docs: https://docs.github.com/rest/billing/budgets#get-a-budget-by-id-for-an-organization
//
//meta:operation GET /organizations/{org}/settings/billing/budgets/{budget_id}
func (s *BillingService) GetOrganizationBudget(ctx context.Context, org, budgetID string) (*Budget, *Response, error) {
u := fmt.Sprintf("organizations/%v/settings/billing/budgets/%v", org, budgetID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
budget := new(Budget)
resp, err := s.client.Do(ctx, req, budget)
if err != nil {
return nil, resp, err
}
return budget, resp, nil
}
// UpdateOrganizationBudget updates a specific budget for an organization.
//
// GitHub API docs: https://docs.github.com/rest/billing/budgets#update-a-budget-for-an-organization
//
//meta:operation PATCH /organizations/{org}/settings/billing/budgets/{budget_id}
func (s *BillingService) UpdateOrganizationBudget(ctx context.Context, org, budgetID string, budget *Budget) (*BudgetResponse, *Response, error) {
u := fmt.Sprintf("organizations/%v/settings/billing/budgets/%v", org, budgetID)
req, err := s.client.NewRequest("PATCH", u, budget)
if err != nil {
return nil, nil, err
}
updatedBudget := new(BudgetResponse)
resp, err := s.client.Do(ctx, req, updatedBudget)
if err != nil {
return nil, resp, err
}
return updatedBudget, resp, nil
}
// DeleteOrganizationBudget deletes a specific budget for an organization.
//
// GitHub API docs: https://docs.github.com/rest/billing/budgets#delete-a-budget-for-an-organization
//
//meta:operation DELETE /organizations/{org}/settings/billing/budgets/{budget_id}
func (s *BillingService) DeleteOrganizationBudget(ctx context.Context, org, budgetID string) (*Response, error) {
u := fmt.Sprintf("organizations/%v/settings/billing/budgets/%v", org, budgetID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}