From 78d7a745a4faf85c065d8459bf512381432f5983 Mon Sep 17 00:00:00 2001 From: Jay MOULIN Date: Thu, 14 Mar 2019 18:11:19 +0100 Subject: [PATCH] fixes #7 - can compare version number that doesn't follow semver (beware, alphanum) --- github_release_notifier/notifier.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/github_release_notifier/notifier.py b/github_release_notifier/notifier.py index e2355fa..6cb5b5a 100644 --- a/github_release_notifier/notifier.py +++ b/github_release_notifier/notifier.py @@ -5,22 +5,15 @@ import os import requests import logging -import re import threading from .webhook import get, get_list from .parser import parse from pathlib import Path +from distutils.version import LooseVersion __DEFAULT_FILE__ = str(Path.home()) + '/.github_release_notifier/versions' -def version_compare(version1: str, version2: str) -> int: - def normalize(v): - return [int(x) for x in re.sub(r'([^.0-9]+)', '', v).split(".")] - - return (normalize(version1) > normalize(version2)) - (normalize(version1) < normalize(version2)) - - def _call_webhook(webhook: str, entry: str, logger: logging.Logger) -> None: logger.info("Hook call : %s / %s" % (webhook, json.dumps(entry))) try: @@ -36,7 +29,7 @@ def run(file: str = __DEFAULT_FILE__) -> dict: for package in get_list(): try: for entry in parse(package): - if version_compare(entry['version'], get_version(package)) > 0: + if LooseVersion(entry['version']) > LooseVersion(get_version(package)): database = _get_database(file) database[package] = entry['version'] _set_database(database, file)