##// END OF EJS Templates
feat(task-for-automatic-pr-merge): added f-ty to support pull request auto merge for EE. Fixes: RCCE-67
ilin.s -
r5657:027566d5 default
parent child Browse files
Show More
@@ -48,6 +48,7 class TestVcsSettings(object):
48 'extensions_evolve': False,
48 'extensions_evolve': False,
49 'phases_publish': 'False',
49 'phases_publish': 'False',
50 'rhodecode_pr_merge_enabled': False,
50 'rhodecode_pr_merge_enabled': False,
51 'rhodecode_auto_merge_enabled': False,
51 'rhodecode_use_outdated_comments': False,
52 'rhodecode_use_outdated_comments': False,
52 'new_svn_branch': '',
53 'new_svn_branch': '',
53 'new_svn_tag': ''
54 'new_svn_tag': ''
@@ -59,7 +60,7 class TestVcsSettings(object):
59 response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name))
60 response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name))
60
61
61 expected_settings = (
62 expected_settings = (
62 'rhodecode_use_outdated_comments', 'rhodecode_pr_merge_enabled',
63 'rhodecode_use_outdated_comments', 'rhodecode_pr_merge_enabled', 'rhodecode_auto_merge_enabled',
63 'hooks_changegroup_repo_size', 'hooks_changegroup_push_logger',
64 'hooks_changegroup_repo_size', 'hooks_changegroup_push_logger',
64 'hooks_outgoing_pull_logger'
65 'hooks_outgoing_pull_logger'
65 )
66 )
@@ -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
@@ -392,6 +392,7 def includeme(config, auth_resources=Non
392 # Add subscribers.
392 # Add subscribers.
393 if load_all:
393 if load_all:
394 log.debug('Adding subscribers...')
394 log.debug('Adding subscribers...')
395 config.add_subscriber(auto_merge_pr_if_needed, rhodecode.events.PullRequestReviewEvent)
395 config.add_subscriber(scan_repositories_if_enabled,
396 config.add_subscriber(scan_repositories_if_enabled,
396 pyramid.events.ApplicationCreated)
397 pyramid.events.ApplicationCreated)
397 config.add_subscriber(write_metadata_if_needed,
398 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
@@ -2125,6 +2125,10 class PullRequestModel(BaseModel):
2125 return self._get_general_setting(
2125 return self._get_general_setting(
2126 pull_request, 'rhodecode_pr_merge_enabled')
2126 pull_request, 'rhodecode_pr_merge_enabled')
2127
2127
2128 def is_automatic_merge_enabled(self, pull_request):
2129 return self._get_general_setting(
2130 pull_request, 'rhodecode_auto_merge_enabled')
2131
2128 def _use_rebase_for_merging(self, pull_request):
2132 def _use_rebase_for_merging(self, pull_request):
2129 repo_type = pull_request.target_repo.repo_type
2133 repo_type = pull_request.target_repo.repo_type
2130 if repo_type == 'hg':
2134 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>
@@ -38,6 +38,7 SVN_FORM_DATA = {
38
38
39 GENERAL_FORM_DATA = {
39 GENERAL_FORM_DATA = {
40 'rhodecode_pr_merge_enabled': True,
40 'rhodecode_pr_merge_enabled': True,
41 'rhodecode_auto_merge_enabled': True,
41 'rhodecode_use_outdated_comments': True,
42 'rhodecode_use_outdated_comments': True,
42 'rhodecode_hg_use_rebase_for_merging': True,
43 'rhodecode_hg_use_rebase_for_merging': True,
43 'rhodecode_hg_close_branch_before_merging': True,
44 'rhodecode_hg_close_branch_before_merging': True,
@@ -989,6 +990,7 class TestCreateOrUpdateRepoSettings(obj
989 'vcs_git_lfs_enabled': False,
990 'vcs_git_lfs_enabled': False,
990 'phases_publish': 'False',
991 'phases_publish': 'False',
991 'rhodecode_pr_merge_enabled': False,
992 'rhodecode_pr_merge_enabled': False,
993 'rhodecode_auto_merge_enabled': False,
992 'rhodecode_use_outdated_comments': False,
994 'rhodecode_use_outdated_comments': False,
993 'new_svn_branch': '',
995 'new_svn_branch': '',
994 'new_svn_tag': ''
996 'new_svn_tag': ''
General Comments 0
You need to be logged in to leave comments. Login now