Skip to content

Commit

Permalink
Merge branch 'bug-7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Mar 14, 2019
2 parents 0858f31 + 78d7a74 commit b5bc20e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions github_release_notifier/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = 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 @@ -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)
Expand Down

0 comments on commit b5bc20e

Please sign in to comment.