Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source branch regexp added #206

Merged
merged 1 commit into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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():
micheelengronne marked this conversation as resolved.
Show resolved Hide resolved
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