Skip to content

Commit

Permalink
source branch regexp added
Browse files Browse the repository at this point in the history
  • Loading branch information
micheelengronne authored and aschmolck committed Jun 15, 2019
1 parent 33f062a commit 07a7372
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`):
Expand Down
7 changes: 7 additions & 0 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions marge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down
6 changes: 6 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 07a7372

Please sign in to comment.