feat: Add org rule-suites APIs - #4482
Conversation
- 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}`
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| // 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) { |
| endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites", org) | ||
|
|
||
| u, err := addOptions(endpoint, opts) |
There was a problem hiding this comment.
For consistency with the rest of the repo.
| 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) |
| endpoint := fmt.Sprintf("orgs/%v/rulesets/rule-suites/%v", org, ruleSuiteID) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", endpoint, nil) |
There was a problem hiding this comment.
| 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) |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
This test can be removed in my opinion. we can simply add testFormValues() in TestOrganizationsService_ListOrganizationRuleSuites
| 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") | ||
| } | ||
| } |
There was a problem hiding this comment.
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)}), |
There was a problem hiding this comment.
We can use referenceTimestamp instead of Timestamp{time.Date(2023, time.July, 6, 8, 43, 3, 0, time.UTC)}.
same applies to other occurrences.

GET /orgs/{org}/rulesets/rule-suitesGET /orgs/{org}/rulesets/rule-suites/{rule_suite_id}