Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@
// 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
}

Check warning on line 24 in github/orgs_rules.go

View check run for this annotation

Codecov / codecov/patch

github/orgs_rules.go#L23-L24

Added lines #L23 - L24 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
Expand Down
9 changes: 7 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 @@ -62,7 +67,7 @@ func TestOrganizationsService_GetAllRepositoryRulesets(t *testing.T) {
const methodName = "GetAllRepositoryRulesets"

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 @@
// 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
}

Check warning on line 47 in github/repos_rules.go

View check run for this annotation

Codecov / codecov/patch

github/repos_rules.go#L46-L47

Added lines #L46 - L47 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
Expand All @@ -55,14 +60,28 @@
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
}

Check warning on line 84 in github/repos_rules.go

View check run for this annotation

Codecov / codecov/patch

github/repos_rules.go#L83-L84

Added lines #L83 - L84 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
Expand Down
25 changes: 21 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 @@ -57,7 +62,7 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) {
const methodName = "GetRulesForBranch"

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 +76,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 +103,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 @@ -126,7 +143,7 @@ func TestRepositoriesService_GetAllRulesets(t *testing.T) {
const methodName = "GetAllRulesets"

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