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

Handle GitHub Rate Limits During Update Checks #449

Merged

Conversation

rgajason
Copy link
Contributor

GGShield checks for updates by connecting to GitHub anonymously. The anonymous API quota is relatively small. For organizations where hundreds of users all connect via a common egress IP, this can result in significant error messages (collectively across users) / confusion during GGShield operations. For example:

% git commit -m 'My Awesome Commit' awesome.py
Failed to check: {"message":"API rate limit exceeded for 1.2.3.4. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}

This PR address this issue by checking for quota exceeded condition and rescheduling the update check for after the quota has been reset.

Additionally, it adds headers to the update check request that are recommended by GitHub:

User Agent: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#user-agent-required
GH API Version: https://docs.github.com/en/rest/overview/api-versions?apiVersion=2022-11-28
Media type (accept): https://docs.github.com/en/rest/overview/media-types?apiVersion=2022-11-28

@codecov-commenter
Copy link

Codecov Report

Merging #449 (019dd91) into main (4d81348) will decrease coverage by 0.26%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #449      +/-   ##
==========================================
- Coverage   93.89%   93.63%   -0.27%     
==========================================
  Files          78       78              
  Lines        3557     3567      +10     
==========================================
  Hits         3340     3340              
- Misses        217      227      +10     
Flag Coverage Δ
unittests 93.63% <0.00%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
ggshield/core/check_updates.py 68.85% <0.00%> (-13.51%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

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

Two minor remarks, but this looks great already. Thanks a lot for taking care of the bug and for adding the missing headers to the request.

ggshield/core/check_updates.py Outdated Show resolved Hide resolved
ggshield/core/check_updates.py Show resolved Hide resolved
rgajason and others added 2 commits January 3, 2023 09:20
Co-authored-by: Aurelien Gateau <aurelien.gateau@gitguardian.com>
@rgajason
Copy link
Contributor Author

rgajason commented Jan 3, 2023

@agateau-gg both changes implemented as requested

Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

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

Thanks, merging the changes in.

@agateau-gg agateau-gg merged commit 13686b0 into GitGuardian:main Jan 3, 2023
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.

3 participants