Skip to content

Commit

Permalink
Add command-line opt to enable gitlab-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Gorin authored and aschmolck committed Mar 1, 2019
1 parent c841d9c commit 97ef9dc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def regexp(str_regex):
'to use merge commits on the *target* branch (the default).)\n'
),
)
parser.add_argument(
'--rebase-remotely',
action='store_true',
help=(
"Instead of rebasing in a local clone of the repository, use GitLab's\n"
"built-in rebase functionality, via their API. Note that Marge can't add\n"
"information in the commits in this case.\n"
),
),
parser.add_argument(
'--add-tested',
action='store_true',
Expand Down Expand Up @@ -199,6 +208,16 @@ def regexp(str_regex):
raise MargeBotCliArgError('--use-merge-strategy and --batch are currently mutually exclusive')
if config.use_merge_strategy and config.add_tested:
raise MargeBotCliArgError('--use-merge-strategy and --add-tested are currently mutually exclusive')
if config.rebase_remotely:
conflicting_flag = [
'--use-merge-strategy',
'--add-tested',
'--add-reviewers',
'--add-part-of',
]
for flag in conflicting_flag:
if getattr(config, flag[2:].replace("-", "_")):
raise MargeBotCliArgError('--rebase-remotely and %s are mutually exclusive' % flag)

cli_args = []
# pylint: disable=protected-access
Expand Down Expand Up @@ -252,6 +271,14 @@ def main(args=None):

if options.use_merge_strategy:
fusion = bot.Fusion.merge
elif options.rebase_remotely:
version = api.version()
if version.release < (11, 6):
raise Exception(
"Need GitLab 11.6+ to use rebase through the API, "
"but your instance is {}".format(version)
)
fusion = bot.Fusion.gitlab_rebase
else:
fusion = bot.Fusion.rebase

Expand Down
3 changes: 3 additions & 0 deletions marge/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,6 @@ def parse(cls, string):
@property
def is_ee(self):
return self.edition == 'ee'

def __str__(self):
return '%s-%s' % ('.'.join(map(str, self.release)), self.edition)
14 changes: 14 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def api_mock(gitlab_url, auth_token):
api = gitlab_mock.Api(gitlab_url=gitlab_url, auth_token=auth_token, initial_state='initial')
user_info_for_token = dict(user_info, is_admin=auth_token == 'ADMIN-TOKEN')
api.add_user(user_info_for_token, is_current=True)
api.add_transition(gitlab_mock.GET('/version'), gitlab_mock.Ok({'version': '11.6.0-ce'}))
return api

class DoNothingBot(bot_module.Bot):
Expand Down Expand Up @@ -103,6 +104,13 @@ def test_embargo():
)


def test_rebase_remotely():
with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'):
with main('--rebase-remotely') as bot:
assert bot.config.merge_opts != job.MergeJobOptions.default()
assert bot.config.merge_opts == job.MergeJobOptions.default(fusion=job.Fusion.gitlab_rebase)


def test_use_merge_strategy():
with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'):
with main('--use-merge-strategy') as bot:
Expand Down Expand Up @@ -142,6 +150,12 @@ def test_add_reviewers():
assert bot.config.merge_opts != job.MergeJobOptions.default()
assert bot.config.merge_opts == job.MergeJobOptions.default(add_reviewers=True)

def test_rebase_remotely_option_conflicts():
for conflicting_flag in ['--use-merge-strategy', '--add-tested', '--add-part-of', '--add-reviewers']:
with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'):
with pytest.raises(app.MargeBotCliArgError):
with main('--rebase-remotely %s' % conflicting_flag) as bot:
pass

def test_impersonate_approvers():
with env(MARGE_AUTH_TOKEN="NON-ADMIN-TOKEN", MARGE_SSH_KEY="KEY", MARGE_GITLAB_URL='http://foo.com'):
Expand Down

0 comments on commit 97ef9dc

Please sign in to comment.