From c42250864d94287b278a04b0385ab0dcf6e5e1a0 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 10 Feb 2026 14:57:39 +0200 Subject: [PATCH 1/2] fix!: Add field `PerPage` to `OrganizationsListOptions` --- .golangci.yml | 1 - github/github-accessors.go | 16 ++++++++ github/github-accessors_test.go | 22 ++++++++++ github/github-iterators.go | 31 -------------- github/github-iterators_test.go | 72 --------------------------------- github/orgs.go | 10 ++--- github/orgs_test.go | 5 +-- 7 files changed, 44 insertions(+), 113 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 36483d72a03..7dffc818c40 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -361,7 +361,6 @@ linters: - NotificationListOptions.Before # TODO: Activities - NotificationListOptions.Participating # TODO: Activities - NotificationListOptions.Since # TODO: Activities - - OrganizationsListOptions.Since # TODO: Organizations - ProjectV2ItemFieldValue.DataType # TODO: Projects - ProjectV2ItemFieldValue.Name # TODO: Projects - PullRequestListCommentsOptions.Direction # TODO: PullRequests diff --git a/github/github-accessors.go b/github/github-accessors.go index 1d79e676c4d..eee825d29c2 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -17374,6 +17374,22 @@ func (o *OrganizationInstallations) GetTotalCount() int { return *o.TotalCount } +// GetPerPage returns the PerPage field if it's non-nil, zero value otherwise. +func (o *OrganizationsListOptions) GetPerPage() int { + if o == nil || o.PerPage == nil { + return 0 + } + return *o.PerPage +} + +// GetSince returns the Since field if it's non-nil, zero value otherwise. +func (o *OrganizationsListOptions) GetSince() int64 { + if o == nil || o.Since == nil { + return 0 + } + return *o.Since +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (o *OrgBlockEvent) GetAction() string { if o == nil || o.Action == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 49296912c7c..f74d6e94554 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -22631,6 +22631,28 @@ func TestOrganizationInstallations_GetTotalCount(tt *testing.T) { o.GetTotalCount() } +func TestOrganizationsListOptions_GetPerPage(tt *testing.T) { + tt.Parallel() + var zeroValue int + o := &OrganizationsListOptions{PerPage: &zeroValue} + o.GetPerPage() + o = &OrganizationsListOptions{} + o.GetPerPage() + o = nil + o.GetPerPage() +} + +func TestOrganizationsListOptions_GetSince(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + o := &OrganizationsListOptions{Since: &zeroValue} + o.GetSince() + o = &OrganizationsListOptions{} + o.GetSince() + o = nil + o.GetSince() +} + func TestOrgBlockEvent_GetAction(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-iterators.go b/github/github-iterators.go index 9689e311574..b1f330da02d 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -1881,37 +1881,6 @@ func (s *OrganizationsService) ListIter(ctx context.Context, user string, opts * } } -// ListAllIter returns an iterator that paginates through all results of ListAll. -func (s *OrganizationsService) ListAllIter(ctx context.Context, opts *OrganizationsListOptions) iter.Seq2[*Organization, error] { - return func(yield func(*Organization, error) bool) { - // Create a copy of opts to avoid mutating the caller's struct - if opts == nil { - opts = &OrganizationsListOptions{} - } else { - opts = Ptr(*opts) - } - - for { - items, resp, err := s.ListAll(ctx, opts) - if err != nil { - yield(nil, err) - return - } - - for _, item := range items { - if !yield(item, nil) { - return - } - } - - if resp.NextPage == 0 { - break - } - opts.ListOptions.Page = resp.NextPage - } - } -} - // ListBlockedUsersIter returns an iterator that paginates through all results of ListBlockedUsers. func (s *OrganizationsService) ListBlockedUsersIter(ctx context.Context, org string, opts *ListOptions) iter.Seq2[*User, error] { return func(yield func(*User, error) bool) { diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index eba8c44540b..73289af8eea 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -4335,78 +4335,6 @@ func TestOrganizationsService_ListIter(t *testing.T) { } } -func TestOrganizationsService_ListAllIter(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - var callNum int - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - callNum++ - switch callNum { - case 1: - w.Header().Set("Link", `; rel="next"`) - fmt.Fprint(w, `[{},{},{}]`) - case 2: - fmt.Fprint(w, `[{},{},{},{}]`) - case 3: - fmt.Fprint(w, `[{},{}]`) - case 4: - w.WriteHeader(http.StatusNotFound) - case 5: - fmt.Fprint(w, `[{},{}]`) - } - }) - - iter := client.Organizations.ListAllIter(t.Context(), nil) - var gotItems int - for _, err := range iter { - gotItems++ - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - } - if want := 7; gotItems != want { - t.Errorf("client.Organizations.ListAllIter call 1 got %v items; want %v", gotItems, want) - } - - opts := &OrganizationsListOptions{} - iter = client.Organizations.ListAllIter(t.Context(), opts) - gotItems = 0 - for _, err := range iter { - gotItems++ - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - } - if want := 2; gotItems != want { - t.Errorf("client.Organizations.ListAllIter call 2 got %v items; want %v", gotItems, want) - } - - iter = client.Organizations.ListAllIter(t.Context(), nil) - gotItems = 0 - for _, err := range iter { - gotItems++ - if err == nil { - t.Error("expected error; got nil") - } - } - if gotItems != 1 { - t.Errorf("client.Organizations.ListAllIter call 3 got %v items; want 1 (an error)", gotItems) - } - - iter = client.Organizations.ListAllIter(t.Context(), nil) - gotItems = 0 - iter(func(item *Organization, err error) bool { - gotItems++ - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - return false - }) - if gotItems != 1 { - t.Errorf("client.Organizations.ListAllIter call 4 got %v items; want 1 (an error)", gotItems) - } -} - func TestOrganizationsService_ListBlockedUsersIter(t *testing.T) { t.Parallel() client, mux, _ := setup(t) diff --git a/github/orgs.go b/github/orgs.go index 185d0393039..6298d16ff86 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -153,13 +153,11 @@ func (p Plan) String() string { // OrganizationsListOptions specifies the optional parameters to the // OrganizationsService.ListAll method. type OrganizationsListOptions struct { - // Since filters Organizations by ID. - Since int64 `url:"since,omitempty"` + // An organization ID. Only return organizations with an ID greater than this ID. + Since *int64 `url:"since,omitempty"` - // Note: Pagination is powered exclusively by the Since parameter, - // ListOptions.Page has no effect. - // ListOptions.PerPage controls an undocumented GitHub API parameter. - ListOptions + // The number of results per page (max 100). + PerPage *int `url:"per_page,omitempty"` } // ListAll lists all organizations, in the order that they were created on GitHub. diff --git a/github/orgs_test.go b/github/orgs_test.go index b89a64a292a..4910070a499 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -71,14 +71,13 @@ func TestOrganizationsService_ListAll(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - since := int64(1342004) mux.HandleFunc("/organizations", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testFormValues(t, r, values{"since": "1342004"}) + testFormValues(t, r, values{"since": "1342004", "per_page": "30"}) fmt.Fprint(w, `[{"id":4314092}]`) }) - opt := &OrganizationsListOptions{Since: since} + opt := &OrganizationsListOptions{Since: Ptr(int64(1342004)), PerPage: Ptr(30)} ctx := t.Context() orgs, _, err := client.Organizations.ListAll(ctx, opt) if err != nil { From 485d0aca91fc1b0725f87eba1864488a3cd8f6e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 10 Feb 2026 17:50:58 +0200 Subject: [PATCH 2/2] revert --- .golangci.yml | 2 ++ github/github-accessors.go | 16 ---------------- github/github-accessors_test.go | 22 ---------------------- github/orgs.go | 4 ++-- github/orgs_test.go | 2 +- 5 files changed, 5 insertions(+), 41 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7dffc818c40..adbb8a0c4d6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -361,6 +361,8 @@ linters: - NotificationListOptions.Before # TODO: Activities - NotificationListOptions.Participating # TODO: Activities - NotificationListOptions.Since # TODO: Activities + - OrganizationsListOptions.Since # TODO: Organizations + - OrganizationsListOptions.PerPage # TODO: Organizations - ProjectV2ItemFieldValue.DataType # TODO: Projects - ProjectV2ItemFieldValue.Name # TODO: Projects - PullRequestListCommentsOptions.Direction # TODO: PullRequests diff --git a/github/github-accessors.go b/github/github-accessors.go index eee825d29c2..1d79e676c4d 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -17374,22 +17374,6 @@ func (o *OrganizationInstallations) GetTotalCount() int { return *o.TotalCount } -// GetPerPage returns the PerPage field if it's non-nil, zero value otherwise. -func (o *OrganizationsListOptions) GetPerPage() int { - if o == nil || o.PerPage == nil { - return 0 - } - return *o.PerPage -} - -// GetSince returns the Since field if it's non-nil, zero value otherwise. -func (o *OrganizationsListOptions) GetSince() int64 { - if o == nil || o.Since == nil { - return 0 - } - return *o.Since -} - // GetAction returns the Action field if it's non-nil, zero value otherwise. func (o *OrgBlockEvent) GetAction() string { if o == nil || o.Action == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index f74d6e94554..49296912c7c 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -22631,28 +22631,6 @@ func TestOrganizationInstallations_GetTotalCount(tt *testing.T) { o.GetTotalCount() } -func TestOrganizationsListOptions_GetPerPage(tt *testing.T) { - tt.Parallel() - var zeroValue int - o := &OrganizationsListOptions{PerPage: &zeroValue} - o.GetPerPage() - o = &OrganizationsListOptions{} - o.GetPerPage() - o = nil - o.GetPerPage() -} - -func TestOrganizationsListOptions_GetSince(tt *testing.T) { - tt.Parallel() - var zeroValue int64 - o := &OrganizationsListOptions{Since: &zeroValue} - o.GetSince() - o = &OrganizationsListOptions{} - o.GetSince() - o = nil - o.GetSince() -} - func TestOrgBlockEvent_GetAction(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/orgs.go b/github/orgs.go index 6298d16ff86..2119f1d5620 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -154,10 +154,10 @@ func (p Plan) String() string { // OrganizationsService.ListAll method. type OrganizationsListOptions struct { // An organization ID. Only return organizations with an ID greater than this ID. - Since *int64 `url:"since,omitempty"` + Since int64 `url:"since,omitempty"` // The number of results per page (max 100). - PerPage *int `url:"per_page,omitempty"` + PerPage int `url:"per_page,omitempty"` } // ListAll lists all organizations, in the order that they were created on GitHub. diff --git a/github/orgs_test.go b/github/orgs_test.go index 4910070a499..9b062bc0347 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -77,7 +77,7 @@ func TestOrganizationsService_ListAll(t *testing.T) { fmt.Fprint(w, `[{"id":4314092}]`) }) - opt := &OrganizationsListOptions{Since: Ptr(int64(1342004)), PerPage: Ptr(30)} + opt := &OrganizationsListOptions{Since: int64(1342004), PerPage: 30} ctx := t.Context() orgs, _, err := client.Organizations.ListAll(ctx, opt) if err != nil {