diff --git a/Makefile b/Makefile index 435d10d..d1025dd 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION ?= 0.4.1 +VERSION ?= 0.4.2 CACHE ?= --no-cache=1 FULLVERSION ?= ${VERSION} archs ?= arm32v7 amd64 i386 arm64v8 arm32v6 diff --git a/github_release_notifier/__init__.py b/github_release_notifier/__init__.py index 8560241..71d9a7b 100644 --- a/github_release_notifier/__init__.py +++ b/github_release_notifier/__init__.py @@ -3,4 +3,4 @@ """ __all__ = ['parser', 'webhook', 'notifier'] -__version__ = '0.4.1' +__version__ = '0.4.2' diff --git a/github_release_notifier/notifier.py b/github_release_notifier/notifier.py index 7f330e8..ddb9c13 100644 --- a/github_release_notifier/notifier.py +++ b/github_release_notifier/notifier.py @@ -14,6 +14,13 @@ __DEFAULT_FILE__ = os.getenv('GRN_VERSIONS_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: @@ -32,9 +39,7 @@ def run(file: str = __DEFAULT_FILE__) -> dict: try: condition = LooseVersion(str(entry['version'])) > LooseVersion(str(get_version(package))) except TypeError as e: - # https://bugs.python.org/issue14894 - # Always consider the version is new in case of buggy comparision - condition = True + condition = version_compare(str(entry['version']), str(get_version(package))) > 0 if condition: database = _get_database(file) database[package] = entry['version']