Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion github/repos_deployment_branch_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 13 additions & 3 deletions github/repos_deployment_branch_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -39,8 +44,13 @@ 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")
got, resp, err := client.Repositories.ListDeploymentBranchPolicies(ctx, "o", "r", "e", opts)
if got != nil {
t.Errorf("got non-nil Repositories.ListDeploymentBranchPolicies response: %+v", got)
}
Expand Down
6 changes: 5 additions & 1 deletion github/repos_deployment_protection_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions github/repos_deployment_protection_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -134,8 +139,12 @@ 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")
got, resp, err := client.Repositories.ListCustomDeploymentRuleIntegrations(ctx, "o", "r", "e", opts)
if got != nil {
t.Errorf("got non-nil Repositories.ListCustomDeploymentRuleIntegrations response: %+v", got)
}
Expand Down
Loading