Class: MergeRequests::CreateService

Inherits:
BaseService show all
Defined in:
app/services/merge_requests/create_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#create_note, #create_title_change_note, #execute_hooks, #hook_data

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/merge_requests/create_service.rb', line 3

def execute
  # @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]

  filter_params
  label_params = params[:label_ids]
  merge_request = MergeRequest.new(params.except(:label_ids))
  merge_request.source_project = source_project
  merge_request.target_project ||= source_project
  merge_request.author = current_user

  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)
    todo_service.new_merge_request(merge_request, current_user)
    merge_request.create_cross_references!(current_user)
    execute_hooks(merge_request)
  end

  merge_request
end