diff --git a/.golangci.yml b/.golangci.yml index 36483d72a03..adbb8a0c4d6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -362,6 +362,7 @@ linters: - 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-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..2119f1d5620 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. + // 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..9b062bc0347 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: int64(1342004), PerPage: 30} ctx := t.Context() orgs, _, err := client.Organizations.ListAll(ctx, opt) if err != nil {