diff --git a/github/github-iterators.go b/github/github-iterators.go index 99c03f4e134..fdc9500a428 100644 --- a/github/github-iterators.go +++ b/github/github-iterators.go @@ -3181,37 +3181,6 @@ func (s *RepositoriesService) ListAllTopicsIter(ctx context.Context, owner strin } } -// ListAutolinksIter returns an iterator that paginates through all results of ListAutolinks. -func (s *RepositoriesService) ListAutolinksIter(ctx context.Context, owner string, repo string, opts *ListOptions) iter.Seq2[*Autolink, error] { - return func(yield func(*Autolink, error) bool) { - // Create a copy of opts to avoid mutating the caller's struct - if opts == nil { - opts = &ListOptions{} - } else { - opts = Ptr(*opts) - } - - for { - items, resp, err := s.ListAutolinks(ctx, owner, repo, opts) - if err != nil { - yield(nil, err) - return - } - - for _, item := range items { - if !yield(item, nil) { - return - } - } - - if resp.NextPage == 0 { - break - } - opts.Page = resp.NextPage - } - } -} - // ListBranchesIter returns an iterator that paginates through all results of ListBranches. func (s *RepositoriesService) ListBranchesIter(ctx context.Context, owner string, repo string, opts *BranchListOptions) iter.Seq2[*Branch, error] { return func(yield func(*Branch, error) bool) { diff --git a/github/github-iterators_test.go b/github/github-iterators_test.go index a85629d5be8..21e09280b9e 100644 --- a/github/github-iterators_test.go +++ b/github/github-iterators_test.go @@ -7359,78 +7359,6 @@ func TestRepositoriesService_ListAllTopicsIter(t *testing.T) { } } -func TestRepositoriesService_ListAutolinksIter(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.Repositories.ListAutolinksIter(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.Repositories.ListAutolinksIter call 1 got %v items; want %v", gotItems, want) - } - - opts := &ListOptions{} - iter = client.Repositories.ListAutolinksIter(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.Repositories.ListAutolinksIter call 2 got %v items; want %v", gotItems, want) - } - - iter = client.Repositories.ListAutolinksIter(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.Repositories.ListAutolinksIter call 3 got %v items; want 1 (an error)", gotItems) - } - - iter = client.Repositories.ListAutolinksIter(t.Context(), "", "", nil) - gotItems = 0 - iter(func(item *Autolink, err error) bool { - gotItems++ - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - return false - }) - if gotItems != 1 { - t.Errorf("client.Repositories.ListAutolinksIter call 4 got %v items; want 1 (an error)", gotItems) - } -} - func TestRepositoriesService_ListBranchesIter(t *testing.T) { t.Parallel() client, mux, _ := setup(t) diff --git a/github/repos_autolinks.go b/github/repos_autolinks.go index 5bf2cede3cd..2deb9f5a67a 100644 --- a/github/repos_autolinks.go +++ b/github/repos_autolinks.go @@ -31,12 +31,8 @@ type Autolink struct { // GitHub API docs: https://docs.github.com/rest/repos/autolinks#get-all-autolinks-of-a-repository // //meta:operation GET /repos/{owner}/{repo}/autolinks -func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Autolink, *Response, error) { +func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo string) ([]*Autolink, *Response, error) { u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } req, err := s.client.NewRequest("GET", u, nil) if err != nil { diff --git a/github/repos_autolinks_test.go b/github/repos_autolinks_test.go index ebd2028275a..ba607f5986a 100644 --- a/github/repos_autolinks_test.go +++ b/github/repos_autolinks_test.go @@ -20,15 +20,11 @@ func TestRepositoriesService_ListAutolinks(t *testing.T) { mux.HandleFunc("/repos/o/r/autolinks", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1, "key_prefix": "TICKET-", "url_template": "https://example.com/TICKET?query="}, {"id":2, "key_prefix": "STORY-", "url_template": "https://example.com/STORY?query="}]`) }) - opt := &ListOptions{ - Page: 2, - } ctx := t.Context() - autolinks, _, err := client.Repositories.ListAutolinks(ctx, "o", "r", opt) + autolinks, _, err := client.Repositories.ListAutolinks(ctx, "o", "r") if err != nil { t.Errorf("Repositories.ListAutolinks returned error: %v", err) } @@ -44,12 +40,12 @@ func TestRepositoriesService_ListAutolinks(t *testing.T) { const methodName = "ListAutolinks" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Repositories.ListAutolinks(ctx, "\n", "\n", opt) + _, _, err = client.Repositories.ListAutolinks(ctx, "\n", "\n") return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.ListAutolinks(ctx, "o", "r", opt) + got, resp, err := client.Repositories.ListAutolinks(ctx, "o", "r") if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) }