Skip to content

Commit

Permalink
scripts: gracefully handle GitHub rate limiting error when downloadin…
Browse files Browse the repository at this point in the history
…g a node (#11)
  • Loading branch information
ixje authored May 28, 2024
1 parent 311f148 commit b162cca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/download-node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import stat
import pathlib
from tomlkit import parse
import os

logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
Expand All @@ -29,7 +30,19 @@ def main():
doc = parse(f.read())
target_tag = doc["tool"]["neogo"]["tag"]

r = requests.get("https://api.github.com/repos/nspcc-dev/neo-go/releases")
token = os.getenv("GITHUB_TOKEN")
if token is None:
r = requests.get("https://api.github.com/repos/nspcc-dev/neo-go/releases")
else:
r = requests.get(
"https://api.github.com/repos/nspcc-dev/neo-go/releases",
headers={"authorization": f"Bearer {token}"},
)

if r.status_code == 403:
raise Exception(
f"we probably execeeded the rate limit. Remaining: {r.headers['X-RateLimit-Remaining']}"
)

for release in r.json():
if release["tag_name"] != target_tag:
Expand Down

0 comments on commit b162cca

Please sign in to comment.