-
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
Merged
gmlewis
merged 7 commits into
google:master
from
maishivamhoo123:feat/enterprise-budget-api
Mar 10, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8afd175
feat: add enterprise budget API
maishivamhoo123 a7d3806
In AddBudget I passed the Budget by value
maishivamhoo123 03ae51c
Passing the Budget as value in UpdateBudget
maishivamhoo123 e9b7ca3
created new struct for EnterpriseCreateBudget and EnterpriseUpdateBudget
maishivamhoo123 b49e045
added enum in place of string
maishivamhoo123 d85eca8
Merge branch 'master' into feat/enterprise-budget-api
maishivamhoo123 9d90b6d
Merge branch 'master' into feat/enterprise-budget-api
maishivamhoo123 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,198 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| // BudgetScope constants represent the scope of the budget. | ||
| const ( | ||
| BudgetScopeEnterprise = "enterprise" | ||
| BudgetScopeOrganization = "organization" | ||
| BudgetScopeRepository = "repository" | ||
| BudgetScopeCostCenter = "cost_center" | ||
| ) | ||
|
|
||
| // BudgetType constants represent the type of pricing for the budget. | ||
| const ( | ||
| BudgetTypeProductPricing = "ProductPricing" | ||
| BudgetTypeSkuPricing = "SkuPricing" | ||
| ) | ||
|
|
||
| // 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"` | ||
maishivamhoo123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BudgetProductSKU *string `json:"budget_product_sku,omitempty"` | ||
| BudgetScope *string `json:"budget_scope,omitempty"` | ||
maishivamhoo123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
| } | ||
|
|
||
| // EnterpriseListBudgets represents a collection of GitHub enterprise budgets. | ||
| type EnterpriseListBudgets struct { | ||
| Budgets []*EnterpriseBudget `json:"budgets"` | ||
| HasNextPage *bool `json:"has_next_page,omitempty"` | ||
| TotalCount *int `json:"total_count,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseCreateBudget represents the payload to create a GitHub enterprise budget. | ||
| type EnterpriseCreateBudget struct { | ||
| BudgetAmount int `json:"budget_amount"` | ||
| PreventFurtherUsage bool `json:"prevent_further_usage"` | ||
| BudgetAlerting *EnterpriseBudgetAlerting `json:"budget_alerting"` | ||
| BudgetScope string `json:"budget_scope"` | ||
| BudgetEntityName *string `json:"budget_entity_name,omitempty"` | ||
| BudgetType string `json:"budget_type"` | ||
| BudgetProductSKU *string `json:"budget_product_sku,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseUpdateBudget represents the payload to update a GitHub enterprise budget. | ||
| type EnterpriseUpdateBudget struct { | ||
| BudgetAmount *int `json:"budget_amount,omitempty"` | ||
| PreventFurtherUsage *bool `json:"prevent_further_usage,omitempty"` | ||
| BudgetAlerting *EnterpriseBudgetAlerting `json:"budget_alerting,omitempty"` | ||
| BudgetScope *string `json:"budget_scope,omitempty"` | ||
| BudgetEntityName *string `json:"budget_entity_name,omitempty"` | ||
| BudgetType *string `json:"budget_type,omitempty"` | ||
| BudgetProductSKU *string `json:"budget_product_sku,omitempty"` | ||
| } | ||
|
|
||
| // EnterpriseCreateOrUpdateBudgetResponse represents the response when creating or updating a budget. | ||
| type EnterpriseCreateOrUpdateBudgetResponse struct { | ||
| Message string `json:"message"` | ||
| Budget *EnterpriseBudget `json:"budget"` | ||
| } | ||
|
|
||
| // EnterpriseDeleteBudgetResponse represents the response when deleting a budget. | ||
| type EnterpriseDeleteBudgetResponse struct { | ||
| Message string `json:"message"` | ||
| ID string `json:"id"` | ||
| } | ||
|
|
||
| // 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) (*EnterpriseListBudgets, *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 *EnterpriseListBudgets | ||
| 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 EnterpriseCreateBudget) (*EnterpriseCreateOrUpdateBudgetResponse, *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 createBudgetResponse *EnterpriseCreateOrUpdateBudgetResponse | ||
| resp, err := s.client.Do(ctx, req, &createBudgetResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return createBudgetResponse, 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 EnterpriseUpdateBudget) (*EnterpriseCreateOrUpdateBudgetResponse, *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 updateBudgetResponse *EnterpriseCreateOrUpdateBudgetResponse | ||
| resp, err := s.client.Do(ctx, req, &updateBudgetResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return updateBudgetResponse, 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) (*EnterpriseDeleteBudgetResponse, *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 deleteBudgetResponse *EnterpriseDeleteBudgetResponse | ||
| resp, err := s.client.Do(ctx, req, &deleteBudgetResponse) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return deleteBudgetResponse, resp, nil | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.