Skip to content

Commit

Permalink
Use requests link parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed May 20, 2020
1 parent f6d5c35 commit a462ab4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions ci/github_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ def github_paginated(session, url):
Get all the results from a paginated GitHub url.
"""
while True:
print(f"GETTING: {url}")
resp = session.get(url)
check_ok(resp)
yield from resp.json()
if 'Link' not in resp.headers:
break
links = resp.headers['link'].split(",")
next_link = next((link for link in links if 'rel="next"' in link), None)
next_link = resp.links.get("next", None)
if not next_link:
break
url = next_link.split(";")[0].strip(" <>")
url = next_link["url"]

def get_releases(session, repo):
"""
Expand All @@ -74,7 +70,7 @@ def get_releases(session, repo):
Returns:
A dict mapping tag names to release dictionaries.
"""
url = RELEASES_URL.format(repo=repo) + "?per_page=100"
url = RELEASES_URL.format(repo=repo)
releases = { r['tag_name']: r for r in github_paginated(session, url) }
return releases

Expand Down

0 comments on commit a462ab4

Please sign in to comment.