Skip to content

Commit

Permalink
Handle invalid version strings in the name field and fallback to th…
Browse files Browse the repository at this point in the history
…e `tag_name`
  • Loading branch information
dcermak committed Nov 3, 2023
1 parent d57e506 commit aa280a7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,33 @@ def fetch_releases(
releases: list[Release] = []

for release in resp.json():
VER_STR_KEYS = ("name", "tag_name")
ver = None
ver_str = release["name"].replace("v", "")
try:
ver = parse(ver_str)
except InvalidVersion as iv_err:

for ver_str_key in VER_STR_KEYS:
ver_str = release.get(ver_str_key, "").replace("v", "").strip()
try:
ver = parse(ver_str)
break
except InvalidVersion:
pass

if ver is None:
print(
f"skipping version {ver_str}, not a valid semver, got the following error while parsing: {str(iv_err)}",
f"skipping version string {', '.join(release.get(k,'') for k in VER_STR_KEYS)},"
" not a valid semver",
file=sys.stderr,
)
continue

assert isinstance(ver, Version)

if min_version is not None and ver <= min_version:
continue
if max_version is not None and ver > max_version:
continue

releases.append(Release(version=ver_str, changelog=release["body"]))
releases.append(Release(version=str(ver), changelog=release["body"]))

return releases

Expand Down

0 comments on commit aa280a7

Please sign in to comment.