Show More
@@ -48,6 +48,7 class TestVcsSettings(object): | |||
|
48 | 48 | 'extensions_evolve': False, |
|
49 | 49 | 'phases_publish': 'False', |
|
50 | 50 | 'rhodecode_pr_merge_enabled': False, |
|
51 | 'rhodecode_auto_merge_enabled': False, | |
|
51 | 52 | 'rhodecode_use_outdated_comments': False, |
|
52 | 53 | 'new_svn_branch': '', |
|
53 | 54 | 'new_svn_tag': '' |
@@ -59,7 +60,7 class TestVcsSettings(object): | |||
|
59 | 60 | response = self.app.get(route_path('edit_repo_vcs', repo_name=repo_name)) |
|
60 | 61 | |
|
61 | 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 | 64 | 'hooks_changegroup_repo_size', 'hooks_changegroup_push_logger', |
|
64 | 65 | 'hooks_outgoing_pull_logger' |
|
65 | 66 | ) |
@@ -49,7 +49,7 from rhodecode.lib.plugins.utils import | |||
|
49 | 49 | from rhodecode.lib.utils2 import AttributeDict |
|
50 | 50 | from rhodecode.lib.exc_tracking import store_exception, format_exc |
|
51 | 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 | 53 | write_metadata_if_needed, write_usage_data, import_license_if_present) |
|
54 | 54 | from rhodecode.lib.statsd_client import StatsdClient |
|
55 | 55 | |
@@ -392,6 +392,7 def includeme(config, auth_resources=Non | |||
|
392 | 392 | # Add subscribers. |
|
393 | 393 | if load_all: |
|
394 | 394 | log.debug('Adding subscribers...') |
|
395 | config.add_subscriber(auto_merge_pr_if_needed, rhodecode.events.PullRequestReviewEvent) | |
|
395 | 396 | config.add_subscriber(scan_repositories_if_enabled, |
|
396 | 397 | pyramid.events.ApplicationCreated) |
|
397 | 398 | config.add_subscriber(write_metadata_if_needed, |
@@ -445,6 +445,7 class _BaseVcsSettingsForm(formencode.Sc | |||
|
445 | 445 | |
|
446 | 446 | # PR/Code-review |
|
447 | 447 | rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False) |
|
448 | rhodecode_auto_merge_enabled = v.StringBoolean(if_missing=False) | |
|
448 | 449 | rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False) |
|
449 | 450 | |
|
450 | 451 | # hg |
@@ -2125,6 +2125,10 class PullRequestModel(BaseModel): | |||
|
2125 | 2125 | return self._get_general_setting( |
|
2126 | 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 | 2132 | def _use_rebase_for_merging(self, pull_request): |
|
2129 | 2133 | repo_type = pull_request.target_repo.repo_type |
|
2130 | 2134 | if repo_type == 'hg': |
@@ -461,6 +461,7 class VcsSettingsModel(object): | |||
|
461 | 461 | GENERAL_SETTINGS = ( |
|
462 | 462 | 'use_outdated_comments', |
|
463 | 463 | 'pr_merge_enabled', |
|
464 | 'auto_merge_enabled', | |
|
464 | 465 | 'hg_use_rebase_for_merging', |
|
465 | 466 | 'hg_close_branch_before_merging', |
|
466 | 467 | 'git_use_rebase_for_merging', |
@@ -57,6 +57,34 def add_renderer_globals(event): | |||
|
57 | 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 | 88 | def set_user_lang(event): |
|
61 | 89 | request = event.request |
|
62 | 90 | cur_user = getattr(request, 'user', None) |
@@ -210,6 +210,23 | |||
|
210 | 210 | <div class="label"> |
|
211 | 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 | 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 | 230 | <div class="checkbox"> |
|
214 | 231 | ${h.checkbox('rhodecode_use_outdated_comments' + suffix, 'True', **kwargs)} |
|
215 | 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 | 39 | GENERAL_FORM_DATA = { |
|
40 | 40 | 'rhodecode_pr_merge_enabled': True, |
|
41 | 'rhodecode_auto_merge_enabled': True, | |
|
41 | 42 | 'rhodecode_use_outdated_comments': True, |
|
42 | 43 | 'rhodecode_hg_use_rebase_for_merging': True, |
|
43 | 44 | 'rhodecode_hg_close_branch_before_merging': True, |
@@ -989,6 +990,7 class TestCreateOrUpdateRepoSettings(obj | |||
|
989 | 990 | 'vcs_git_lfs_enabled': False, |
|
990 | 991 | 'phases_publish': 'False', |
|
991 | 992 | 'rhodecode_pr_merge_enabled': False, |
|
993 | 'rhodecode_auto_merge_enabled': False, | |
|
992 | 994 | 'rhodecode_use_outdated_comments': False, |
|
993 | 995 | 'new_svn_branch': '', |
|
994 | 996 | 'new_svn_tag': '' |
General Comments 0
You need to be logged in to leave comments.
Login now