2014-09-02 18:07:02 +05:30
|
|
|
module MergeRequests
|
|
|
|
class CreateService < MergeRequests::BaseService
|
|
|
|
def execute
|
2015-09-11 14:41:01 +05:30
|
|
|
# @project is used to determine whether the user can set the merge request's
|
2016-04-02 18:10:28 +05:30
|
|
|
# assignee, milestone and labels. Whether they can depends on their
|
2015-09-11 14:41:01 +05:30
|
|
|
# permissions on the target project.
|
|
|
|
source_project = @project
|
|
|
|
@project = Project.find(params[:target_project_id]) if params[:target_project_id]
|
|
|
|
|
|
|
|
filter_params
|
2016-06-02 11:05:42 +05:30
|
|
|
label_params = params.delete(:label_ids)
|
|
|
|
force_remove_source_branch = params.delete(:force_remove_source_branch)
|
|
|
|
|
|
|
|
merge_request = MergeRequest.new(params)
|
2015-09-11 14:41:01 +05:30
|
|
|
merge_request.source_project = source_project
|
|
|
|
merge_request.target_project ||= source_project
|
2014-09-02 18:07:02 +05:30
|
|
|
merge_request.author = current_user
|
2016-06-02 11:05:42 +05:30
|
|
|
merge_request.merge_params['force_remove_source_branch'] = force_remove_source_branch
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
if merge_request.save
|
|
|
|
merge_request.update_attributes(label_ids: label_params)
|
|
|
|
event_service.open_mr(merge_request, current_user)
|
|
|
|
notification_service.new_merge_request(merge_request, current_user)
|
2016-04-02 18:10:28 +05:30
|
|
|
todo_service.new_merge_request(merge_request, current_user)
|
2015-10-24 18:46:33 +05:30
|
|
|
merge_request.create_cross_references!(current_user)
|
2014-09-02 18:07:02 +05:30
|
|
|
execute_hooks(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
merge_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|