2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module MergeRequests
|
|
|
|
class CreateService < MergeRequests::BaseService
|
|
|
|
def execute
|
2018-03-17 18:26:18 +05:30
|
|
|
set_projects!
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
merge_request = MergeRequest.new
|
2017-09-10 17:25:29 +05:30
|
|
|
merge_request.target_project = @project
|
2018-03-17 18:26:18 +05:30
|
|
|
merge_request.source_project = @source_project
|
2017-09-10 17:25:29 +05:30
|
|
|
merge_request.source_branch = params[:source_branch]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
create(merge_request)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def before_create(merge_request)
|
2018-03-17 18:26:18 +05:30
|
|
|
# current_user (defined in BaseService) is not available within run_after_commit block
|
2017-09-10 17:25:29 +05:30
|
|
|
user = current_user
|
|
|
|
merge_request.run_after_commit do
|
|
|
|
NewMergeRequestWorker.perform_async(merge_request.id, user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
def after_create(issuable)
|
|
|
|
todo_service.new_merge_request(issuable, current_user)
|
2016-09-29 09:46:39 +05:30
|
|
|
issuable.cache_merge_request_closes_issues!(current_user)
|
2019-07-07 11:18:12 +05:30
|
|
|
create_pipeline_for(issuable, current_user)
|
2019-02-15 15:39:39 +05:30
|
|
|
issuable.update_head_pipeline
|
2019-12-04 20:38:33 +05:30
|
|
|
Gitlab::UsageDataCounters::MergeRequestCounter.count(:create)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
# expose issuable create method so it can be called from email
|
|
|
|
# handler CreateMergeRequestHandler
|
|
|
|
def create(merge_request)
|
|
|
|
super
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
# Override from IssuableBaseService
|
|
|
|
def handle_quick_actions_on_create(merge_request)
|
|
|
|
super
|
|
|
|
handle_wip_event(merge_request)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
private
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def set_projects!
|
|
|
|
# @project is used to determine whether the user can set the merge request's
|
|
|
|
# assignee, milestone and labels. Whether they can depends on their
|
|
|
|
# permissions on the target project.
|
|
|
|
@source_project = @project
|
|
|
|
@project = Project.find(params[:target_project_id]) if params[:target_project_id]
|
|
|
|
|
|
|
|
# make sure that source/target project ids are not in
|
|
|
|
# params so it can't be overridden later when updating attributes
|
|
|
|
# from params when applying quick actions
|
|
|
|
params.delete(:source_project_id)
|
|
|
|
params.delete(:target_project_id)
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
unless can?(current_user, :create_merge_request_from, @source_project) &&
|
|
|
|
can?(current_user, :create_merge_request_in, @project)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
MergeRequests::CreateService.include_if_ee('EE::MergeRequests::CreateService')
|