Skip to content

Commit

Permalink
Refactored version->tag mapping logic in Tagger
Browse files Browse the repository at this point in the history
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 <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Jan 26, 2017
1 parent b277962 commit 7154ac4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/tito/builder/main.py
Expand Up @@ -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)

Expand Down
27 changes: 16 additions & 11 deletions src/tito/tagger/main.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 7154ac4

Please sign in to comment.