From c809f21d6c6ca2348fb2598134a14911ea28d3b7 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Tue, 10 Feb 2026 14:07:34 +0000 Subject: [PATCH 1/2] add ListOptions to ListDeploymentBranchPolicies and ListCustomDeploymentRuleIntegrations --- github/repos_deployment_branch_policies.go | 6 +++++- github/repos_deployment_branch_policies_test.go | 11 ++++++++--- github/repos_deployment_protection_rules.go | 6 +++++- github/repos_deployment_protection_rules_test.go | 9 +++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/github/repos_deployment_branch_policies.go b/github/repos_deployment_branch_policies.go index 77ac73e44e1..41088f11735 100644 --- a/github/repos_deployment_branch_policies.go +++ b/github/repos_deployment_branch_policies.go @@ -35,8 +35,12 @@ type DeploymentBranchPolicyRequest struct { // GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#list-deployment-branch-policies // //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies -func (s *RepositoriesService) ListDeploymentBranchPolicies(ctx context.Context, owner, repo, environment string) (*DeploymentBranchPolicyResponse, *Response, error) { +func (s *RepositoriesService) ListDeploymentBranchPolicies(ctx context.Context, owner, repo, environment string, opts *ListOptions) (*DeploymentBranchPolicyResponse, *Response, error) { u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies", owner, repo, environment) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/repos_deployment_branch_policies_test.go b/github/repos_deployment_branch_policies_test.go index c87ad4d8c57..28918356463 100644 --- a/github/repos_deployment_branch_policies_test.go +++ b/github/repos_deployment_branch_policies_test.go @@ -17,12 +17,17 @@ func TestRepositoriesService_ListDeploymentBranchPolicies(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/repos/o/r/environments/e/deployment-branch-policies", func(w http.ResponseWriter, _ *http.Request) { + mux.HandleFunc("/repos/o/r/environments/e/deployment-branch-policies", func(w http.ResponseWriter, r *http.Request) { + testFormValues(t, r, values{ + "page": "1", + "per_page": "30", + }) fmt.Fprint(w, `{"total_count":2, "branch_policies":[{"id":1}, {"id": 2}]}`) }) + opts := &ListOptions{Page: 1, PerPage: 30} ctx := t.Context() - got, _, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e") + got, _, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e", opts) if err != nil { t.Errorf("Repositories.ListDeploymentBranchPolicies returned error: %v", err) } @@ -40,7 +45,7 @@ func TestRepositoriesService_ListDeploymentBranchPolicies(t *testing.T) { const methodName = "ListDeploymentBranchPolicies" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e") + got, resp, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e", opts) if got != nil { t.Errorf("got non-nil Repositories.ListDeploymentBranchPolicies response: %+v", got) } diff --git a/github/repos_deployment_protection_rules.go b/github/repos_deployment_protection_rules.go index 29d49032818..3454f1f28cf 100644 --- a/github/repos_deployment_protection_rules.go +++ b/github/repos_deployment_protection_rules.go @@ -92,8 +92,12 @@ func (s *RepositoriesService) CreateCustomDeploymentProtectionRule(ctx context.C // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#list-custom-deployment-rule-integrations-available-for-an-environment // //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/apps -func (s *RepositoriesService) ListCustomDeploymentRuleIntegrations(ctx context.Context, owner, repo, environment string) (*ListCustomDeploymentRuleIntegrationsResponse, *Response, error) { +func (s *RepositoriesService) ListCustomDeploymentRuleIntegrations(ctx context.Context, owner, repo, environment string, opts *ListOptions) (*ListCustomDeploymentRuleIntegrationsResponse, *Response, error) { u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules/apps", owner, repo, environment) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/repos_deployment_protection_rules_test.go b/github/repos_deployment_protection_rules_test.go index 743144e040f..d9e45d0b378 100644 --- a/github/repos_deployment_protection_rules_test.go +++ b/github/repos_deployment_protection_rules_test.go @@ -113,11 +113,16 @@ func TestRepositoriesService_ListCustomDeploymentRuleIntegrations(t *testing.T) mux.HandleFunc("/repos/o/r/environments/e/deployment_protection_rules/apps", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{ + "page": "1", + "per_page": "30", + }) fmt.Fprint(w, `{"total_count": 2, "available_custom_deployment_protection_rule_integrations": [{"id": 1, "node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy", "slug": "a-custom-app", "integration_url": "https://api.github.com/apps/a-custom-app"}, {"id": 2, "node_id": "UHVE67RlcGxveW1lbnRTdTY!jfeuy", "slug": "another-custom-app", "integration_url": "https://api.github.com/apps/another-custom-app"}]}`) }) ctx := t.Context() - got, _, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e") + opts := &ListOptions{Page: 1, PerPage: 30} + got, _, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e", opts) if err != nil { t.Errorf("Repositories.ListCustomDeploymentRuleIntegrations returned error: %v", err) } @@ -135,7 +140,7 @@ func TestRepositoriesService_ListCustomDeploymentRuleIntegrations(t *testing.T) const methodName = "ListCustomDeploymentRuleIntegrations" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e") + got, resp, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e", opts) if got != nil { t.Errorf("got non-nil Repositories.ListCustomDeploymentRuleIntegrations response: %+v", got) } From ea9dedb6582c076128a8e339d8b14768f46a4462 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Tue, 10 Feb 2026 14:34:57 +0000 Subject: [PATCH 2/2] add badOptions --- github/repos_deployment_branch_policies_test.go | 5 +++++ github/repos_deployment_protection_rules_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/github/repos_deployment_branch_policies_test.go b/github/repos_deployment_branch_policies_test.go index 28918356463..31518a4d365 100644 --- a/github/repos_deployment_branch_policies_test.go +++ b/github/repos_deployment_branch_policies_test.go @@ -44,6 +44,11 @@ func TestRepositoriesService_ListDeploymentBranchPolicies(t *testing.T) { } const methodName = "ListDeploymentBranchPolicies" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Repositories.ListDeploymentBranchPolicies(ctx, "\n", "\n", "\n", opts) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { got, resp, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e", opts) if got != nil { diff --git a/github/repos_deployment_protection_rules_test.go b/github/repos_deployment_protection_rules_test.go index d9e45d0b378..7abb4cb27ab 100644 --- a/github/repos_deployment_protection_rules_test.go +++ b/github/repos_deployment_protection_rules_test.go @@ -139,6 +139,10 @@ func TestRepositoriesService_ListCustomDeploymentRuleIntegrations(t *testing.T) } const methodName = "ListCustomDeploymentRuleIntegrations" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "\n", "\n", "\n", opts) + return err + }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { got, resp, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e", opts) if got != nil {