-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add enterprise budgets API #4069
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
2
commits into
google:master
Choose a base branch
from
maishivamhoo123:feat/enterprise-budget-api
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.
+814
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,156 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // EnterpriseBudgetAlerting represents alerting settings for a GitHub enterprise budget. | ||
| type EnterpriseBudgetAlerting struct { | ||
| WillAlert *bool `json:"will_alert,omitempty"` | ||
| AlertRecipients []string `json:"alert_recipients,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseBudget represents a GitHub enterprise budget. | ||
| type EnterpriseBudget struct { | ||
| ID *string `json:"id,omitempty"` | ||
| BudgetType *string `json:"budget_type,omitempty"` | ||
| BudgetProductSkus []string `json:"budget_product_skus,omitempty"` | ||
| BudgetProductSKU *string `json:"budget_product_sku,omitempty"` | ||
| BudgetScope *string `json:"budget_scope,omitempty"` | ||
| BudgetEntityName *string `json:"budget_entity_name,omitempty"` | ||
| BudgetAmount *int `json:"budget_amount,omitempty"` | ||
| PreventFurtherUsage *bool `json:"prevent_further_usage,omitempty"` | ||
| BudgetAlerting *EnterpriseBudgetAlerting `json:"budget_alerting,omitempty"` | ||
| } | ||
|
|
||
| func (b EnterpriseBudget) String() string { | ||
| return Stringify(b) | ||
| } | ||
|
|
||
| // EnterpriseBudgets represents a collection of GitHub enterprise budgets. | ||
| type EnterpriseBudgets struct { | ||
| Budgets []*EnterpriseBudget `json:"budgets,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseBudgetActionResponse represents the response when creating, updating, or deleting a budget. | ||
| type EnterpriseBudgetActionResponse struct { | ||
| Message *string `json:"message,omitempty"` | ||
| BudgetID *string `json:"budget_id,omitempty"` | ||
| Budget *EnterpriseBudget `json:"budget,omitempty"` | ||
| } | ||
|
|
||
| // ListBudgets gets all budgets for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/budgets#get-all-budgets | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/settings/billing/budgets | ||
| func (s *EnterpriseService) ListBudgets(ctx context.Context, enterprise string) (*EnterpriseBudgets, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var budgets *EnterpriseBudgets | ||
| resp, err := s.client.Do(ctx, req, &budgets) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return budgets, resp, nil | ||
| } | ||
|
|
||
| // CreateBudget creates a new budget for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/budgets#create-a-budget | ||
| // | ||
| //meta:operation POST /enterprises/{enterprise}/settings/billing/budgets | ||
| func (s *EnterpriseService) CreateBudget(ctx context.Context, enterprise string, budget EnterpriseBudget) (*EnterpriseBudgetActionResponse, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest("POST", u, budget) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var actionResponse *EnterpriseBudgetActionResponse | ||
| resp, err := s.client.Do(ctx, req, &actionResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return actionResponse, resp, nil | ||
| } | ||
|
|
||
| // GetBudget gets a budget by ID for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/budgets#get-a-budget-by-id | ||
| // | ||
| //meta:operation GET /enterprises/{enterprise}/settings/billing/budgets/{budget_id} | ||
| func (s *EnterpriseService) GetBudget(ctx context.Context, enterprise, budgetID string) (*EnterpriseBudget, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v", enterprise, budgetID) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var budget *EnterpriseBudget | ||
| resp, err := s.client.Do(ctx, req, &budget) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return budget, resp, nil | ||
| } | ||
|
|
||
| // UpdateBudget updates an existing budget for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/budgets#update-a-budget | ||
| // | ||
| //meta:operation PATCH /enterprises/{enterprise}/settings/billing/budgets/{budget_id} | ||
| func (s *EnterpriseService) UpdateBudget(ctx context.Context, enterprise, budgetID string, budget *EnterpriseBudget) (*EnterpriseBudgetActionResponse, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v", enterprise, budgetID) | ||
|
|
||
| req, err := s.client.NewRequest("PATCH", u, budget) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var actionResponse *EnterpriseBudgetActionResponse | ||
| resp, err := s.client.Do(ctx, req, &actionResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return actionResponse, resp, nil | ||
| } | ||
|
|
||
| // DeleteBudget deletes a budget by ID for an enterprise. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/budgets#delete-a-budget | ||
| // | ||
| //meta:operation DELETE /enterprises/{enterprise}/settings/billing/budgets/{budget_id} | ||
| func (s *EnterpriseService) DeleteBudget(ctx context.Context, enterprise, budgetID string) (*EnterpriseBudgetActionResponse, *Response, error) { | ||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v", enterprise, budgetID) | ||
|
|
||
| req, err := s.client.NewRequest("DELETE", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| var actionResponse *EnterpriseBudgetActionResponse | ||
| resp, err := s.client.Do(ctx, req, &actionResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return actionResponse, resp, nil | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as for
CreateBudget: