Skip to content

Commit

Permalink
Use old version comparison as fallback (since new is sooo lame)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed May 4, 2019
1 parent 056d8d3 commit d17770c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 0.4.1
VERSION ?= 0.4.2
CACHE ?= --no-cache=1
FULLVERSION ?= ${VERSION}
archs ?= arm32v7 amd64 i386 arm64v8 arm32v6
Expand Down
2 changes: 1 addition & 1 deletion github_release_notifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""

__all__ = ['parser', 'webhook', 'notifier']
__version__ = '0.4.1'
__version__ = '0.4.2'
11 changes: 8 additions & 3 deletions github_release_notifier/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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']
Expand Down

0 comments on commit d17770c

Please sign in to comment.