From ecaa942afcd5b82a0f4eddceca3b73b8123261b0 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jun 04 2018 07:45:28 +0000 Subject: Handle malformed versions in changelogs There can be anything really, so when we fail to compare the versions for any reason the changelog should not crash. Instead we will take whatever entries we collected so far (which could potentially be missing something), or if we have nothing so far return the whole changelog. Fixes: https://pagure.io/compose-utils/issue/71 Signed-off-by: Lubomír Sedlář --- diff --git a/compose_utils/changelog.py b/compose_utils/changelog.py index ed32512..1a38638 100644 --- a/compose_utils/changelog.py +++ b/compose_utils/changelog.py @@ -104,18 +104,27 @@ def get_changelog_diff_from_headers(old, new, max_records=-1): if new_changelog and old_changelog: result = [] - old_time = old_changelog[0].time - old_nvr = LooseVersion(to_utf8(old_changelog[0].name).rsplit(None, 1)[-1]) - while new_changelog: - entry = new_changelog.pop(0) - new_nvr = LooseVersion(to_utf8(entry.name).rsplit(None, 1)[-1]) - if entry.time < old_time or (entry.time == old_time and new_nvr <= old_nvr): - # We want to take all entries from new changelog that are newer - # than old changelog, or from the same day as latest old entry - # but with newer version. - break - result.insert(0, entry) - return result + try: + old_time = old_changelog[0].time + old_nvr = LooseVersion(to_utf8(old_changelog[0].name).rsplit(None, 1)[-1]) + while new_changelog: + entry = new_changelog.pop(0) + new_nvr = LooseVersion(to_utf8(entry.name).rsplit(None, 1)[-1]) + if entry.time < old_time or ( + entry.time == old_time and new_nvr <= old_nvr + ): + # We want to take all entries from new changelog that are newer + # than old changelog, or from the same day as latest old entry + # but with newer version. + break + result.insert(0, entry) + return result + except Exception: + # There was a problem getting all new changelog entries. If we + # managed to get at least some, return that, otherwise fall back to + # returning whole changelog. + if result: + return result return new_changelog