debian-mirror-gitlab/app/services/merge_requests/create_service.rb

51 lines
1.6 KiB
Ruby
Raw Normal View History

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]
2016-09-13 17:45:13 +05:30
merge_request = MergeRequest.new
2017-09-10 17:25:29 +05:30
merge_request.target_project = @project
2015-09-11 14:41:01 +05:30
merge_request.source_project = source_project
2017-09-10 17:25:29 +05:30
merge_request.source_branch = params[:source_branch]
2016-09-13 17:45:13 +05:30
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
2014-09-02 18:07:02 +05:30
2016-09-13 17:45:13 +05:30
create(merge_request)
end
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
def before_create(merge_request)
user = current_user
merge_request.run_after_commit do
NewMergeRequestWorker.perform_async(merge_request.id, user.id)
end
end
2016-09-13 17:45:13 +05:30
def after_create(issuable)
todo_service.new_merge_request(issuable, current_user)
2016-09-29 09:46:39 +05:30
issuable.cache_merge_request_closes_issues!(current_user)
2017-09-10 17:25:29 +05:30
update_merge_requests_head_pipeline(issuable)
end
private
def update_merge_requests_head_pipeline(merge_request)
pipeline = head_pipeline_for(merge_request)
merge_request.update(head_pipeline_id: pipeline.id) if pipeline
end
def head_pipeline_for(merge_request)
return unless merge_request.source_project
sha = merge_request.source_branch_sha
return unless sha
pipelines = merge_request.source_project.pipelines.where(ref: merge_request.source_branch, sha: sha)
pipelines.order(id: :desc).first
2014-09-02 18:07:02 +05:30
end
end
end