From a84e40fcf30921042f82699ae2325c20d91fe25a Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Sep 19 2017 14:06:41 +0000 Subject: changelog: Extract changelogs from same days If the package is built twice on the same day, we want to extract even changelog entries from same day but with newer version. Signed-off-by: Lubomír Sedlář --- diff --git a/compose_utils/changelog.py b/compose_utils/changelog.py index b378183..b02617f 100644 --- a/compose_utils/changelog.py +++ b/compose_utils/changelog.py @@ -11,6 +11,7 @@ __all__ = ( import os import json +from distutils.version import LooseVersion import kobo.pkgset from kobo.rpmlib import parse_nvra, make_nvr, make_nvra, get_changelogs_from_header @@ -103,11 +104,14 @@ def get_changelog_diff_from_headers(old, new, max_records=-1): if new_changelog and old_changelog: result = [] old_time = old_changelog[0].time - while True: - if not new_changelog: - break + old_nvr = LooseVersion(old_changelog[0].name.rsplit(None, 1)[-1]) + while new_changelog: entry = new_changelog.pop(0) - if entry.time <= old_time: + new_nvr = LooseVersion(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 diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 43144cd..8b9ef60 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -5,10 +5,12 @@ import locale import mock import unittest +from kobo.rpmlib import ChangelogEntry + from .helpers import get_compose, get_fixture import productmd.compose -from compose_utils.changelog import ComposeChangelog +from compose_utils.changelog import ComposeChangelog, get_changelog_diff_from_headers DUMMY_FIREFOX_SIZE = 5966 + 5934 @@ -183,5 +185,33 @@ class TestFormat(unittest.TestCase): expected) +class TestCompareChangelogs(unittest.TestCase): + def test_select_new(self): + c1 = ChangelogEntry('John Doe 1.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 1.1-1', 2000000, 'change 2') + old = mock.Mock(changelogs=[c1]) + new = mock.Mock(changelogs=[c2, c1]) + clog = get_changelog_diff_from_headers(old, new) + self.assertEqual(clog, [c2]) + + def test_select_with_same_date(self): + c1 = ChangelogEntry('John Doe 1.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 1.1-1', 1000000, 'change 2') + old = mock.Mock(changelogs=[c1]) + new = mock.Mock(changelogs=[c2, c1]) + clog = get_changelog_diff_from_headers(old, new) + self.assertEqual(clog, [c2]) + + def test_no_subset(self): + c1 = ChangelogEntry('John Doe 0:2.0-1', 1000000, 'change 1') + c2 = ChangelogEntry('John Doe 1:1.1-1', 1000000, 'change 2') + c3 = ChangelogEntry('John Doe 1:1.2-1', 1000000, 'change 3') + c4 = ChangelogEntry('John Doe 1:1.3-1', 1000000, 'change 4') + old = mock.Mock(changelogs=[c3, c1]) + new = mock.Mock(changelogs=[c4, c2, c1]) + clog = get_changelog_diff_from_headers(old, new) + self.assertEqual(clog, [c4]) + + if __name__ == '__main__': unittest.main()