Support branch aliases in releasers

Fix #430
This commit is contained in:
Jakub Kadlcik 2023-12-30 16:49:10 +01:00 committed by Pavel Raiskup
parent 9d1c10f52f
commit 3cb798fa83
2 changed files with 34 additions and 2 deletions

View file

@ -16,6 +16,13 @@ import subprocess
import sys import sys
import tempfile 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 ( from tito.common import (
run_command, run_command,
debug, debug,
@ -56,8 +63,7 @@ class FedoraGitReleaser(Releaser):
else: else:
self.cli_tool = "fedpkg" self.cli_tool = "fedpkg"
self.git_branches = \ self.git_branches = self._branches()
self.releaser_config.get(self.target, "branches").split(" ")
# check .tito/releasers.conf # check .tito/releasers.conf
if self.releaser_config.has_option(self.target, "remote_git_name"): if self.releaser_config.has_option(self.target, "remote_git_name"):
@ -86,6 +92,31 @@ class FedoraGitReleaser(Releaser):
self.no_build = no_build self.no_build = no_build
self._git_release() 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): def _get_build_target_for_branch(self, branch):
if branch in self.build_targets: if branch in self.build_targets:
return self.build_targets[branch] return self.build_targets[branch]

View file

@ -36,6 +36,7 @@ Requires: python3-setuptools
Requires: python3-bugzilla Requires: python3-bugzilla
Requires: python3-blessed Requires: python3-blessed
Requires: rpm-python3 Requires: rpm-python3
Recommends: python3-fedora-distro-aliases
%else %else
BuildRequires: python2-devel BuildRequires: python2-devel
BuildRequires: python-setuptools BuildRequires: python-setuptools