Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pagination #503

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

thomasjm
Copy link

This PR is an attempt to support GitHub's pagination API.

At present, this package allows you to construct a request with FetchCount, which has constructors FetchAtLeast Word and FetchAll. Both of these cause the library to repeatedly call the GitHub endpoint as many times as necessary to collect the desired number of items.

This obscures the actual pagination API from the user. What if I want to fetch a specific page? And what if I want to access the Link header information returned by the GitHub API, to determine the total number of pages, next/last page links, etc.?

This PR adds a new constructor to FetchCount called FetchPage PageParams. PageParams allows you to specify the page and/or perPage as integers, and you will get exactly the items you're asking for.

This PR also exposes a function parsePageLinks, which you can use to extract the page links from an HTTP response. You can use it like this:

mgr <- newManager tlsManagerSettings
ret <- executeRequestWithMgrAndRes mgr auth $
  issuesForRepoR owner repo mempty (GitHub.FetchPage (GitHub.PageParams (Just 2) (Just 1)))
case ret of
  Left e -> expectationFailure . show $ e
  Right res -> do
    let issues = responseBody res
    let pageLinks = GitHub.parsePageLinks res
    putStrLn ("pageLinks: " ++ show pageLinks)

I'd like to expose this in a nicer way at the higher levels of the API, like the github function. Maybe by providing a githubPaged version that returns the response value and also a PageLinks object. But this is serviceable enough for now. More API design suggestions are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant