From 219efc50a2c17b159cc21ca3e7b4d5ac872a26f1 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Wed, 22 Apr 2020 15:42:31 +0200 Subject: [PATCH] Add a possibility to have full datetime entries in changelog Fix #305 Unfortunatelly we need to use `pytz` instead of `datetime.timezone` because of python2. --- src/tito/tagger/main.py | 8 +++++++- test/unit/tagger_tests.py | 38 ++++++++++++++++++++++++++++++++++++++ tito.props.5.asciidoc | 6 ++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/unit/tagger_tests.py diff --git a/src/tito/tagger/main.py b/src/tito/tagger/main.py index 5fd0272..4501668 100644 --- a/src/tito/tagger/main.py +++ b/src/tito/tagger/main.py @@ -68,7 +68,7 @@ class VersionTagger(ConfigObject): self.spec_file_name) self.keep_version = keep_version - self.today = strftime("%a %b %d %Y") + self.today = self._changelog_date() (self.git_user, self.git_email) = self._get_git_user_info() git_email = self.git_email if git_email is None: @@ -163,6 +163,12 @@ class VersionTagger(ConfigObject): print undo_tag(tag) + def _changelog_date(self): + option = (BUILDCONFIG_SECTION, "changelog_date_with_time") + if self.config.has_option(*option) and self.config.getboolean(*option): + return strftime("%a %b %d %T %Z %Y") + return strftime("%a %b %d %Y") + def _changelog_remove_cherrypick(self, line): """ remove text "(cherry picked from commit ..." from line unless diff --git a/test/unit/tagger_tests.py b/test/unit/tagger_tests.py new file mode 100644 index 0000000..ecb3b38 --- /dev/null +++ b/test/unit/tagger_tests.py @@ -0,0 +1,38 @@ +import unittest +import mock +from datetime import datetime +from tito.tagger import VersionTagger +from tito.compat import PY2, RawConfigParser + +from unit import is_epel6 +if is_epel6: + import unittest2 as unittest +else: + import unittest + + +def strftime_mock(s): + if not PY2: + from datetime import timezone + tzinfo = None if PY2 else timezone.utc + someday = datetime(2020, 4, 22, 15, 2, tzinfo=tzinfo) + return someday.strftime(s) + + +class TestVersionTagger(unittest.TestCase): + def setUp(self): + self.config = RawConfigParser() + + @mock.patch("tito.tagger.main.strftime", strftime_mock) + def test_today(self): + tagger = VersionTagger(self.config) + assert tagger.today == "Wed Apr 22 2020" + + @unittest.skipIf(PY2, "It is not trivial to represent timezone in python2 because" + "datetime.timezone is python3 only and pytz is not in EPEL. This feature" + "is for F27+ and EPEL8+ so we don't need to test it for python2") + @mock.patch("tito.tagger.main.strftime", strftime_mock) + def test_today_datetime(self): + self.config["buildconfig"] = {"changelog_date_with_time": True} + tagger = VersionTagger(self.config) + assert tagger.today == "Wed Apr 22 15:02:00 UTC 2020" diff --git a/tito.props.5.asciidoc b/tito.props.5.asciidoc index c4b6550..c2793ea 100644 --- a/tito.props.5.asciidoc +++ b/tito.props.5.asciidoc @@ -69,6 +69,12 @@ changelog_do_not_remove_cherrypick:: If set to 0, it will not remove from cherry picked commits the part "(cherry picked from commit ...)" +changelog_date_with_time:: +By default, changelog dates don't contain time (e.g. Wed Nov 1 2017). When +this option is set to `True`, changelog entries are generated in a datetime +format (e.g. Wed Nov 1 11:08:13 EDT 2017). This feature requires RPM 4.14, +therefore it is supported only on Fedora 27, EPEL8, openSUSE Leap 15 and higher. + tag_suffix:: An optional specification of a suffix to append to all tags created by tito for this repo. Can be useful for situations where one git repository is