Paginating public GitHub repos identifies the last page
Created by: vrto
Problem
Our paging logic thru public repositories in GitHub enterprise doesn't gracefully terminate the pagination on the last page.
Public repositories are paged using since query parameter, which carries the offset where the pagination ought to resume.
The problem is that GitHub API somewhat surprisingly returns an OK (HTTP 200) response when more items are to be served, but NOT-FOUND (HTTP 404) when the provided since
value is greater than the last known entry ID.
This error bubbles up to the user interface, which we don't want to.
Solution
Checking for status code (200 vs. 404) might not be enough, as GitHub can serve a 404 response for many different reasons.
The proper way to determine whether we've reached the last page (hence an empty result) is by looking at the Link
response header.
It carries a first
relationship attribute, and an optional next
relationship attribute - only when there's another page to look at. If next
is missing, we know we've reached the end.
Test plan
- see
TestPublicRepos_PaginationTerminatesGracefully
test