diff options
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r-- | app/services/merge_requests/base_service.rb | 12 | ||||
-rw-r--r-- | app/services/merge_requests/rebase_service.rb | 21 | ||||
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 4 | ||||
-rw-r--r-- | app/services/merge_requests/update_service.rb | 2 |
4 files changed, 32 insertions, 7 deletions
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index 468cadb03c7..f6cbe889128 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -94,6 +94,10 @@ module MergeRequests private + def refresh_pipelines_on_merge_requests(merge_request, allow_duplicate: false) + create_pipeline_for(merge_request, current_user, async: true, allow_duplicate: allow_duplicate) + end + def enqueue_jira_connect_messages_for(merge_request) return unless project.jira_subscription_exists? @@ -184,16 +188,18 @@ module MergeRequests merge_request, merge_request.project, current_user, old_reviewers) end - def create_pipeline_for(merge_request, user, async: false) + def create_pipeline_for(merge_request, user, async: false, allow_duplicate: false) + create_pipeline_params = params.slice(:push_options).merge(allow_duplicate: allow_duplicate) + if async MergeRequests::CreatePipelineWorker.perform_async( project.id, user.id, merge_request.id, - params.slice(:push_options).deep_stringify_keys) + create_pipeline_params.deep_stringify_keys) else MergeRequests::CreatePipelineService - .new(project: project, current_user: user, params: params.slice(:push_options)) + .new(project: project, current_user: user, params: create_pipeline_params) .execute(merge_request) end end diff --git a/app/services/merge_requests/rebase_service.rb b/app/services/merge_requests/rebase_service.rb index 1c4e1784b34..792f1728b88 100644 --- a/app/services/merge_requests/rebase_service.rb +++ b/app/services/merge_requests/rebase_service.rb @@ -6,6 +6,19 @@ module MergeRequests attr_reader :merge_request, :rebase_error + def validate(merge_request) + return error_response(_('Source branch does not exist')) unless + merge_request.source_branch_exists? + + return error_response(_('Cannot push to source branch')) unless + user_access.can_push_to_branch?(merge_request.source_branch) + + return error_response(_('Source branch is protected from force push')) unless + merge_request.permits_force_push? + + ServiceResponse.success + end + def execute(merge_request, skip_ci: false) @merge_request = merge_request @skip_ci = skip_ci @@ -40,5 +53,13 @@ module MergeRequests REBASE_ERROR end end + + def user_access + Gitlab::UserAccess.new(current_user, container: project) + end + + def error_response(message) + ServiceResponse.error(message: message) + end end end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index 533d0052fb8..ce49d5dd43c 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -162,10 +162,6 @@ module MergeRequests @outdate_service ||= Suggestions::OutdateService.new end - def refresh_pipelines_on_merge_requests(merge_request) - create_pipeline_for(merge_request, current_user, async: true) - end - def abort_auto_merges(merge_request) abort_auto_merge(merge_request, 'source branch was updated') end diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb index 745647b727c..a273b853c0d 100644 --- a/app/services/merge_requests/update_service.rb +++ b/app/services/merge_requests/update_service.rb @@ -169,6 +169,8 @@ module MergeRequests merge_request.target_branch ) + refresh_pipelines_on_merge_requests(merge_request, allow_duplicate: true) + abort_auto_merge(merge_request, 'target branch was changed') end |