From 3cb798fa83a19fd01f49202f346346d9e4d0734a Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sat, 30 Dec 2023 16:49:10 +0100 Subject: [PATCH] Support branch aliases in releasers Fix #430 --- src/tito/release/distgit.py | 35 +++++++++++++++++++++++++++++++++-- tito.spec | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/tito/release/distgit.py b/src/tito/release/distgit.py index 4eef3da7..943cd255 100644 --- a/src/tito/release/distgit.py +++ b/src/tito/release/distgit.py @@ -16,6 +16,13 @@ import sys import tempfile +try: + # Optional dependency available on Fedora and EPEL9+ + # Without it, branch aliases in releasers.conf won't work. + from fedora_distro_aliases import get_distro_aliases +except ImportError: + get_distro_aliases = None + from tito.common import ( run_command, debug, @@ -56,8 +63,7 @@ def __init__(self, name=None, tag=None, build_dir=None, else: self.cli_tool = "fedpkg" - self.git_branches = \ - self.releaser_config.get(self.target, "branches").split(" ") + self.git_branches = self._branches() # check .tito/releasers.conf if self.releaser_config.has_option(self.target, "remote_git_name"): @@ -86,6 +92,31 @@ def release(self, dry_run=False, no_build=False, scratch=False): self.no_build = no_build self._git_release() + def _branches(self): + names = self.releaser_config.get(self.target, "branches").split(" ") + + # This is a bit hacky because our inheritence hierarchy is messed up. + # RHEL, and CentOS releasers inherits from the Fedora releaser instead + # of all of them having a common ancestor. For now, we only want the + # support for branch aliases in the `FedoraGitReleaser`. There is no + # reason to query Fedora PDC in RHEL and CentOS releasers. + if self.cli_tool != "fedpkg": + return names + + if not get_distro_aliases: + warn_out("Missing optional dependency `fedora-distro-aliases'") + warn_out("Branch aliases in releasers.conf won't be evaluated.") + return names + + aliases = get_distro_aliases() + result = [] + for name in names: + branches = [name] + if name in aliases: + branches = [x.branch for x in aliases[name]] + result.extend(branches) + return result + def _get_build_target_for_branch(self, branch): if branch in self.build_targets: return self.build_targets[branch] diff --git a/tito.spec b/tito.spec index 9a166256..ef1720c5 100644 --- a/tito.spec +++ b/tito.spec @@ -36,6 +36,7 @@ Requires: python3-setuptools Requires: python3-bugzilla Requires: python3-blessed Requires: rpm-python3 +Recommends: python3-fedora-distro-aliases %else BuildRequires: python2-devel BuildRequires: python-setuptools