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

Wait for merge status to resolve. #265

Merged
merged 1 commit into from
Nov 11, 2020
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
22 changes: 22 additions & 0 deletions marge/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ def wait_for_ci_to_pass(self, merge_request, commit_sha=None):

raise CannotMerge('CI is taking too long.')

def wait_for_merge_status_to_resolve(self, merge_request):
attempts = 3
waiting_time_in_secs = 5

log.info('Waiting for MR !%s to have merge_status can_be_merged', merge_request.iid)
for attempt in range(attempts):
merge_request.refetch_info()
merge_status = merge_request.merge_status

if merge_status == 'can_be_merged':
log.info('MR !%s can be merged on attempt %d', merge_request.iid, attempt)
return

if merge_status == 'cannot_be_merged':
log.info('MR !%s cannot be merged on attempt %d', merge_request.iid, attempt)
raise CannotMerge('GitLab believes this MR cannot be merged.')

if merge_status == 'unchecked':
log.info('MR !%s merge status currently unchecked on attempt %d.', merge_request.iid, attempt)

time.sleep(waiting_time_in_secs)

def unassign_from_mr(self, merge_request):
log.info('Unassigning from MR !%s', merge_request.iid)
author_id = merge_request.author_id
Expand Down
4 changes: 4 additions & 0 deletions marge/merge_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def title(self):
def state(self):
return self.info['state']

@property
def merge_status(self):
return self.info['merge_status']

@property
def rebase_in_progress(self):
return self.info.get('rebase_in_progress', False)
Expand Down
2 changes: 2 additions & 0 deletions marge/single_merge_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def update_merge_request_and_accept(self, approvals):
self.wait_for_ci_to_pass(merge_request, actual_sha)
time.sleep(2)

self.wait_for_merge_status_to_resolve(merge_request)

self.ensure_mergeable_mr(merge_request)

try:
Expand Down
1 change: 1 addition & 0 deletions tests/gitlab_api_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, initial_master_sha='505e', gitlab_url=None, fork=False, merge
'assignees': [{'id': self.user_id}],
'approved_by': [],
'state': 'opened',
'merge_status': 'can_be_merged',
'sha': self.commit_info['id'],
'source_project_id': 1234,
'target_project_id': 1234,
Expand Down