2014-04-03 03:36:10 -04:00
|
|
|
module MergeRequests
|
2014-04-02 14:51:17 -04:00
|
|
|
class CreateService < MergeRequests::BaseService
|
|
|
|
def execute
|
2015-08-21 12:47:39 -04:00
|
|
|
# @project is used to determine whether the user can set the merge request's
|
2016-02-16 18:01:14 -05:00
|
|
|
# assignee, milestone and labels. Whether they can depends on their
|
2015-08-21 12:47:39 -04:00
|
|
|
# permissions on the target project.
|
|
|
|
source_project = @project
|
|
|
|
@project = Project.find(params[:target_project_id]) if params[:target_project_id]
|
|
|
|
|
2015-06-25 10:17:48 -04:00
|
|
|
filter_params
|
2016-02-12 15:41:31 -05:00
|
|
|
label_params = params.delete(:label_ids)
|
|
|
|
force_remove_source_branch = params.delete(:force_remove_source_branch)
|
|
|
|
|
|
|
|
merge_request = MergeRequest.new(params)
|
2015-08-21 12:47:39 -04:00
|
|
|
merge_request.source_project = source_project
|
|
|
|
merge_request.target_project ||= source_project
|
2014-04-02 14:51:17 -04:00
|
|
|
merge_request.author = current_user
|
2016-02-12 15:41:31 -05:00
|
|
|
merge_request.merge_params['force_remove_source_branch'] = force_remove_source_branch
|
2014-04-02 14:51:17 -04:00
|
|
|
|
|
|
|
if merge_request.save
|
2014-07-30 15:48:21 -04:00
|
|
|
merge_request.update_attributes(label_ids: label_params)
|
2014-04-02 14:51:17 -04:00
|
|
|
event_service.open_mr(merge_request, current_user)
|
|
|
|
notification_service.new_merge_request(merge_request, current_user)
|
2016-02-20 08:59:59 -05:00
|
|
|
todo_service.new_merge_request(merge_request, current_user)
|
2015-10-12 05:54:46 -04:00
|
|
|
merge_request.create_cross_references!(current_user)
|
2014-04-02 14:51:17 -04:00
|
|
|
execute_hooks(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
merge_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|