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

Add a helper function gh_rate_limit to extract rate limit information. #105

Merged
merged 3 commits into from
Jan 31, 2020
Merged

Conversation

rundel
Copy link
Contributor

@rundel rundel commented Jan 31, 2020

Adds the function gh_rate_limit which returns basic rate limit information from either a gh_response object or a call to GET /rate_limit.

Currently returns a list with:

  • limit - overall limit (integer)
  • remaining - remaining requests (integer)
  • reset - reset time for limit (datetime)

Fixes #93 and may be helpful for #67.

Copy link
Member

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great! I made some small comments below.

R/utils.R Outdated Show resolved Hide resolved
R/gh_rate_limit.R Outdated Show resolved Hide resolved
R/gh_rate_limit.R Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Jan 31, 2020

Codecov Report

Merging #105 into master will decrease coverage by 4.85%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #105      +/-   ##
==========================================
- Coverage   50.22%   45.37%   -4.86%     
==========================================
  Files          11       12       +1     
  Lines         442      454      +12     
==========================================
- Hits          222      206      -16     
- Misses        220      248      +28
Impacted Files Coverage Δ
R/utils.R 58.33% <ø> (ø) ⬆️
R/gh_rate_limit.R 100% <100%> (ø)
R/gh_whoami.R 41.17% <0%> (-58.83%) ⬇️
R/gh_response.R 42.37% <0%> (-25.43%) ⬇️
R/package.R 58.82% <0%> (-8.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a36cccb...360fb5c. Read the comment docs.

@rundel
Copy link
Contributor Author

rundel commented Jan 31, 2020

One other wrinkle is that depending on the end point you hit you get slightly different details (since things like search have different rate limits).

> r  = gh("/user")
> gh_rate_limit(r)
$limit
[1] 5000
$remaining
[1] 4985
$reset
[1] "2020-01-31 14:59:35 PST"
> r2 = gh("/search/repositories", q="tidyverse")
> gh_rate_limit(r2)
$limit
[1] 30
$remaining
[1] 29
$reset
[1] "2020-01-31 14:15:26 PST"

All of this is available from "/rate_limit" and looks like the possible different options are: core, search, graphql, integration_manifest, source_import. Search is the only one that "looks" different. I'm not seeing anything obvious in the response headers about what rate limit you used.

Dealing with search separately via a gh_search (#33) may make this less of an issue.

@gaborcsardi
Copy link
Member

One other wrinkle is that depending on the end point you hit you get slightly different details (since things like search have different rate limits).

I think we can handle these separately/later, this PR is a good step already. :)

@gaborcsardi gaborcsardi merged commit 891715b into r-lib:master Jan 31, 2020
@gaborcsardi
Copy link
Member

Thanks much!

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.

return the rate limit in the responses
3 participants