diff --git a/README.md b/README.md index 3f6f25a5..503ad615 100644 --- a/README.md +++ b/README.md @@ -453,6 +453,8 @@ marge-bot with `--embargo "Friday 1pm - Monday 9am" --branch-regexp master` and the other with `--branch-regexp (?!master)`. This would allow development to continue on other branches during the embargo on master. +It is possible to restrict the source branches with `--source-branch-regexp`. + ## Some handy git aliases Only `git bisect run` on commits that have passed CI (requires running marge-bot with `--add-tested`): diff --git a/marge/app.py b/marge/app.py index 6d057c72..07486431 100644 --- a/marge/app.py +++ b/marge/app.py @@ -197,6 +197,12 @@ def regexp(str_regex): default='.*', help='Only process MRs whose target branches match the given regular expression.\n', ) + parser.add_argument( + '--source-branch-regexp', + type=regexp, + default='.*', + help='Only process MRs whose source branches match the given regular expression.\n', + ) parser.add_argument( '--debug', action='store_true', @@ -289,6 +295,7 @@ def main(args=None): git_timeout=options.git_timeout, git_reference_repo=options.git_reference_repo, branch_regexp=options.branch_regexp, + source_branch_regexp=options.source_branch_regexp, merge_order=options.merge_order, merge_opts=bot.MergeJobOptions.default( add_tested=options.add_tested, diff --git a/marge/bot.py b/marge/bot.py index 1afb3f0e..398dde46 100644 --- a/marge/bot.py +++ b/marge/bot.py @@ -119,7 +119,20 @@ def _get_merge_requests(self, project, project_name): 'MRs that do not match branch_regexp: %s', [mr.web_url for mr in filtered_out] ) - return filtered_mrs + source_branch_regexp = self._config.source_branch_regexp + source_filtered_mrs = [mr for mr in filtered_mrs + if source_branch_regexp.match(mr.source_branch)] + log.debug( + 'MRs that match source_branch_regexp: %s', + [mr.web_url for mr in source_filtered_mrs] + ) + source_filtered_out = set(filtered_mrs) - set(source_filtered_mrs) + if filtered_out: + log.debug( + 'MRs that do not match source_branch_regexp: %s', + [mr.web_url for mr in source_filtered_out] + ) + return source_filtered_mrs def _process_merge_requests(self, repo_manager, project, merge_requests): if not merge_requests: @@ -174,7 +187,7 @@ def _get_single_job(self, project, merge_request, repo, options): class BotConfig(namedtuple('BotConfig', 'user ssh_key_file project_regexp merge_order merge_opts git_timeout ' + - 'git_reference_repo branch_regexp batch')): + 'git_reference_repo branch_regexp source_branch_regexp batch')): pass diff --git a/tests/test_app.py b/tests/test_app.py index 2de41a34..822a42c9 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -216,6 +216,12 @@ def test_branch_regexp(): assert bot.config.branch_regexp == re.compile('foo.*bar') +def test_source_branch_regexp(): + with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'): + with main("--source-branch-regexp='foo.*bar'") as bot: + assert bot.config.source_branch_regexp == re.compile('foo.*bar') + + def test_git_reference_repo(): with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'): with main("--git-reference-repo='/foo/reference_repo'") as bot: