Skip to content

Commit

Permalink
scripts: refactor rate-limit workaround when downloading node and pro…
Browse files Browse the repository at this point in the history
…vide more information (#12)
  • Loading branch information
ixje authored May 29, 2024
1 parent 1ec8c7d commit d413530
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/validate-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ jobs:
pip install -e .[dev]
- if: matrix.os != 'windows-latest'
name: fetch neo-go for Unix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd boatest
source venv/bin/activate
cd scripts
python download-node.py
- if: matrix.os == 'windows-latest'
name: fetch neo-go for Windows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd boatest
venv/Scripts/activate
Expand Down
21 changes: 11 additions & 10 deletions scripts/download-node.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ def main():
doc = parse(f.read())
target_tag = doc["tool"]["neogo"]["tag"]

headers = None
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 token is not None:
headers = {"authorization": f"Bearer {token}"}

r = requests.get(
"https://api.github.com/repos/nspcc-dev/neo-go/releases",
headers=headers,
)

if r.status_code == 403:
if r.status_code != 200:
r2 = requests.get("https://api.github.com/rate_limit", headers=headers)
raise Exception(
f"we probably execeeded the rate limit. Remaining: {r.headers['X-RateLimit-Remaining']}"
f"we probably execeeded the rate limit. Rate limit info: {r2.json()}"
)

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

0 comments on commit d413530

Please sign in to comment.