Skip to content

Commit

Permalink
Fix since+page pagination bug (#2218)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlewis committed Dec 6, 2021
1 parent b8b15df commit f5943db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion github/github.go
Expand Up @@ -544,7 +544,7 @@ func (r *Response) populatePageValues() {
continue
}

if since != "" {
if since != "" && page == "" {
page = since
}

Expand Down
29 changes: 29 additions & 0 deletions github/github_test.go
Expand Up @@ -677,6 +677,35 @@ func TestResponse_populateSinceValues(t *testing.T) {
}
}

func TestResponse_SinceWithPage(t *testing.T) {
r := http.Response{
Header: http.Header{
"Link": {`<https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=1>; rel="first",` +
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=2>; rel="prev",` +
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=4>; rel="next",` +
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=5>; rel="last"`,
},
},
}

response := newResponse(&r)
if got, want := response.FirstPage, 1; got != want {
t.Errorf("response.FirstPage: %v, want %v", got, want)
}
if got, want := response.PrevPage, 2; want != got {
t.Errorf("response.PrevPage: %v, want %v", got, want)
}
if got, want := response.NextPage, 4; want != got {
t.Errorf("response.NextPage: %v, want %v", got, want)
}
if got, want := response.LastPage, 5; want != got {
t.Errorf("response.LastPage: %v, want %v", got, want)
}
if got, want := response.NextPageToken, ""; want != got {
t.Errorf("response.NextPageToken: %v, want %v", got, want)
}
}

func TestResponse_cursorPagination(t *testing.T) {
r := http.Response{
Header: http.Header{
Expand Down

0 comments on commit f5943db

Please sign in to comment.