Skip to content

Commit

Permalink
Remove support for filtering MRs based on source and target branch (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
slovdahl authored Feb 4, 2025
1 parent deb185c commit c56328e
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 0.15.0:
- Remove support for ancient GitLab versions (#61)
- Remove support for filtering MRs based on source and target branch (#62)
* 0.14.1:
- Update dependencies (#52)
- ci: Run tests on Python 3.11 (#16)
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ optional arguments:
--git-reference-repo GIT_REFERENCE_REPO
A reference repo to be used when git cloning.
[env var: MARGE_GIT_REFERENCE_REPO] (default: None)
--branch-regexp BRANCH_REGEXP
Only process MRs whose target branches match the given regular expression.
[env var: MARGE_BRANCH_REGEXP] (default: .*)
--source-branch-regexp SOURCE_BRANCH_REGEXP
Only process MRs whose source branches match the given regular expression.
[env var: MARGE_SOURCE_BRANCH_REGEXP] (default: .*)
--debug Debug logging (includes all HTTP requests etc).
[env var: MARGE_DEBUG] (default: False)
--cli Run marge-bot as a single CLI command, not as a long-running service.
Expand Down
14 changes: 0 additions & 14 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,6 @@ def regexp(str_regex):
default=None,
help='A reference repo to be used when git cloning.\n'
)
parser.add_argument(
'--branch-regexp',
type=regexp,
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 @@ -337,8 +325,6 @@ def main(args=None):
project_regexp=options.project_regexp,
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
30 changes: 2 additions & 28 deletions marge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,7 @@ def _get_merge_requests(self, project, project_name):
api=self._api,
merge_order=self._config.merge_order,
)
branch_regexp = self._config.branch_regexp
filtered_mrs = [mr for mr in my_merge_requests
if branch_regexp.match(mr.target_branch)]
log.debug(
'MRs that match branch_regexp: %s',
[mr.web_url for mr in filtered_mrs]
)
filtered_out = set(my_merge_requests) - set(filtered_mrs)
if filtered_out:
log.debug(
'MRs that do not match branch_regexp: %s',
[mr.web_url for mr in filtered_out]
)
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 source_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
return my_merge_requests

def _process_merge_requests(self, repo_manager, project, merge_requests):
if not merge_requests:
Expand Down Expand Up @@ -223,7 +197,7 @@ def _get_single_job(self, project, merge_request, repo, config, options):

class BotConfig(namedtuple('BotConfig',
'user use_https auth_token ssh_key_file project_regexp merge_order merge_opts '
+ 'git_timeout git_reference_repo branch_regexp source_branch_regexp batch cli '
+ 'git_timeout git_reference_repo batch cli '
+ 'use_only_gitlab_api')):
pass

Expand Down
2 changes: 0 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def create_bot_config(user, options):
project_regexp='',
git_timeout='',
git_reference_repo='',
branch_regexp='',
source_branch_regexp='',
merge_order='created_at',
merge_opts=options,
batch=False,
Expand Down
14 changes: 0 additions & 14 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,6 @@ def test_git_timeout():
assert bot.config.git_timeout == datetime.timedelta(seconds=150)


def test_branch_regexp():
with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'):
with main("--branch-regexp='foo.*bar'") as bot:
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 Expand Up @@ -278,7 +266,6 @@ def test_config_file():
)
assert bot.config.project_regexp == re.compile('foo.*bar')
assert bot.config.git_timeout == datetime.timedelta(seconds=150)
assert bot.config.branch_regexp == re.compile('foo.*bar')


def test_config_overwrites():
Expand All @@ -299,4 +286,3 @@ def test_config_overwrites():
)
assert bot.config.project_regexp == re.compile('foo.*bar')
assert bot.config.git_timeout == datetime.timedelta(seconds=100)
assert bot.config.branch_regexp == re.compile('foo.*bar')

0 comments on commit c56328e

Please sign in to comment.