#420 Add the ability to configure multiple regex expressions for base_module_stream_regex_from_branch
Merged 5 years ago by onosek. Opened 5 years ago by mprahl.

file modified
+10 -6
@@ -1988,26 +1988,30 @@ 

          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):

@@ -17,3 +17,7 @@ 

  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

file modified
+2 -8
@@ -2122,7 +2122,7 @@ 

              '--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 @@ 

  

          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 @@ 

  

          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 = {

This is to support the use-case described in FACTORY-3896

OK, I also didn't find any problem. Merging.

Pull-Request has been merged by onosek

5 years ago