From dba77147a53e3e584dc3972ecdb6537d177a30a2 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 29 Nov 2023 18:42:48 +0100 Subject: [PATCH] Consider version with the higther number as the latest release --- check_forgejo_upgrade | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/check_forgejo_upgrade b/check_forgejo_upgrade index dc287a0..5b982a8 100755 --- a/check_forgejo_upgrade +++ b/check_forgejo_upgrade @@ -81,18 +81,31 @@ CURRENT = CURRENT.replace("+", "-") logging.debug("Cleaned current version: %s", CURRENT) LATEST = None +LATEST_INT = None try: logging.debug("Get releases RSS feed from %s...", options.url) r = requests.get(options.url, timeout=options.timeout) logging.debug("Data retreive:\n%s", r.text) data = xmltodict.parse(r.text) + versions = {} for item in data["rss"]["channel"]["item"]: version = re.sub("^v", "", item["title"]) if not options.include_rc and "-rc" in version: logging.debug("Ignore release candidate %s", version) continue - LATEST = version - break + version_int = int(re.sub(r"[\.-]", "000", version)) + logging.debug("Found version %s (%s)", version, version_int) + if not LATEST_INT or LATEST_INT < version_int: + if LATEST: + logging.debug( + "Version %s considered as newer than %s, override latest version", + version, + LATEST, + ) + LATEST = version + LATEST_INT = version_int + else: + logging.debug("Version %s considered as oldest than %s", version, LATEST) except Exception: # pylint: disable=broad-except pass logging.debug("Latest version: %s", LATEST)