Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion github/orgs_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import (
// GitHub API docs: https://docs.github.com/rest/orgs/rules#get-all-organization-repository-rulesets
//
//meta:operation GET /orgs/{org}/rulesets
func (s *OrganizationsService) GetAllRepositoryRulesets(ctx context.Context, org string) ([]*RepositoryRuleset, *Response, error) {
func (s *OrganizationsService) GetAllRepositoryRulesets(ctx context.Context, org string, opts *ListOptions) ([]*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("orgs/%v/rulesets", org)

u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
Expand Down
13 changes: 11 additions & 2 deletions github/orgs_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestOrganizationsService_GetAllRepositoryRulesets(t *testing.T) {

mux.HandleFunc("/orgs/o/rulesets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
"per_page": "35",
})
fmt.Fprint(w, `[{
"id": 21,
"name": "test ruleset",
Expand All @@ -37,8 +41,9 @@ func TestOrganizationsService_GetAllRepositoryRulesets(t *testing.T) {
}]`)
})

opts := &ListOptions{Page: 2, PerPage: 35}
ctx := context.Background()
rulesets, _, err := client.Organizations.GetAllRepositoryRulesets(ctx, "o")
rulesets, _, err := client.Organizations.GetAllRepositoryRulesets(ctx, "o", opts)
if err != nil {
t.Errorf("Organizations.GetAllRepositoryRulesets returned error: %v", err)
}
Expand All @@ -60,9 +65,13 @@ func TestOrganizationsService_GetAllRepositoryRulesets(t *testing.T) {
}

const methodName = "GetAllRepositoryRulesets"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.GetAllRepositoryRulesets(ctx, "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.GetAllRepositoryRulesets(ctx, "o")
got, resp, err := client.Organizations.GetAllRepositoryRulesets(ctx, "o", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
27 changes: 23 additions & 4 deletions github/repos_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ type rulesetClearBypassActors struct {
// GitHub API docs: https://docs.github.com/rest/repos/rules#get-rules-for-a-branch
//
//meta:operation GET /repos/{owner}/{repo}/rules/branches/{branch}
func (s *RepositoriesService) GetRulesForBranch(ctx context.Context, owner, repo, branch string) (*BranchRules, *Response, error) {
func (s *RepositoriesService) GetRulesForBranch(ctx context.Context, owner, repo, branch string, opts *ListOptions) (*BranchRules, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/rules/branches/%v", owner, repo, branch)

u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
Expand All @@ -55,14 +60,28 @@ func (s *RepositoriesService) GetRulesForBranch(ctx context.Context, owner, repo
return rules, resp, nil
}

// RepositoryListRulesetsOptions specifies optional parameters to the
// RepositoriesService.GetAllRulesets method.
type RepositoryListRulesetsOptions struct {
// IncludesParents indicates whether to include rulesets configured at the organization or enterprise level that apply to the repository.
IncludesParents *bool `url:"includes_parents,omitempty"`
Comment thread
gmlewis marked this conversation as resolved.
ListOptions
}

// GetAllRulesets gets all the repository rulesets for the specified repository.
// If includesParents is true, rulesets configured at the organization or enterprise level that apply to the repository will be returned.
// By default, this endpoint will include rulesets configured at the organization or enterprise level that apply to the repository.
Comment thread
gmlewis marked this conversation as resolved.
// To exclude those rulesets, set the `RepositoryListRulesetsOptions.IncludesParents` parameter to `false`.
//
// GitHub API docs: https://docs.github.com/rest/repos/rules#get-all-repository-rulesets
//
//meta:operation GET /repos/{owner}/{repo}/rulesets
func (s *RepositoriesService) GetAllRulesets(ctx context.Context, owner, repo string, includesParents bool) ([]*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/rulesets?includes_parents=%v", owner, repo, includesParents)
func (s *RepositoriesService) GetAllRulesets(ctx context.Context, owner, repo string, opts *RepositoryListRulesetsOptions) ([]*RepositoryRuleset, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/rulesets", owner, repo)

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
33 changes: 29 additions & 4 deletions github/repos_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {

mux.HandleFunc("/repos/o/repo/rules/branches/branch", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
"per_page": "35",
})
fmt.Fprint(w, `[
{
"ruleset_id": 42069,
Expand All @@ -39,8 +43,9 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
]`)
})

opts := &ListOptions{Page: 2, PerPage: 35}
ctx := context.Background()
rules, _, err := client.Repositories.GetRulesForBranch(ctx, "o", "repo", "branch")
rules, _, err := client.Repositories.GetRulesForBranch(ctx, "o", "repo", "branch", opts)
if err != nil {
t.Errorf("Repositories.GetRulesForBranch returned error: %v", err)
}
Expand All @@ -55,9 +60,13 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
}

const methodName = "GetRulesForBranch"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Repositories.GetRulesForBranch(ctx, "\n", "\n", "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Repositories.GetRulesForBranch(ctx, "o", "repo", "branch")
got, resp, err := client.Repositories.GetRulesForBranch(ctx, "o", "repo", "branch", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand All @@ -71,6 +80,11 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {

mux.HandleFunc("/repos/o/repo/rulesets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"includes_parents": "false",
"page": "2",
"per_page": "35",
})
fmt.Fprintf(w, `[
{
"id": 42,
Expand All @@ -93,8 +107,15 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
]`, referenceTimeStr)
})

opts := &RepositoryListRulesetsOptions{
IncludesParents: Ptr(false),
ListOptions: ListOptions{
Page: 2,
PerPage: 35,
},
}
ctx := context.Background()
ruleSet, _, err := client.Repositories.GetAllRulesets(ctx, "o", "repo", false)
ruleSet, _, err := client.Repositories.GetAllRulesets(ctx, "o", "repo", opts)
if err != nil {
t.Errorf("Repositories.GetAllRulesets returned error: %v", err)
}
Expand Down Expand Up @@ -124,9 +145,13 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
}

const methodName = "GetAllRulesets"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Repositories.GetAllRulesets(ctx, "\n", "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Repositories.GetAllRulesets(ctx, "o", "repo", false)
got, resp, err := client.Repositories.GetAllRulesets(ctx, "o", "repo", opts)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
Loading