Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Go v1.23 introduces the new `iter` package.

The new `github/gen-iterators.go` file auto-generates "*Iter" methods in `github/github-iterators.go`
for all methods that support page number iteration (using the `NextPage` field in each response)
or string cursor iteration (using the `Cursor` field in each response).
or string cursor iteration (using the `After` field in each response).
To handle rate limiting issues, make sure to use a rate-limiting transport.
(See [Rate Limiting](/#rate-limiting) above for more details.)
To use these methods, simply create an iterator and then range over it, for example:
Expand Down
10 changes: 5 additions & 5 deletions github/gen-iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ func ({{.RecvVar}} *{{.RecvType}}) {{.IterMethod}}({{.Args}}) iter.Seq2[{{.Retur
}

{{if and .UseListCursorOptions .UseListOptions}}
if resp.Cursor == "" && resp.NextPage == 0 {
if resp.After == "" && resp.NextPage == 0 {
break
}
{{.OptsName}}.ListCursorOptions.Cursor = resp.Cursor
{{.OptsName}}.ListCursorOptions.After = resp.After
{{.OptsName}}.ListOptions.Page = resp.NextPage
{{else if .UseListCursorOptions}}
if resp.Cursor == "" {
if resp.After == "" {
break
}
{{.OptsName}}.ListCursorOptions.Cursor = resp.Cursor
{{.OptsName}}.ListCursorOptions.After = resp.After
{{else if .UseListOptions}}
if resp.NextPage == 0 {
break
Expand Down Expand Up @@ -494,7 +494,7 @@ func Test{{.RecvType}}_{{.IterMethod}}(t *testing.T) {
switch callNum {
case 1:
{{- if .UseListCursorOptions}}
w.Header().Set("Link", ` + "`" + `<https://api.github.com/?cursor=yo>; rel="next"` + "`" + `)
w.Header().Set("Link", ` + "`" + `<https://api.github.com/?after=yo>; rel="next"` + "`" + `)
{{else}}
w.Header().Set("Link", ` + "`" + `<https://api.github.com/?page=1>; rel="next"` + "`" + `)
{{end -}}
Expand Down
44 changes: 22 additions & 22 deletions github/github-iterators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions github/github-iterators_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions test/integration/pagination_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2026 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build integration

package integration

import (
"testing"

"github.com/google/go-github/v82/github"
)

func TestSecurityAdvisories_ListGlobalSecurityAdvisories(t *testing.T) {
opt := &github.ListGlobalSecurityAdvisoriesOptions{
ListCursorOptions: github.ListCursorOptions{
PerPage: 2,
},
}
advisories, resp, err := client.SecurityAdvisories.ListGlobalSecurityAdvisories(t.Context(), opt)
if err != nil {
t.Fatalf("ListGlobalSecurityAdvisories returned error: %v", err)
}

if got, want := len(advisories), 2; got != want {
t.Errorf("ListGlobalSecurityAdvisories returned %v advisories, want %v", got, want)
}

if resp.After == "" {
t.Error("ListGlobalSecurityAdvisories returned an empty 'after' cursor")
}

if resp.Cursor != "" {
t.Error("ListGlobalSecurityAdvisories returned a non-empty 'cursor' value")
}
}
Loading