Skip to content

feat!: Add pagination to Enterprise.ListBudgets and add GetUserStatesForBudget (#4408) - #4501

Open
devaniketh wants to merge 4 commits into
google:masterfrom
devaniketh:enterprise-budgets-pagination
Open

feat!: Add pagination to Enterprise.ListBudgets and add GetUserStatesForBudget (#4408)#4501
devaniketh wants to merge 4 commits into
google:masterfrom
devaniketh:enterprise-budgets-pagination

Conversation

@devaniketh

Copy link
Copy Markdown

Fixes #4408

Summary

  • Added EnterpriseListBudgetsOptions embedding ListOptions to enable pagination (page, per_page) in EnterpriseService.ListBudgets.
  • Added EnterpriseService.GetUserStatesForBudget along with EnterpriseBudgetUserState, EnterpriseBudgetUserStates, and EnterpriseGetUserStatesOptions for endpoint GET /enterprises/{enterprise}/settings/billing/budgets/{budget_id}/user-states.
  • Regenerated accessors, iterators (ListBudgetsIter), and stringifier test fixtures via script/generate.sh.
  • Added full unit test coverage in enterprise_budgets_test.go.

@google-cla

google-cla Bot commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Sep 1, 2026
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.52%. Comparing base (6d624b5) to head (c0102b1).

Files with missing lines Patch % Lines
github/enterprise_budgets.go 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4501      +/-   ##
==========================================
- Coverage   98.53%   98.52%   -0.01%     
==========================================
  Files         195      195              
  Lines       17763    17798      +35     
==========================================
+ Hits        17502    17535      +33     
- Misses        261      263       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis changed the title feat: Add pagination to Enterprise.ListBudgets and add GetUserStatesForBudget (#4408) feat!: Add pagination to Enterprise.ListBudgets and add GetUserStatesForBudget (#4408) Sep 2, 2026
@gmlewis gmlewis added the Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). label Sep 2, 2026
Comment thread github/enterprise_budgets.go Outdated
@devaniketh
devaniketh requested a review from gmlewis September 2, 2026 12:14
//
//meta:operation GET /enterprises/{enterprise}/settings/billing/budgets
func (s *EnterpriseService) ListBudgets(ctx context.Context, enterprise string) (*EnterpriseListBudgets, *Response, error) {
func (s *EnterpriseService) ListBudgets(ctx context.Context, enterprise string, opts *ListOptions) (*EnterpriseListBudgets, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint has a few other query parameters as well.
Let’s create a new ListBudgetsOptions struct for it

type ListBudgetsOptions struct {
	Scope string `url:"scope,omitempty"`
	User  string `url:"user,omitempty"`
	ListOptions
}
Image

Comment on lines +157 to +159
u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v/user-states", enterprise, budgetID)

u, err := addOptions(u, opts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v/user-states", enterprise, budgetID)
u, err := addOptions(u, opts)
u := fmt.Sprintf("enterprises/%v/settings/billing/budgets/%v/user-states", enterprise, budgetID)
u, err := addOptions(u, opts)

Comment on lines +69 to +73
type EnterpriseBudgetUserStates struct {
UserStates []*EnterpriseBudgetUserState `json:"user_states"`
HasNextPage *bool `json:"has_next_page,omitempty"`
TotalCount *int `json:"total_count,omitempty"`
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_next_page and total_count are required field and we don't use ,omitempty with them.

  "required": [
    "user_states",
    "has_next_page",
    "total_count"
  ]
Suggested change
type EnterpriseBudgetUserStates struct {
UserStates []*EnterpriseBudgetUserState `json:"user_states"`
HasNextPage *bool `json:"has_next_page,omitempty"`
TotalCount *int `json:"total_count,omitempty"`
}
type EnterpriseBudgetUserStates struct {
UserStates []*EnterpriseBudgetUserState `json:"user_states"`
HasNextPage bool `json:"has_next_page"`
TotalCount int `json:"total_count"`
}

Comment on lines +57 to +62
type EnterpriseBudgetUserState struct {
User *string `json:"user,omitempty"`
ConsumedAmount *float64 `json:"consumed_amount,omitempty"`
TargetAmount *float64 `json:"target_amount,omitempty"`
OverrideBudgetID *string `json:"override_budget_id,omitempty"`
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consumed_amount and target_amount are required.

        "required": [
          "consumed_amount",
          "target_amount"
        ]
Suggested change
type EnterpriseBudgetUserState struct {
User *string `json:"user,omitempty"`
ConsumedAmount *float64 `json:"consumed_amount,omitempty"`
TargetAmount *float64 `json:"target_amount,omitempty"`
OverrideBudgetID *string `json:"override_budget_id,omitempty"`
}
type EnterpriseBudgetUserState struct {
User *string `json:"user,omitempty"`
ConsumedAmount float64 `json:"consumed_amount"`
TargetAmount float64 `json:"target_amount"`
OverrideBudgetID *string `json:"override_budget_id,omitempty"`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add additional functionality for enterprise budgets

3 participants