diff --git a/github/billing_budgets.go b/github/billing_budgets.go new file mode 100644 index 00000000000..bca17d34489 --- /dev/null +++ b/github/billing_budgets.go @@ -0,0 +1,128 @@ +// 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 +//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} +//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) +} diff --git a/github/billing_budgets_test.go b/github/billing_budgets_test.go new file mode 100644 index 00000000000..e29c4970e81 --- /dev/null +++ b/github/billing_budgets_test.go @@ -0,0 +1,166 @@ +// 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 ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBillingService_ListOrganizationBudgets(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/settings/billing/budgets", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "budgets": [ + { + "id": "1", + "budget_name": "Budget 1", + "limit_amount": 100.5, + "budget_alerting": { + "will_alert": true, + "alert_recipients": ["user1"] + } + } + ] + }`) + }) + + ctx := t.Context() + budgets, _, err := client.Billing.ListOrganizationBudgets(ctx, "o") + if err != nil { + t.Errorf("Billing.ListOrganizationBudgets returned error: %v", err) + } + + want := &BudgetList{ + Budgets: []*Budget{ + { + ID: Ptr("1"), + BudgetName: Ptr("Budget 1"), + LimitAmount: Ptr(100.5), + BudgetAlerting: &BudgetAlerting{ + WillAlert: Ptr(true), + AlertRecipients: []string{"user1"}, + }, + }, + }, + } + if !cmp.Equal(budgets, want) { + t.Errorf("Billing.ListOrganizationBudgets returned %+v, want %+v", budgets, want) + } + const methodName = "ListOrganizationBudgets" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.ListOrganizationBudgets(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_GetOrganizationBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "id": "1", + "budget_name": "Budget 1" + }`) + }) + + ctx := t.Context() + budget, _, err := client.Billing.GetOrganizationBudget(ctx, "o", "1") + if err != nil { + t.Errorf("Billing.GetOrganizationBudget returned error: %v", err) + } + + want := &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("Budget 1"), + } + if !cmp.Equal(budget, want) { + t.Errorf("Billing.GetOrganizationBudget returned %+v, want %+v", budget, want) + } + const methodName = "GetOrganizationBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.GetOrganizationBudget(ctx, "o", "1") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_UpdateOrganizationBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + input := &Budget{ + BudgetName: Ptr("Updated Budget"), + } + + mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + testBody(t, r, `{"budget_name":"Updated Budget"}`+"\n") + fmt.Fprint(w, `{ + "budget": { + "id": "1", + "budget_name": "Updated Budget" + } + }`) + }) + + ctx := t.Context() + budget, _, err := client.Billing.UpdateOrganizationBudget(ctx, "o", "1", input) + if err != nil { + t.Errorf("Billing.UpdateOrganizationBudget returned error: %v", err) + } + + want := &BudgetResponse{ + Budget: &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("Updated Budget"), + }, + } + if !cmp.Equal(budget, want) { + t.Errorf("Billing.UpdateOrganizationBudget returned %+v, want %+v", budget, want) + } + const methodName = "UpdateOrganizationBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Billing.UpdateOrganizationBudget(ctx, "o", "1", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestBillingService_DeleteOrganizationBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := t.Context() + _, err := client.Billing.DeleteOrganizationBudget(ctx, "o", "1") + if err != nil { + t.Errorf("Billing.DeleteOrganizationBudget returned error: %v", err) + } + const methodName = "DeleteOrganizationBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Billing.DeleteOrganizationBudget(ctx, "o", "1") + }) +} diff --git a/github/enterprise_billing_budgets.go b/github/enterprise_billing_budgets.go new file mode 100644 index 00000000000..b17a72bd80b --- /dev/null +++ b/github/enterprise_billing_budgets.go @@ -0,0 +1,110 @@ +// 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" +) + +// ListEnterpriseBudgets lists 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) (*BudgetList, *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 + } + + budgets := new(BudgetList) + resp, err := s.client.Do(ctx, req, budgets) + if err != nil { + return nil, resp, err + } + + return budgets, resp, nil +} + +// GetEnterpriseBudget gets a specific budget 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) + if err != nil { + return nil, resp, err + } + + return budget, resp, nil +} + +// CreateEnterpriseBudget creates a specific 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) (*Budget, *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 + } + + createdBudget := new(Budget) + resp, err := s.client.Do(ctx, req, createdBudget) + if err != nil { + return nil, resp, err + } + + return createdBudget, resp, nil +} + +// UpdateEnterpriseBudget updates a specific 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) (*BudgetResponse, *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 + } + + updatedBudget := new(BudgetResponse) + resp, err := s.client.Do(ctx, req, updatedBudget) + if err != nil { + return nil, resp, err + } + + return updatedBudget, resp, nil +} + +// DeleteEnterpriseBudget deletes a specific budget 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) (*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, err + } + + return s.client.Do(ctx, req, nil) +} diff --git a/github/enterprise_billing_budgets_test.go b/github/enterprise_billing_budgets_test.go new file mode 100644 index 00000000000..2f77b68417d --- /dev/null +++ b/github/enterprise_billing_budgets_test.go @@ -0,0 +1,226 @@ +// 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 ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestEnterpriseService_ListBudgets(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/settings/billing/budgets", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "budgets": [ + { + "id": "1", + "budget_name": "Budget 1" + } + ] + }`) + }) + + ctx := t.Context() + budgets, _, err := client.Enterprise.ListBudgets(ctx, "e") + if err != nil { + t.Errorf("Enterprise.ListBudgets returned error: %v", err) + } + + want := &BudgetList{ + Budgets: []*Budget{ + { + ID: Ptr("1"), + BudgetName: Ptr("Budget 1"), + }, + }, + } + if !cmp.Equal(budgets, want) { + t.Errorf("Enterprise.ListBudgets returned %+v, want %+v", budgets, want) + } + const methodName = "ListBudgets" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.ListBudgets(ctx, "e") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_GetBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "id": "1", + "budget_name": "Budget 1" + }`) + }) + + ctx := t.Context() + budget, _, err := client.Enterprise.GetBudget(ctx, "e", "1") + if err != nil { + t.Errorf("Enterprise.GetBudget returned error: %v", err) + } + + want := &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("Budget 1"), + } + if !cmp.Equal(budget, want) { + t.Errorf("Enterprise.GetBudget returned %+v, want %+v", budget, want) + } + const methodName = "GetBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetBudget(ctx, "e", "1") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_CreateBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + input := &Budget{ + BudgetName: Ptr("New Budget"), + LimitAmount: Ptr(500.0), + } + + mux.HandleFunc("/enterprises/e/settings/billing/budgets", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testBody(t, r, `{"budget_name":"New Budget","limit_amount":500}`+"\n") + fmt.Fprint(w, `{ + "id": "1", + "budget_name": "New Budget", + "limit_amount": 500 + }`) + }) + + ctx := t.Context() + budget, _, err := client.Enterprise.CreateBudget(ctx, "e", input) + if err != nil { + t.Errorf("Enterprise.CreateBudget returned error: %v", err) + } + + want := &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("New Budget"), + LimitAmount: Ptr(500.0), + } + if !cmp.Equal(budget, want) { + t.Errorf("Enterprise.CreateBudget returned %+v, want %+v", budget, want) + } + const methodName = "CreateBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.CreateBudget(ctx, "e", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_UpdateBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + input := &Budget{ + BudgetName: Ptr("Updated Budget"), + } + + mux.HandleFunc("/enterprises/e/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + testBody(t, r, `{"budget_name":"Updated Budget"}`+"\n") + fmt.Fprint(w, `{ + "budget": { + "id": "1", + "budget_name": "Updated Budget" + } + }`) + }) + + ctx := t.Context() + budget, _, err := client.Enterprise.UpdateBudget(ctx, "e", "1", input) + if err != nil { + t.Errorf("Enterprise.UpdateBudget returned error: %v", err) + } + + want := &BudgetResponse{ + Budget: &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("Updated Budget"), + }, + } + if !cmp.Equal(budget, want) { + t.Errorf("Enterprise.UpdateBudget returned %+v, want %+v", budget, want) + } + const methodName = "UpdateBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.UpdateBudget(ctx, "e", "1", input) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_DeleteBudget(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/settings/billing/budgets/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := t.Context() + _, err := client.Enterprise.DeleteBudget(ctx, "e", "1") + if err != nil { + t.Errorf("Enterprise.DeleteBudget returned error: %v", err) + } + const methodName = "DeleteBudget" + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.DeleteBudget(ctx, "e", "1") + }) +} + +func TestBudget_Marshal(t *testing.T) { + t.Parallel() + testJSONMarshal(t, &Budget{}, "{}") + + b := &Budget{ + ID: Ptr("1"), + BudgetName: Ptr("Budget"), + LimitAmount: Ptr(100.0), + BudgetAlerting: &BudgetAlerting{ + WillAlert: Ptr(true), + AlertRecipients: []string{"u1"}, + }, + } + + want := `{ + "id": "1", + "budget_name": "Budget", + "limit_amount": 100, + "budget_alerting": { + "will_alert": true, + "alert_recipients": ["u1"] + } + }` + + testJSONMarshal(t, b, want) +} diff --git a/github/github-accessors.go b/github/github-accessors.go index 957e2784249..c34e1e03d96 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2198,6 +2198,134 @@ func (b *BranchProtectionRuleEvent) GetSender() *User { return b.Sender } +// GetBudgetAlerting returns the BudgetAlerting field. +func (b *Budget) GetBudgetAlerting() *BudgetAlerting { + if b == nil { + return nil + } + return b.BudgetAlerting +} + +// GetBudgetName returns the BudgetName field if it's non-nil, zero value otherwise. +func (b *Budget) GetBudgetName() string { + if b == nil || b.BudgetName == nil { + return "" + } + return *b.BudgetName +} + +// GetBudgetType returns the BudgetType field if it's non-nil, zero value otherwise. +func (b *Budget) GetBudgetType() string { + if b == nil || b.BudgetType == nil { + return "" + } + return *b.BudgetType +} + +// GetCurrency returns the Currency field if it's non-nil, zero value otherwise. +func (b *Budget) GetCurrency() string { + if b == nil || b.Currency == nil { + return "" + } + return *b.Currency +} + +// GetCurrentAmount returns the CurrentAmount field. +func (b *Budget) GetCurrentAmount() *float64 { + if b == nil { + return nil + } + return b.CurrentAmount +} + +// GetExcludeCostCenterUsage returns the ExcludeCostCenterUsage field if it's non-nil, zero value otherwise. +func (b *Budget) GetExcludeCostCenterUsage() bool { + if b == nil || b.ExcludeCostCenterUsage == nil { + return false + } + return *b.ExcludeCostCenterUsage +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (b *Budget) GetID() string { + if b == nil || b.ID == nil { + return "" + } + return *b.ID +} + +// GetLimitAmount returns the LimitAmount field. +func (b *Budget) GetLimitAmount() *float64 { + if b == nil { + return nil + } + return b.LimitAmount +} + +// GetPricingModel returns the PricingModel field if it's non-nil, zero value otherwise. +func (b *Budget) GetPricingModel() string { + if b == nil || b.PricingModel == nil { + return "" + } + return *b.PricingModel +} + +// GetPricingModelDisplayName returns the PricingModelDisplayName field if it's non-nil, zero value otherwise. +func (b *Budget) GetPricingModelDisplayName() string { + if b == nil || b.PricingModelDisplayName == nil { + return "" + } + return *b.PricingModelDisplayName +} + +// GetPricingModelID returns the PricingModelID field if it's non-nil, zero value otherwise. +func (b *Budget) GetPricingModelID() string { + if b == nil || b.PricingModelID == nil { + return "" + } + return *b.PricingModelID +} + +// GetTargetID returns the TargetID field if it's non-nil, zero value otherwise. +func (b *Budget) GetTargetID() int64 { + if b == nil || b.TargetID == nil { + return 0 + } + return *b.TargetID +} + +// GetTargetName returns the TargetName field if it's non-nil, zero value otherwise. +func (b *Budget) GetTargetName() string { + if b == nil || b.TargetName == nil { + return "" + } + return *b.TargetName +} + +// GetTargetSubAccount returns the TargetSubAccount field if it's non-nil, zero value otherwise. +func (b *Budget) GetTargetSubAccount() string { + if b == nil || b.TargetSubAccount == nil { + return "" + } + return *b.TargetSubAccount +} + +// GetTargetType returns the TargetType field if it's non-nil, zero value otherwise. +func (b *Budget) GetTargetType() string { + if b == nil || b.TargetType == nil { + return "" + } + return *b.TargetType +} + +// GetWillAlert returns the WillAlert field if it's non-nil, zero value otherwise. +func (b *BudgetAlerting) GetWillAlert() bool { + if b == nil || b.WillAlert == nil { + return false + } + return *b.WillAlert +} + // GetActorID returns the ActorID field if it's non-nil, zero value otherwise. func (b *BypassActor) GetActorID() int64 { if b == nil || b.ActorID == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 8743dd4548c..dc08f3a982e 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2880,6 +2880,173 @@ func TestBranchProtectionRuleEvent_GetSender(tt *testing.T) { b.GetSender() } +func TestBudget_GetBudgetAlerting(tt *testing.T) { + tt.Parallel() + b := &Budget{} + b.GetBudgetAlerting() + b = nil + b.GetBudgetAlerting() +} + +func TestBudget_GetBudgetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{BudgetName: &zeroValue} + b.GetBudgetName() + b = &Budget{} + b.GetBudgetName() + b = nil + b.GetBudgetName() +} + +func TestBudget_GetBudgetType(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{BudgetType: &zeroValue} + b.GetBudgetType() + b = &Budget{} + b.GetBudgetType() + b = nil + b.GetBudgetType() +} + +func TestBudget_GetCurrency(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{Currency: &zeroValue} + b.GetCurrency() + b = &Budget{} + b.GetCurrency() + b = nil + b.GetCurrency() +} + +func TestBudget_GetCurrentAmount(tt *testing.T) { + tt.Parallel() + b := &Budget{} + b.GetCurrentAmount() + b = nil + b.GetCurrentAmount() +} + +func TestBudget_GetExcludeCostCenterUsage(tt *testing.T) { + tt.Parallel() + var zeroValue bool + b := &Budget{ExcludeCostCenterUsage: &zeroValue} + b.GetExcludeCostCenterUsage() + b = &Budget{} + b.GetExcludeCostCenterUsage() + b = nil + b.GetExcludeCostCenterUsage() +} + +func TestBudget_GetID(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{ID: &zeroValue} + b.GetID() + b = &Budget{} + b.GetID() + b = nil + b.GetID() +} + +func TestBudget_GetLimitAmount(tt *testing.T) { + tt.Parallel() + b := &Budget{} + b.GetLimitAmount() + b = nil + b.GetLimitAmount() +} + +func TestBudget_GetPricingModel(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{PricingModel: &zeroValue} + b.GetPricingModel() + b = &Budget{} + b.GetPricingModel() + b = nil + b.GetPricingModel() +} + +func TestBudget_GetPricingModelDisplayName(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{PricingModelDisplayName: &zeroValue} + b.GetPricingModelDisplayName() + b = &Budget{} + b.GetPricingModelDisplayName() + b = nil + b.GetPricingModelDisplayName() +} + +func TestBudget_GetPricingModelID(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{PricingModelID: &zeroValue} + b.GetPricingModelID() + b = &Budget{} + b.GetPricingModelID() + b = nil + b.GetPricingModelID() +} + +func TestBudget_GetTargetID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + b := &Budget{TargetID: &zeroValue} + b.GetTargetID() + b = &Budget{} + b.GetTargetID() + b = nil + b.GetTargetID() +} + +func TestBudget_GetTargetName(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{TargetName: &zeroValue} + b.GetTargetName() + b = &Budget{} + b.GetTargetName() + b = nil + b.GetTargetName() +} + +func TestBudget_GetTargetSubAccount(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{TargetSubAccount: &zeroValue} + b.GetTargetSubAccount() + b = &Budget{} + b.GetTargetSubAccount() + b = nil + b.GetTargetSubAccount() +} + +func TestBudget_GetTargetType(tt *testing.T) { + tt.Parallel() + var zeroValue string + b := &Budget{TargetType: &zeroValue} + b.GetTargetType() + b = &Budget{} + b.GetTargetType() + b = nil + b.GetTargetType() +} + +func TestBudgetAlerting_GetWillAlert(tt *testing.T) { + tt.Parallel() + var zeroValue bool + b := &BudgetAlerting{WillAlert: &zeroValue} + b.GetWillAlert() + b = &BudgetAlerting{} + b.GetWillAlert() + b = nil + b.GetWillAlert() +} + func TestBypassActor_GetActorID(tt *testing.T) { tt.Parallel() var zeroValue int64