8000 Refactor get_github_auth_token by coni2k · Pull Request #71 · ossf/criticality_score · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor get_github_auth_token #71

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 2 commits into from
Jan 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions criticality_score/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,21 @@ def get_github_auth_token():
assert github_auth_token, 'GITHUB_AUTH_TOKEN needs to be set.'
tokens = github_auth_token.split(',')

wait_time = None
min_wait_time = None
token_obj = None
for token in tokens:
token_obj = github.Github(token)
near_expiry, wait_time = get_github_token_info(token_obj)
if not min_wait_time or wait_time < min_wait_time:
min_wait_time = wait_time
if not near_expiry:
_CACHED_GITHUB_TOKEN = token
_CACHED_GITHUB_TOKEN_OBJ = token_obj
return token_obj

print(f'Rate limit exceeded, sleeping till reset: {wait_time} seconds.',
print(f'Rate limit exceeded, sleeping till reset: {round(min_wait_time / 60, 1)} minutes.',
file=sys.stderr)
time.sleep(wait_time)
time.sleep(min_wait_time)
return token_obj


Expand Down
0