Skip to content

Commit 8c01a01

Browse files
committed
Fix since+page pagination bug
1 parent b8b15df commit 8c01a01

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func (r *Response) populatePageValues() {
544544
continue
545545
}
546546

547-
if since != "" {
547+
if since != "" && page == "" {
548548
page = since
549549
}
550550

github/github_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,35 @@ func TestResponse_populateSinceValues(t *testing.T) {
677677
}
678678
}
679679

680+
func TestResponse_SinceWithPage(t *testing.T) {
681+
r := http.Response{
682+
Header: http.Header{
683+
"Link": {`<https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=1>; rel="first",` +
684+
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=2>; rel="prev",` +
685+
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=4>; rel="next",` +
686+
` <https://api.github.com/?since=2021-12-04T10%3A43%3A42Z&page=5>; rel="last"`,
687+
},
688+
},
689+
}
690+
691+
response := newResponse(&r)
692+
if got, want := response.FirstPage, 1; got != want {
693+
t.Errorf("response.FirstPage: %v, want %v", got, want)
694+
}
695+
if got, want := response.PrevPage, 2; want != got {
696+
t.Errorf("response.PrevPage: %v, want %v", got, want)
697+
}
698+
if got, want := response.NextPage, 4; want != got {
699+
t.Errorf("response.NextPage: %v, want %v", got, want)
700+
}
701+
if got, want := response.LastPage, 5; want != got {
702+
t.Errorf("response.LastPage: %v, want %v", got, want)
703+
}
704+
if got, want := response.NextPageToken, ""; want != got {
705+
t.Errorf("response.NextPageToken: %v, want %v", got, want)
706+
}
707+
}
708+
680709
func TestResponse_cursorPagination(t *testing.T) {
681710
r := http.Response{
682711
Header: http.Header{

0 commit comments

Comments
 (0)