2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-03 03:36:10 -04:00
|
|
|
module MergeRequests
|
2014-04-02 14:51:17 -04:00
|
|
|
class CreateService < MergeRequests::BaseService
|
|
|
|
def execute
|
2018-01-05 12:55:37 -05:00
|
|
|
set_projects!
|
2015-08-21 12:47:39 -04:00
|
|
|
|
2016-06-30 11:34:19 -04:00
|
|
|
merge_request = MergeRequest.new
|
2017-07-12 04:45:40 -04:00
|
|
|
merge_request.target_project = @project
|
2018-01-05 12:55:37 -05:00
|
|
|
merge_request.source_project = @source_project
|
2017-05-25 17:14:40 -04:00
|
|
|
merge_request.source_branch = params[:source_branch]
|
2014-04-02 14:51:17 -04:00
|
|
|
|
2018-02-07 06:04:49 -05:00
|
|
|
create(merge_request)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
|
2017-08-01 08:38:45 -04:00
|
|
|
def before_create(merge_request)
|
2017-08-08 03:41:27 -04:00
|
|
|
# current_user (defined in BaseService) is not available within run_after_commit block
|
2017-08-01 08:38:45 -04:00
|
|
|
user = current_user
|
|
|
|
merge_request.run_after_commit do
|
|
|
|
NewMergeRequestWorker.perform_async(merge_request.id, user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
def after_create(issuable)
|
2016-06-30 11:34:19 -04:00
|
|
|
todo_service.new_merge_request(issuable, current_user)
|
2016-09-20 15:52:20 -04:00
|
|
|
issuable.cache_merge_request_closes_issues!(current_user)
|
2019-03-21 09:08:32 -04:00
|
|
|
create_pipeline_for(issuable, current_user)
|
2019-01-02 01:39:45 -05:00
|
|
|
issuable.update_head_pipeline
|
2019-08-26 10:30:45 -04:00
|
|
|
Gitlab::UsageDataCounters::MergeRequestCounter.count(:create)
|
2017-08-17 11:21:25 -04:00
|
|
|
|
|
|
|
super
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
2017-05-25 17:14:40 -04:00
|
|
|
|
2017-08-24 02:20:36 -04:00
|
|
|
# expose issuable create method so it can be called from email
|
|
|
|
# handler CreateMergeRequestHandler
|
|
|
|
def create(merge_request)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-03-01 09:32:39 -05:00
|
|
|
# Override from IssuableBaseService
|
2018-03-05 08:24:18 -05:00
|
|
|
def handle_quick_actions_on_create(merge_request)
|
2018-03-01 09:32:39 -05:00
|
|
|
super
|
|
|
|
handle_wip_event(merge_request)
|
|
|
|
end
|
|
|
|
|
2017-05-25 17:14:40 -04:00
|
|
|
private
|
|
|
|
|
2018-01-05 12:55:37 -05:00
|
|
|
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-04-06 08:18:58 -04:00
|
|
|
unless can?(current_user, :create_merge_request_from, @source_project) &&
|
|
|
|
can?(current_user, :create_merge_request_in, @project)
|
2018-01-05 12:55:37 -05:00
|
|
|
|
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
MergeRequests::CreateService.include_if_ee('EE::MergeRequests::CreateService')
|