# HG changeset patch # User Marcin Kuzminski # Date 2018-10-01 11:54:51 # Node ID dcaa9d6757edb9798d5ff37df7db495de5c065c9 # Parent 12ce4f25da270f9a455ad58255af35d5d51d81d0 vcs: use a real two part name for merge operation. - expose settings into vcs_settings for easier override later 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 @@ -485,9 +485,9 @@ class BaseRepository(object): :param close_branch: If `True` branch will be close before merging it """ if dry_run: - message = message or 'dry_run_merge_message' - user_email = user_email or 'dry-run-merge@rhodecode.com' - user_name = user_name or 'Dry-Run User' + message = message or settings.MERGE_DRY_RUN_MESSAGE + user_email = user_email or settings.MERGE_DRY_RUN_EMAIL + user_name = user_name or settings.MERGE_DRY_RUN_USER else: if not user_name: raise ValueError('user_name cannot be empty') diff --git a/rhodecode/lib/vcs/conf/settings.py b/rhodecode/lib/vcs/conf/settings.py --- a/rhodecode/lib/vcs/conf/settings.py +++ b/rhodecode/lib/vcs/conf/settings.py @@ -54,6 +54,14 @@ HOOKS_DIRECT_CALLS = False HOOKS_HOST = '127.0.0.1' +MERGE_MESSAGE_TMPL = ( + u'Merge pull request #{pr_id} from {source_repo} {source_ref_name}\n\n ' + u'{pr_title}') +MERGE_DRY_RUN_MESSAGE = 'dry_run_merge_message_from_rhodecode' +MERGE_DRY_RUN_USER = 'Dry-Run User' +MERGE_DRY_RUN_EMAIL = 'dry-run-merge@rhodecode.com' + + def available_aliases(): """ Mercurial is required for the system to work, so in case vcs.backends does 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 @@ -608,23 +608,24 @@ class PullRequestModel(BaseModel): def _merge_pull_request(self, pull_request, user, extras, merge_msg=None): target_vcs = pull_request.target_repo.scm_instance() source_vcs = pull_request.source_repo.scm_instance() - target_ref = self._refresh_reference( - pull_request.target_ref_parts, target_vcs) - message = merge_msg or ( - 'Merge pull request #%(pr_id)s from ' - '%(source_repo)s %(source_ref_name)s\n\n %(pr_title)s') % { - 'pr_id': pull_request.pull_request_id, - 'source_repo': source_vcs.name, - 'source_ref_name': pull_request.source_ref_parts.name, - 'pr_title': pull_request.title - } + message = safe_unicode(merge_msg or vcs_settings.MERGE_MESSAGE_TMPL).format( + pr_id=pull_request.pull_request_id, + pr_title=pull_request.title, + source_repo=source_vcs.name, + source_ref_name=pull_request.source_ref_parts.name, + target_repo=target_vcs.name, + target_ref_name=pull_request.target_ref_parts.name, + ) workspace_id = self._workspace_id(pull_request) repo_id = pull_request.target_repo.repo_id use_rebase = self._use_rebase_for_merging(pull_request) close_branch = self._close_branch_before_merging(pull_request) + target_ref = self._refresh_reference( + pull_request.target_ref_parts, target_vcs) + callback_daemon, extras = prepare_callback_daemon( extras, protocol=vcs_settings.HOOKS_PROTOCOL, host=vcs_settings.HOOKS_HOST, @@ -635,10 +636,12 @@ class PullRequestModel(BaseModel): # for a single call. target_vcs.config.set( 'rhodecode', 'RC_SCM_DATA', json.dumps(extras)) + + user_name = user.short_contact merge_state = target_vcs.merge( repo_id, workspace_id, target_ref, source_vcs, pull_request.source_ref_parts, - user_name=user.username, user_email=user.email, + user_name=user_name, user_email=user.email, message=message, use_rebase=use_rebase, close_branch=close_branch) return merge_state 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 @@ -305,7 +305,7 @@ class TestPullRequestModel(object): pull_request.target_ref_parts, pull_request.source_repo.scm_instance(), pull_request.source_ref_parts, - user_name=user.username, user_email=user.email, message=message, + user_name=user.short_contact, user_email=user.email, message=message, use_rebase=False, close_branch=False ) self.invalidation_mock.assert_called_once_with( @@ -345,7 +345,7 @@ class TestPullRequestModel(object): pull_request.target_ref_parts, pull_request.source_repo.scm_instance(), pull_request.source_ref_parts, - user_name=user.username, user_email=user.email, message=message, + user_name=user.short_contact, user_email=user.email, message=message, use_rebase=False, close_branch=False )