# HG changeset patch # User Marcin Kuzminski # Date 2019-04-09 11:12:26 # Node ID cff84552b4a340deee8eac9c56380c821a7c94c6 # Parent 30cddb613ff37d35ffaff05f5de5b5c1ee4d4ba6 pull-requests: updated metadata information for failed merges with multiple heads. diff --git a/rhodecode/lib/hooks_utils.py b/rhodecode/lib/hooks_utils.py --- a/rhodecode/lib/hooks_utils.py +++ b/rhodecode/lib/hooks_utils.py @@ -80,7 +80,7 @@ def trigger_log_create_pull_request_hook 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) diff --git a/rhodecode/lib/vcs/backends/base.py b/rhodecode/lib/vcs/backends/base.py --- a/rhodecode/lib/vcs/backends/base.py +++ b/rhodecode/lib/vcs/backends/base.py @@ -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) diff --git a/rhodecode/lib/vcs/backends/hg/repository.py b/rhodecode/lib/vcs/backends/hg/repository.py --- a/rhodecode/lib/vcs/backends/hg/repository.py +++ b/rhodecode/lib/vcs/backends/hg/repository.py @@ -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( diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -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) diff --git a/rhodecode/tests/models/test_pullrequest.py b/rhodecode/tests/models/test_pullrequest.py --- a/rhodecode/tests/models/test_pullrequest.py +++ b/rhodecode/tests/models/test_pullrequest.py @@ -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,