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]
|
|
|
|
|
2016-06-30 11:34:19 -04:00
|
|
|
params[:target_project_id] ||= source_project.id
|
2016-02-12 15:41:31 -05:00
|
|
|
|
2016-06-30 11:34:19 -04:00
|
|
|
merge_request = MergeRequest.new
|
2015-08-21 12:47:39 -04:00
|
|
|
merge_request.source_project = source_project
|
2016-06-30 11:34:19 -04:00
|
|
|
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
|
2014-04-02 14:51:17 -04:00
|
|
|
|
2016-06-30 11:34:19 -04:00
|
|
|
create(merge_request)
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
def after_create(issuable)
|
2016-06-30 11:34:19 -04:00
|
|
|
event_service.open_mr(issuable, current_user)
|
|
|
|
notification_service.new_merge_request(issuable, current_user)
|
|
|
|
todo_service.new_merge_request(issuable, current_user)
|
2016-09-20 15:52:20 -04:00
|
|
|
issuable.cache_merge_request_closes_issues!(current_user)
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|