Skip to content

Support pagination #503

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

Merged
merged 11 commits into from
May 9, 2025
Merged

Conversation

thomasjm
Copy link
Contributor

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!

@andreasabel andreasabel merged commit 2bed394 into haskell-github:master May 9, 2025
1 check passed
@andreasabel andreasabel added this to the 0.30 milestone May 9, 2025
andreasabel added a commit that referenced this pull request May 9, 2025
andreasabel added a commit that referenced this pull request May 9, 2025
andreasabel added a commit that referenced this pull request May 9, 2025
@andreasabel andreasabel removed this from the 0.30 milestone May 9, 2025
@andreasabel
Copy link
Member

I had to revert this PR since it did not support GHC 9.0 and below.
It is reopened in:

@andreasabel andreasabel added this to the 0.30 milestone May 9, 2025
andreasabel added a commit that referenced this pull request May 9, 2025
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.

2 participants