Skip to content

Commit

Permalink
Update dependencies (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
slovdahl authored Jan 26, 2024
1 parent e54d0e8 commit 3333c31
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 650 deletions.
4 changes: 2 additions & 2 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def main(args=None):

if options.batch:
if options.rebase_remotely:
raise Exception("Batch processing does not work together with rebase remotely.")
raise MargeBotCliArgError("Batch processing does not work together with rebase remotely.")

logging.warning('Experimental batch mode enabled')

Expand All @@ -320,7 +320,7 @@ def main(args=None):
elif options.rebase_remotely:
version = api.version()
if version.release < (11, 6):
raise Exception(
raise MargeBotCliArgError(
"Need GitLab 11.6+ to use rebase through the API, "
f"but your instance is {version}"
)
Expand Down
16 changes: 8 additions & 8 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ def synchronize_using_gitlab_rebase(self, merge_request, verify_expected_sha=Tru
if branch.protected:
raise CannotMerge("Sorry, I can't modify protected branches!") from err
raise
else:
if verify_expected_sha and merge_request.sha != expected_sha:
raise GitLabRebaseResultMismatch(
gitlab_sha=merge_request.sha,
expected_sha=expected_sha,
)

return merge_request.sha
if verify_expected_sha and merge_request.sha != expected_sha:
raise GitLabRebaseResultMismatch(
gitlab_sha=merge_request.sha,
expected_sha=expected_sha,
)

return merge_request.sha


def _get_reviewer_names_and_emails(commits, approvals, api):
Expand Down Expand Up @@ -484,7 +484,7 @@ def default(
approval_timeout=None, embargo=None, ci_timeout=None, fusion=Fusion.rebase,
use_no_ff_batches=False, use_merge_commit_batches=False, skip_ci_batches=False,
guarantee_final_pipeline=False,
):
): # pylint: disable=too-many-arguments
approval_timeout = approval_timeout or timedelta(seconds=0)
embargo = embargo or IntervalUnion.empty()
ci_timeout = ci_timeout or timedelta(minutes=15)
Expand Down
10 changes: 5 additions & 5 deletions marge/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ def rebase(self):
def accept(self, remove_branch=False, sha=None, merge_when_pipeline_succeeds=True):
return self._api.call(PUT(
f'/projects/{self.project_id}/merge_requests/{self.iid}/merge',
dict(
should_remove_source_branch=remove_branch,
merge_when_pipeline_succeeds=merge_when_pipeline_succeeds,
sha=sha or self.sha, # if provided, ensures what is merged is what we want (or fails)
),
{
'should_remove_source_branch': remove_branch,
'merge_when_pipeline_succeeds': merge_when_pipeline_succeeds,
'sha': sha or self.sha # if provided, ensures what is merged is what we want (or fails)
},
))

def close(self):
Expand Down
899 changes: 319 additions & 580 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ attr-rgx=(([a-z_][a-z0-9_]{2,40})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$
argument-rgx=(([a-z_][a-z0-9_]{2,40})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$

[MESSAGE CONTROL]
disable=bad-continuation,
fixme,
disable=fixme,
missing-docstring,
no-self-use,
unsubscriptable-object

[SIMILARITIES]
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ tzdata = "^2022.7"
[tool.poetry.dev-dependencies]
pytest = "~7"
pytest-cov = "^4.0.0"
pytest-flake8 = "^1.1.1"
pytest-pylint = "^0.19.0"
pylint = "^3.0.3"
flake8 = "^4"
pendulum = "^2.1.2"

[tool.poetry.scripts]
marge = "marge.__main__:run"
Expand Down
6 changes: 3 additions & 3 deletions tests/git_repo_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def git(self, *args, from_repo=True):
except Exception:
log.warning('Failed to simulate: git %r %s', command, command_args)
raise
else:
return self._pretend_result_comes_from_popen(result)

return self._pretend_result_comes_from_popen(result)

@staticmethod
def _pretend_result_comes_from_popen(result):
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self, origin, remote_repos):

self.remote_repos = remote_repos
self._local_repo = GitRepoModel()
self._remotes = dict(origin=origin)
self._remotes = {"origin": origin}
self._remote_refs = {}
self._branch = None
self.on_push_callbacks = []
Expand Down
12 changes: 6 additions & 6 deletions tests/gitlab_api_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def call(self, command, sudo=None):
return []

raise MockedEndpointNotFound(command, sudo, self.state) from err
else:
if next_state:
self.state = next_state

if side_effect:
side_effect()
return response()
if next_state:
self.state = next_state

if side_effect:
side_effect()
return response()

def _find(self, command, sudo):
more_specific = self._transitions.get(_key(command, sudo, self.state))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_config_file():
with config_file() as config_file_name:
with env(MARGE_AUTH_TOKEN="ADMIN-TOKEN"):
with main(f'--config-file={config_file_name}') as bot:
admin_user_info = dict(**user_info)
admin_user_info = {**user_info}
admin_user_info['is_admin'] = True
assert bot.user.info == admin_user_info
assert bot.config.merge_opts != job.MergeJobOptions.default()
Expand All @@ -285,7 +285,7 @@ def test_config_overwrites():
with config_file() as config_file_name:
with env(MARGE_CI_TIMEOUT='20min', MARGE_AUTH_TOKEN="ADMIN-TOKEN"):
with main(f'--git-timeout=100s --config-file={config_file_name}') as bot:
admin_user_info = dict(**user_info)
admin_user_info = {**user_info}
admin_user_info['is_admin'] = True
assert bot.user.info == admin_user_info
assert bot.config.merge_opts != job.MergeJobOptions.default()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def fail_on_filter_branch(*args, **unused_kwargs):
raise subprocess.CalledProcessError(returncode=1, cmd='git rebase blah')
if 'rev-parse' in args or 'reset' in args:
return mock.Mock()
raise Exception('Unexpected call:', args)
raise AssertionError('Unexpected call:', args)

mocked_run.side_effect = fail_on_filter_branch

Expand Down
30 changes: 15 additions & 15 deletions tests/test_merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def test_accept_remove_branch(self):
self.merge_request.accept(remove_branch=boolean)
self.api.call.assert_called_once_with(PUT(
'/projects/1234/merge_requests/54/merge',
dict(
merge_when_pipeline_succeeds=True,
should_remove_source_branch=boolean,
sha='badc0de',
)
{
'merge_when_pipeline_succeeds': True,
'should_remove_source_branch': boolean,
'sha': 'badc0de',
}
))
self.api.call.reset_mock()

Expand All @@ -229,23 +229,23 @@ def test_accept_sha(self):
self.merge_request.accept(sha='g00dc0de')
self.api.call.assert_called_once_with(PUT(
'/projects/1234/merge_requests/54/merge',
dict(
merge_when_pipeline_succeeds=True,
should_remove_source_branch=False,
sha='g00dc0de',
)
{
'merge_when_pipeline_succeeds': True,
'should_remove_source_branch': False,
'sha': 'g00dc0de',
}
))

def test_accept_merge_when_pipeline_succeeds(self):
self._load(dict(INFO, sha='badc0de'))
self.merge_request.accept(merge_when_pipeline_succeeds=False)
self.api.call.assert_called_once_with(PUT(
'/projects/1234/merge_requests/54/merge',
dict(
merge_when_pipeline_succeeds=False,
should_remove_source_branch=False,
sha='badc0de',
)
{
'merge_when_pipeline_succeeds': False,
'should_remove_source_branch': False,
'sha': 'badc0de',
}
))

def test_fetch_all_opened_for_me(self):
Expand Down
76 changes: 53 additions & 23 deletions tests/test_single_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ def __init__(
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{self.merge_request_info['iid']}/merge",
dict(sha=self.merge_request_info['sha'],
should_remove_source_branch=True,
merge_when_pipeline_succeeds=True),
{
'sha': self.merge_request_info['sha'],
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Ok({}),
from_state=['pipeline-finished', 'skipped'], to_state='merged',
Expand Down Expand Up @@ -146,7 +148,11 @@ def __init__(
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{self.merge_request_info['iid']}/merge",
dict(sha=rewritten_sha, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': rewritten_sha,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Ok({}),
from_state=['passed', 'skipped'], to_state='merged',
Expand Down Expand Up @@ -404,10 +410,10 @@ def test_succeeds_if_skipped(self, mocks):

def test_succeeds_if_source_is_master(self, mocks_factory):
mocklab, api, job = mocks_factory(
extra_mocklab_opts=dict(merge_request_options={
extra_mocklab_opts={'merge_request_options': {
'source_branch': 'master',
'target_branch': 'production',
}),
}},
)

if job.opts.fusion is Fusion.gitlab_rebase:
Expand Down Expand Up @@ -581,11 +587,11 @@ def push_effects(remote_url, remote_branch, old_sha, new_sha):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(
sha=first_rewritten_sha,
should_remove_source_branch=True,
merge_when_pipeline_succeeds=True,
),
{
'sha': first_rewritten_sha,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.NotAcceptable()),
from_state='pushed_but_master_moved', to_state='merge_rejected',
Expand Down Expand Up @@ -645,7 +651,11 @@ def test_handles_races_for_merging(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.NotFound(404, {'message': '404 Branch Not Found'})),
from_state='passed', to_state='someone_else_merged',
Expand Down Expand Up @@ -682,11 +692,11 @@ def test_calculates_merge_when_pipeline_succeeds_correctly(
api.add_transition(
PUT(
f"/projects/{project_info['id']}/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(
sha=expected_sha1,
should_remove_source_branch=True,
merge_when_pipeline_succeeds=only_allow_merge_if_pipeline_succeeds
),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': only_allow_merge_if_pipeline_succeeds
},
),
Ok(True),
to_state='merged',
Expand All @@ -712,7 +722,11 @@ def test_handles_request_becoming_wip_after_push(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
from_state='passed', to_state='now_is_wip',
Expand Down Expand Up @@ -745,7 +759,11 @@ def test_guesses_git_hook_error_on_merge_refusal(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
from_state='passed', to_state='rejected_by_git_hook',
Expand Down Expand Up @@ -781,7 +799,11 @@ def test_assumes_unresolved_discussions_on_merge_refusal(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
from_state='passed', to_state='unresolved_discussions',
Expand Down Expand Up @@ -818,7 +840,11 @@ def test_discovers_if_someone_closed_the_merge_request(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
from_state='passed', to_state='oops_someone_closed_it',
Expand Down Expand Up @@ -851,7 +877,11 @@ def test_tells_explicitly_that_gitlab_refused_to_merge(self, mocks):
api.add_transition(
PUT(
f"/projects/1234/merge_requests/{mocklab.merge_request_info['iid']}/merge",
dict(sha=expected_sha1, should_remove_source_branch=True, merge_when_pipeline_succeeds=True),
{
'sha': expected_sha1,
'should_remove_source_branch': True,
'merge_when_pipeline_succeeds': True
},
),
Error(marge.gitlab.MethodNotAllowed(405, {'message': '405 Method Not Allowed'})),
from_state='passed', to_state='rejected_for_mysterious_reasons',
Expand Down Expand Up @@ -900,7 +930,7 @@ def test_wont_merge_branches_with_autosquash_if_rewriting(self, mocks):
def test_waits_for_approvals(self, mock_log, mocks_factory):
five_secs = timedelta(seconds=5)
mocklab, api, job = mocks_factory(
extra_opts=dict(approval_timeout=five_secs, reapprove=True)
extra_opts={'approval_timeout': five_secs, 'reapprove': True}
)

if job.opts.fusion is Fusion.gitlab_rebase:
Expand Down

0 comments on commit 3333c31

Please sign in to comment.