##// END OF EJS Templates
added latest changes
ilin.s -
r5658:a109f5ac merge default
parent child Browse files
Show More
@@ -47,6 +47,7 class TestVcsSettings(object):
47 'extensions_evolve': False,
47 'extensions_evolve': False,
48 'phases_publish': 'False',
48 'phases_publish': 'False',
49 'rhodecode_pr_merge_enabled': False,
49 'rhodecode_pr_merge_enabled': False,
50 'rhodecode_auto_merge_enabled': False,
50 'rhodecode_use_outdated_comments': False,
51 'rhodecode_use_outdated_comments': False,
51 'new_svn_branch': '',
52 'new_svn_branch': '',
52 'new_svn_tag': ''
53 'new_svn_tag': ''
@@ -58,7 +59,7 class TestVcsSettings(object):
58 response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name))
59 response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name))
59
60
60 expected_settings = (
61 expected_settings = (
61 'rhodecode_use_outdated_comments', 'rhodecode_pr_merge_enabled',
62 'rhodecode_use_outdated_comments', 'rhodecode_pr_merge_enabled', 'rhodecode_auto_merge_enabled',
62 'hooks_changegroup_repo_size', 'hooks_changegroup_push_logger',
63 'hooks_changegroup_repo_size', 'hooks_changegroup_push_logger',
63 'hooks_outgoing_pull_logger'
64 'hooks_outgoing_pull_logger'
64 )
65 )
@@ -49,7 +49,7 from rhodecode.lib.plugins.utils import
49 from rhodecode.lib.utils2 import AttributeDict
49 from rhodecode.lib.utils2 import AttributeDict
50 from rhodecode.lib.exc_tracking import store_exception, format_exc
50 from rhodecode.lib.exc_tracking import store_exception, format_exc
51 from rhodecode.subscribers import (
51 from rhodecode.subscribers import (
52 scan_repositories_if_enabled, write_js_routes_if_enabled,
52 auto_merge_pr_if_needed, scan_repositories_if_enabled, write_js_routes_if_enabled,
53 write_metadata_if_needed, write_usage_data, import_license_if_present)
53 write_metadata_if_needed, write_usage_data, import_license_if_present)
54 from rhodecode.lib.statsd_client import StatsdClient
54 from rhodecode.lib.statsd_client import StatsdClient
55
55
@@ -395,6 +395,7 def includeme(config, auth_resources=Non
395 # Add subscribers.
395 # Add subscribers.
396 if load_all:
396 if load_all:
397 log.debug('Adding subscribers...')
397 log.debug('Adding subscribers...')
398 config.add_subscriber(auto_merge_pr_if_needed, rhodecode.events.PullRequestReviewEvent)
398 config.add_subscriber(scan_repositories_if_enabled,
399 config.add_subscriber(scan_repositories_if_enabled,
399 pyramid.events.ApplicationCreated)
400 pyramid.events.ApplicationCreated)
400 config.add_subscriber(write_metadata_if_needed,
401 config.add_subscriber(write_metadata_if_needed,
@@ -445,6 +445,7 class _BaseVcsSettingsForm(formencode.Sc
445
445
446 # PR/Code-review
446 # PR/Code-review
447 rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False)
447 rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False)
448 rhodecode_auto_merge_enabled = v.StringBoolean(if_missing=False)
448 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
449 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
449
450
450 # hg
451 # hg
@@ -2124,6 +2124,10 class PullRequestModel(BaseModel):
2124 return self._get_general_setting(
2124 return self._get_general_setting(
2125 pull_request, 'rhodecode_pr_merge_enabled')
2125 pull_request, 'rhodecode_pr_merge_enabled')
2126
2126
2127 def is_automatic_merge_enabled(self, pull_request):
2128 return self._get_general_setting(
2129 pull_request, 'rhodecode_auto_merge_enabled')
2130
2127 def _use_rebase_for_merging(self, pull_request):
2131 def _use_rebase_for_merging(self, pull_request):
2128 repo_type = pull_request.target_repo.repo_type
2132 repo_type = pull_request.target_repo.repo_type
2129 if repo_type == 'hg':
2133 if repo_type == 'hg':
@@ -461,6 +461,7 class VcsSettingsModel(object):
461 GENERAL_SETTINGS = (
461 GENERAL_SETTINGS = (
462 'use_outdated_comments',
462 'use_outdated_comments',
463 'pr_merge_enabled',
463 'pr_merge_enabled',
464 'auto_merge_enabled',
464 'hg_use_rebase_for_merging',
465 'hg_use_rebase_for_merging',
465 'hg_close_branch_before_merging',
466 'hg_close_branch_before_merging',
466 'git_use_rebase_for_merging',
467 'git_use_rebase_for_merging',
@@ -57,6 +57,34 def add_renderer_globals(event):
57 event['h'] = helpers
57 event['h'] = helpers
58
58
59
59
60 def auto_merge_pr_if_needed(event):
61 from rhodecode.model.db import PullRequest
62 from rhodecode.model.pull_request import (
63 PullRequestModel, ChangesetStatus, MergeCheck
64 )
65
66 pr_event_data = event.as_dict()['pullrequest']
67 pull_request = PullRequest.get(pr_event_data['pull_request_id'])
68 calculated_status = pr_event_data['status']
69 if (calculated_status == ChangesetStatus.STATUS_APPROVED
70 and PullRequestModel().is_automatic_merge_enabled(pull_request)):
71 user = pull_request.author.AuthUser()
72
73 merge_check = MergeCheck.validate(
74 pull_request, user, translator=lambda x: x, fail_early=True
75 )
76 if merge_check.merge_possible:
77 from rhodecode.lib.base import vcs_operation_context
78 extras = vcs_operation_context(
79 event.request.environ, repo_name=pull_request.target_repo.repo_name,
80 username=user.username, action='push',
81 scm=pull_request.target_repo.repo_type)
82 from rc_ee.lib.celerylib.tasks import auto_merge_repo
83 auto_merge_repo.apply_async(
84 args=(pull_request.pull_request_id, extras)
85 )
86
87
60 def set_user_lang(event):
88 def set_user_lang(event):
61 request = event.request
89 request = event.request
62 cur_user = getattr(request, 'user', None)
90 cur_user = getattr(request, 'user', None)
@@ -210,6 +210,23
210 <div class="label">
210 <div class="label">
211 <span class="help-block">${_('Note: when this feature is enabled, it only runs hooks defined in the rcextension package. Custom hooks added on the Admin -> Settings -> Hooks page will not be run when pull requests are automatically merged from the web interface.')}</span>
211 <span class="help-block">${_('Note: when this feature is enabled, it only runs hooks defined in the rcextension package. Custom hooks added on the Admin -> Settings -> Hooks page will not be run when pull requests are automatically merged from the web interface.')}</span>
212 </div>
212 </div>
213 %if c.rhodecode_edition_id != 'EE':
214 <div class="checkbox">
215 <input type="checkbox" disabled>
216 <label for="rhodecode_auto_merge_enabled${suffix}">${_('Enable automatic merge for approved pull requests')}</label>
217 </div>
218 <div class="label">
219 <span class="help-block">${_('This feature is available in RhodeCode EE edition only. Contact {sales_email} to obtain a trial license.').format(sales_email='<a href="mailto:sales@rhodecode.com">sales@rhodecode.com</a>')|n}</span>
220 <div>
221 %else:
222 <div class="checkbox">
223 ${h.checkbox('rhodecode_auto_merge_enabled' + suffix, 'True', **kwargs)}
224 <label for="rhodecode_auto_merge_enabled${suffix}">${_('Enable automatic merge for approved pull requests')}</label>
225 </div>
226 <div class="label">
227 <span class="help-block">${_('When this is enabled, the pull request will be merged once it has at least one reviewer and is approved.')}</span>
228 </div>
229 %endif
213 <div class="checkbox">
230 <div class="checkbox">
214 ${h.checkbox('rhodecode_use_outdated_comments' + suffix, 'True', **kwargs)}
231 ${h.checkbox('rhodecode_use_outdated_comments' + suffix, 'True', **kwargs)}
215 <label for="rhodecode_use_outdated_comments${suffix}">${_('Invalidate and relocate inline comments during update')}</label>
232 <label for="rhodecode_use_outdated_comments${suffix}">${_('Invalidate and relocate inline comments during update')}</label>
@@ -37,6 +37,7 SVN_FORM_DATA = {
37
37
38 GENERAL_FORM_DATA = {
38 GENERAL_FORM_DATA = {
39 'rhodecode_pr_merge_enabled': True,
39 'rhodecode_pr_merge_enabled': True,
40 'rhodecode_auto_merge_enabled': True,
40 'rhodecode_use_outdated_comments': True,
41 'rhodecode_use_outdated_comments': True,
41 'rhodecode_hg_use_rebase_for_merging': True,
42 'rhodecode_hg_use_rebase_for_merging': True,
42 'rhodecode_hg_close_branch_before_merging': True,
43 'rhodecode_hg_close_branch_before_merging': True,
@@ -988,6 +989,7 class TestCreateOrUpdateRepoSettings(obj
988 'vcs_git_lfs_enabled': False,
989 'vcs_git_lfs_enabled': False,
989 'phases_publish': 'False',
990 'phases_publish': 'False',
990 'rhodecode_pr_merge_enabled': False,
991 'rhodecode_pr_merge_enabled': False,
992 'rhodecode_auto_merge_enabled': False,
991 'rhodecode_use_outdated_comments': False,
993 'rhodecode_use_outdated_comments': False,
992 'new_svn_branch': '',
994 'new_svn_branch': '',
993 'new_svn_tag': ''
995 'new_svn_tag': ''
General Comments 0
You need to be logged in to leave comments. Login now