r-lib / gh

Minimalistic GitHub API client in R
https://gh.r-lib.org
Other
223 stars 52 forks source link

Fix pagination for various response types #141

Closed gaborcsardi closed 3 years ago

gaborcsardi commented 3 years ago

Use 'total_count' and info from the schema on how to calculate the "length" of a response.

Fixes #135.

gaborcsardi commented 3 years ago

@rundel Thanks for looking at this. I think it is definitely an improvement and hopefully we were conservative enough not to break anyone's code.

There is still this to fix:

se = gh::gh(
  "GET /search/code?q=foobar",
  .limit=101
)
lengths(se)
#>        total_count incomplete_results              items
#>                  2                  2                200

se$total_count
#> [1] 18043087 18080930

se$incomplete_results
#> [1]  TRUE FALSE

In the future I am hoping that we can use r-lib/webfakes and the info from the spec to write a test suite with reasonable coverage, and then we can be more confident about handling the output of the API better.

gaborcsardi commented 3 years ago

Oh, yeah the issue with that code is this line:

          if (is.atomic(z)) unique(z)

and of course the API provided different values for total_count and incomplete_results for the two responses. I'll tweak that a bit and will use the latest value for these two fields.