From 3aab252e142c49abd0f10f17cb6b842c4f63d92c Mon Sep 17 00:00:00 2001 From: mprahl Date: Feb 22 2019 16:00:59 +0000 Subject: Add the ability to configure multiple regex expressions for base_module_stream_regex_from_branch Signed-off-by: mprahl --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index db1b4e9..4aae289 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1988,26 +1988,30 @@ see API KEY section of copr-cli(1) man page. buildrequires = self.args.buildrequires or [] branch_search = None try: - # The regex to parse the base module stream override from the dist-git branch name. + # The regexes to parse the base module stream override from the dist-git branch name. # For example, if you had a branch called `10-fedora-29.0.1` and you wanted to # parse `f29.0.1` from that as the stream to use for the base module, you could # have a regex of `(f)(?:edora)(?:\-)(\d+\.\d+\.\d+)$`. Then after combining # the capture groups, you'd get the desired result of `f29.0.1`. - branch_bm_regex = self.config.get( - self.config_section, 'base_module_stream_regex_from_branch') + branch_bm_regexes = self.config.get( + self.config_section, 'base_module_stream_regex_from_branch').strip().split('\n') # The base module (e.g. platform) to apply the buildrequire override to if the parsing # of the branch name is successfull bm = self.config.get(self.config_section, 'base_module') except configparser.NoOptionError: pass else: - branch_search = re.search(branch_bm_regex, branch) + # Check if any of the regexes match, and break after the first match + for regex in branch_bm_regexes: + branch_search = re.search(regex, branch) + if branch_search: + break if branch_search: - # Concatenate all the groups together to get the desired stream. + # Concatenate all the groups that are not None together to get the desired stream. # This approach is taken in case there are sections to ignore. # For instance, if we need to parse `f27.0.0` from `fedora-27.0.0`. - bm_stream = ''.join(branch_search.groups()) + bm_stream = ''.join(group for group in branch_search.groups() if group) # Don't override the base module buildrequire if the user # manually already overrode it with the `--buildrequire` argument if not any(br[0] == bm for br in buildrequires): diff --git a/tests/fixtures/rpkg.conf b/tests/fixtures/rpkg.conf index 241194e..0a3a79e 100644 --- a/tests/fixtures/rpkg.conf +++ b/tests/fixtures/rpkg.conf @@ -17,3 +17,7 @@ oidc_id_provider = https://id.fedoraproject.org/openidc/ oidc_client_id = mbs-authorizer oidc_client_secret = notsecret oidc_scopes = openid,https://id.fedoraproject.org/scope/groups,https://mbs.fedoraproject.org/oidc/submit-build +base_module_stream_regex_from_branch = + (f)(?:edora)(?:\-)(\d+\.\d+\.\d+)$ + (?:\-LP\-)(.+)$ +base_module = platform diff --git a/tests/test_cli.py b/tests/test_cli.py index e035938..3dfa9e8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2122,7 +2122,7 @@ class TestModulesCli(CliTestCase): '--path', self.cloned_repo_path, 'module-build', 'git://pkgs.fedoraproject.org/modules/testmodule?#79d87a5a', - '10-fedora-27.0.1' + '10-LP-f27.0.1' ] mock_get.return_value.ok = True mock_get.return_value.json.return_value = { @@ -2133,15 +2133,12 @@ class TestModulesCli(CliTestCase): with patch('sys.argv', new=cli_cmd): cli = self.new_cli() - cli.config.set('rpkg.mbs', 'base_module', 'platform') - cli.config.set('rpkg.mbs', 'base_module_stream_regex_from_branch', - r'(f)(?:edora)(?:\-)(\d+\.\d+\.\d+)$') cli.module_build() exp_json = { 'scmurl': ('git://pkgs.fedoraproject.org/modules/testmodule?' '#79d87a5a'), - 'branch': '10-fedora-27.0.1', + 'branch': '10-LP-f27.0.1', 'buildrequire_overrides': {'platform': ['f27.0.1']} } exp_url = ('https://mbs.fedoraproject.org/module-build-service/2/' @@ -2177,9 +2174,6 @@ class TestModulesCli(CliTestCase): with patch('sys.argv', new=cli_cmd): cli = self.new_cli() - cli.config.set('rpkg.mbs', 'base_module', 'platform') - cli.config.set('rpkg.mbs', 'base_module_stream_regex_from_branch', - r'(f)(?:edora)(?:\-)(\d+\.\d+\.\d+)$') cli.module_build() exp_json = {