pull-requests: updated metadata information for failed merges with multiple heads.

This commit is contained in:
Marcin Kuzminski 2019-04-09 13:12:26 +02:00
parent d693a556b4
commit 0215f5278c
5 changed files with 22 additions and 6 deletions

View file

@ -80,7 +80,7 @@ def trigger_log_create_pull_request_hook(username, repo_name, repo_alias,
extras = _get_rc_scm_extras(username, repo_name, repo_alias,
'create_pull_request')
events.trigger(events.PullRequestCreateEvent(pull_request))
extras.update(pull_request.get_api_data())
extras.update(pull_request.get_api_data(with_merge_state=False))
hooks_base.log_create_pull_request(**extras)

View file

@ -161,7 +161,7 @@ class MergeResponse(object):
u'This pull request cannot be merged because the source contains '
u'more branches than the target.'),
MergeFailureReason.HG_TARGET_HAS_MULTIPLE_HEADS: lazy_ugettext(
u'This pull request cannot be merged because the target '
u'This pull request cannot be merged because the target `{target_ref.name}` '
u'has multiple heads: `{heads}`.'),
MergeFailureReason.TARGET_IS_LOCKED: lazy_ugettext(
u'This pull request cannot be merged because the target repository is '
@ -309,6 +309,9 @@ class BaseRepository(object):
def _remote(self):
raise NotImplementedError
def _heads(self, branch=None):
return []
@LazyProperty
def EMPTY_COMMIT(self):
return EmptyCommit(self.EMPTY_COMMIT_ID)

View file

@ -715,11 +715,16 @@ class MercurialRepository(BaseRepository):
try:
if target_ref.type == 'branch' and len(self._heads(target_ref.name)) != 1:
heads = ','.join(self._heads(target_ref.name))
heads = '\n,'.join(self._heads(target_ref.name))
metadata = {
'target_ref': target_ref,
'source_ref': source_ref,
'heads': heads
}
return MergeResponse(
False, False, None,
MergeFailureReason.HG_TARGET_HAS_MULTIPLE_HEADS,
metadata={'heads': heads})
metadata=metadata)
except CommitDoesNotExistError:
log.exception('Failure when looking up branch heads on hg target')
return MergeResponse(

View file

@ -1317,8 +1317,16 @@ class PullRequestModel(BaseModel):
possible = pull_request.last_merge_status == MergeFailureReason.NONE
metadata = {
'target_ref': pull_request.target_ref_parts,
'source_ref': pull_request.source_ref_parts
'source_ref': pull_request.source_ref_parts,
}
if not possible and target_ref.type == 'branch':
# NOTE(marcink): case for mercurial multiple heads on branch
heads = target_vcs._heads(target_ref.name)
if len(heads) != 1:
heads = '\n,'.join(target_vcs._heads(target_ref.name))
metadata.update({
'heads': heads
})
merge_state = MergeResponse(
possible, False, None, pull_request.last_merge_status, metadata=metadata)

View file

@ -512,7 +512,7 @@ def test_outdated_comments(
(MergeFailureReason.HG_SOURCE_HAS_MORE_BRANCHES,
'This pull request cannot be merged because the source contains more branches than the target.'),
(MergeFailureReason.HG_TARGET_HAS_MULTIPLE_HEADS,
'This pull request cannot be merged because the target has multiple heads: `a,b,c`.'),
'This pull request cannot be merged because the target `ref_name` has multiple heads: `a,b,c`.'),
(MergeFailureReason.TARGET_IS_LOCKED,
'This pull request cannot be merged because the target repository is locked by user:123.'),
(MergeFailureReason.MISSING_TARGET_REF,