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
|
|
|
|
# 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]
|
|
|
|
|
2015-06-25 10:17:48 -04:00
|
|
|
filter_params
|
2014-07-30 15:48:21 -04:00
|
|
|
label_params = params[:label_ids]
|
|
|
|
merge_request = MergeRequest.new(params.except(:label_ids))
|
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
|
|
|
|
|
|
|
|
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)
|
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
|