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

github-release脚本获取仓库所有release #171

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 7 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
22 changes: 17 additions & 5 deletions github-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime
import tempfile
import json

import re
import requests


Expand Down Expand Up @@ -203,9 +203,21 @@ def link_latest(name, repo_dir):
print(f"syncing {repo} to {repo_dir}")

try:
r = github_get(f"{args.base_url}{repo}/releases")
r.raise_for_status()
releases = r.json()
headers = {"Accept": "application/vnd.github+json"}
releases = []
url_str = f"{args.base_url}{repo}/releases"
pattern = re.compile(r'<(.*)>;\s*rel="next"')
while url_str:
r = github_get(url_str, headers=headers)
r.raise_for_status()
releases.extend(r.json())
next_url = re.findall(pattern=pattern,string=r.headers["link"])
jimorsm marked this conversation as resolved.
Show resolved Hide resolved
if versions > 0 and len(releases) > versions:
jimorsm marked this conversation as resolved.
Show resolved Hide resolved
url_str = None
elif next_url:
url_str = next_url[0]
else:
url_str = None
except:
traceback.print_exc()
break
Expand Down Expand Up @@ -261,4 +273,4 @@ def link_latest(name, repo_dir):
main()


# vim: ts=4 sw=4 sts=4 expandtab
# vim: ts=4 sw=4 sts=4 expandtab