Skip to content

feat: Add org rule-suites APIs - #4482

Open
ralucas wants to merge 3 commits into
google:masterfrom
ralucas:org_rulesuite_apis
Open

feat: Add org rule-suites APIs#4482
ralucas wants to merge 3 commits into
google:masterfrom
ralucas:org_rulesuite_apis

Conversation

@ralucas

@ralucas ralucas commented Aug 24, 2026

Copy link
Copy Markdown
  • Adds list org rule suites: GET /orgs/{org}/rulesets/rule-suites
  • Adds get org rule suite by id: GET /orgs/{org}/rulesets/rule-suites/{rule_suite_id}

- Adds list org rule suites: `GET /orgs/{org}/rulesets/rule-suites`
- Adds get org rule suite by id: `GET /orgs/{org}/rulesets/rule-suites/{rule_suite_id}`
@gmlewis gmlewis changed the title feat: adding org rule-suites apis feat: Add org rule-suites APIs Aug 25, 2026
@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.52%. Comparing base (30af001) to head (5b76268).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4482   +/-   ##
=======================================
  Coverage   98.51%   98.52%           
=======================================
  Files         195      196    +1     
  Lines       17691    17727   +36     
=======================================
+ Hits        17429    17465   +36     
  Misses        262      262           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @ralucas!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @Not-Dhananjay-Mishra

Comment thread github/orgs_rulesuites.go Outdated
// GitHub API docs: https://docs.github.com/rest/orgs/rule-suites?apiVersion=2022-11-28#list-organization-rule-suites
//
//meta:operation GET /orgs/{org}/rulesets/rule-suites
func (s *OrganizationsService) ListOrganizationRuleSuites(ctx context.Context, org string, opts *ListOptions) ([]*RuleSuite, *Response, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint accepts ref, repository_name, time_period, actor_name, rule_suite_result, evaluate_status, per_page and page as query parameters currently only per_page and page are being sent.
Let's make a new Option struct containing all of these fields.

Image

Comment thread github/orgs_rulesuites.go
Comment on lines +51 to +53
endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites", org)

u, err := addOptions(endpoint, opts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the repo.

Suggested change
endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites", org)
u, err := addOptions(endpoint, opts)
u := fmt.Sprintf("orgs/%v/rulesets/rule-suites", org)
u, err := addOptions(u, opts)

Comment thread github/orgs_rulesuites.go
Comment on lines +78 to +80
endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites/%v", org, ruleSuiteID)

req, err := s.client.NewRequest(ctx, "GET", endpoint, nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites/%v", org, ruleSuiteID)
req, err := s.client.NewRequest(ctx, "GET", endpoint, nil)
u := fmt.Sprintf("orgs/%v/rulesets/rule-suites/%v", org, ruleSuiteID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)

Comment on lines +72 to +121
func TestOrganizationsService_ListOrganizationRuleSuites_ListOptions(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/orgs/o/rulesets/rule-suites", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "2",
"per_page": "35",
})
fmt.Fprint(w, `[
{
"id": 201,
"actor_id": 13,
"actor_name": "alice",
"before_sha": "aaa111",
"after_sha": "bbb222",
"ref": "refs/heads/feature",
"repository_id": 2,
"repository_name": "repo2",
"pushed_at": "2023-07-07T08:43:03Z",
"result": "pass"
}
]`)
})

opts := &ListOptions{Page: 2, PerPage: 35}
ctx := t.Context()
suites, _, err := client.Organizations.ListOrganizationRuleSuites(ctx, "o", opts)
if err != nil {
t.Errorf("Organizations.ListOrganizationRuleSuites returned error: %v", err)
}

want := []*RuleSuite{{
ID: Ptr(int64(201)),
ActorID: Ptr(int64(13)),
ActorName: Ptr("alice"),
BeforeSHA: Ptr("aaa111"),
AfterSHA: Ptr("bbb222"),
Ref: Ptr("refs/heads/feature"),
RepositoryID: Ptr(int64(2)),
RepositoryName: Ptr("repo2"),
PushedAt: Ptr(Timestamp{time.Date(2023, time.July, 7, 8, 43, 3, 0, time.UTC)}),
Result: Ptr("pass"),
}}

if !cmp.Equal(suites, want) {
t.Errorf("Organizations.ListOrganizationRuleSuites returned %+v, want %+v", suites, want)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be removed in my opinion. we can simply add testFormValues() in TestOrganizationsService_ListOrganizationRuleSuites

Comment on lines +123 to +131
func TestOrganizationsService_ListOrganizationRuleSuites_addOptionsError(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)

_, _, err := client.Organizations.ListOrganizationRuleSuites(t.Context(), "\u007F", &ListOptions{})
if err == nil {
t.Fatal("Organizations.ListOrganizationRuleSuites returned nil error, want non-nil")
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, In my opinion we can remove this, and add testBadOptions in TestOrganizationsService_ListOrganizationRuleSuites

Ref: Ptr("refs/heads/main"),
RepositoryID: Ptr(int64(1)),
RepositoryName: Ptr("repo"),
PushedAt: Ptr(Timestamp{time.Date(2023, time.July, 6, 8, 43, 3, 0, time.UTC)}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use referenceTimestamp instead of Timestamp{time.Date(2023, time.July, 6, 8, 43, 3, 0, time.UTC)}.
same applies to other occurrences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants