From 7154ac479afb39860b291202ee466ea9f46e7adb Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Thu, 26 Jan 2017 08:21:19 -0500 Subject: [PATCH] Refactored version->tag mapping logic in Tagger While the `tito.VersionTagger._get_new_tag()` method encapsulated some of the version->tag mapping logic, other areas in the `VersionTagger` used their own logic to do the mapping. This commit ensures that this mapping happens in one place, which allows for custom implementations to override the behavior simply. Signed-off-by: Steve Kuznetsov --- src/tito/builder/main.py | 2 +- src/tito/tagger/main.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index f681ba62..2aa917c4 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -452,7 +452,7 @@ def _get_tag_for_version(self, version): """ Determine what the tag will look like for a given version. Can be overridden when custom taggers override counterpart, - tito.VersionTagger._get_new_tag(). + tito.VersionTagger._get_tag_for_version(). """ return "%s-%s".format(self.project_name, version) diff --git a/src/tito/tagger/main.py b/src/tito/tagger/main.py index fe1975d8..cf0cbd1e 100644 --- a/src/tito/tagger/main.py +++ b/src/tito/tagger/main.py @@ -147,8 +147,7 @@ def _undo(self): Tag commit must be the most recent commit, and the tag must not exist in the remote git repo, otherwise we report and error out. """ - tag = "%s-%s" % (self.project_name, - get_latest_tagged_version(self.project_name)) + tag = self._get_tag_for_version(get_latest_tagged_version(self.project_name)) info_out("Undoing tag: %s" % tag) if not tag_exists_locally(tag): raise TitoException( @@ -258,7 +257,7 @@ def _make_changelog(self): write(fd, "\n") else: if old_version is not None: - last_tag = "%s-%s" % (self.project_name, old_version) + last_tag = self._get_tag_for_version(old_version) output = self._generate_default_changelog(last_tag) else: output = self._new_changelog_msg @@ -452,12 +451,7 @@ def _update_package_metadata(self, new_version): """ self._clear_package_metadata() - suffix = "" - # If global config specifies a tag suffix, use it: - if self.config.has_option(BUILDCONFIG_SECTION, "tag_suffix"): - suffix = self.config.get(BUILDCONFIG_SECTION, "tag_suffix") - - new_version_w_suffix = "%s%s" % (new_version, suffix) + new_version_w_suffix = self._get_suffixed_version(new_version) # Write out our package metadata: metadata_file = os.path.join(self.rel_eng_dir, "packages", self.project_name) @@ -555,11 +549,22 @@ def _get_git_user_info(self): def _get_new_tag(self, new_version): """ Returns the actual tag we'll be creating. """ + return self._get_tag_for_version(self._get_suffixed_version(new_version)) + + def _get_suffixed_version(self, version): + """ If global config specifies a tag suffix, use it """ suffix = "" - # If global config specifies a tag suffix, use it: if self.config.has_option(BUILDCONFIG_SECTION, "tag_suffix"): suffix = self.config.get(BUILDCONFIG_SECTION, "tag_suffix") - return "%s-%s%s" % (self.project_name, new_version, suffix) + return "{}{}".format(version, suffix) + + def _get_tag_for_version(self, version): + """ + Determine what the tag will look like for a given version. + Can be overridden when custom taggers override counterpart, + tito.Builder._get_tag_for_version(). + """ + return "{}-{}".format(self.project_name, version) def _update_version_file(self, new_version): """