-
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 1 commit
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
Some comments aren't visible on the classic Files Changed page.
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" | ||
| ) | ||
|
|
||
| // BudgetAlerting represents alerting settings for a GitHub enterprise budget. | ||
| type BudgetAlerting struct { | ||
| WillAlert *bool `json:"will_alert,omitempty"` | ||
| AlertRecipients []string `json:"alert_recipients,omitempty"` | ||
| } | ||
|
|
||
| // Budget represents a GitHub enterprise budget. | ||
| type Budget struct { | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| 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 *BudgetAlerting `json:"budget_alerting,omitempty"` | ||
| } | ||
|
|
||
| func (b Budget) String() string { | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| return Stringify(b) | ||
| } | ||
|
|
||
| // EnterpriseBudgets represents a collection of GitHub enterprise budgets. | ||
| type EnterpriseBudgets struct { | ||
| Budgets []*Budget `json:"budgets,omitempty"` | ||
| } | ||
|
|
||
| // BudgetActionResponse represents the response when creating, updating, or deleting a budget. | ||
| type BudgetActionResponse struct { | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| Message *string `json:"message,omitempty"` | ||
| BudgetID *string `json:"budget_id,omitempty"` | ||
| Budget *Budget `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) { | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| budgets := new(EnterpriseBudgets) | ||
| resp, err := s.client.Do(ctx, req, budgets) | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| 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 *Budget) (*BudgetActionResponse, *Response, error) { | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| u := fmt.Sprintf("enterprises/%v/settings/billing/budgets", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest("POST", u, budget) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| actionResponse := new(BudgetActionResponse) | ||
| resp, err := s.client.Do(ctx, req, actionResponse) | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| 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) (*Budget, *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 | ||
| } | ||
|
|
||
| budget := new(Budget) | ||
| resp, err := s.client.Do(ctx, req, budget) | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| 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 *Budget) (*BudgetActionResponse, *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 | ||
| } | ||
|
|
||
| actionResponse := new(BudgetActionResponse) | ||
| resp, err := s.client.Do(ctx, req, actionResponse) | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| 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) (*BudgetActionResponse, *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 | ||
| } | ||
|
|
||
| actionResponse := new(BudgetActionResponse) | ||
| resp, err := s.client.Do(ctx, req, actionResponse) | ||
|
maishivamhoo123 marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return actionResponse, 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.