Read about our upcoming Code of Conduct on this issue

update_service.rb 1.27 KB
Newer Older
1
2
3
4
require_relative 'base_service'
require_relative 'reopen_service'
require_relative 'close_service'

5
6
7
8
9
module MergeRequests
  class UpdateService < MergeRequests::BaseService
    def execute(merge_request)
      # We dont allow change of source/target projects
      # after merge request was created
10
11
      params.except!(:source_project_id)
      params.except!(:target_project_id)
12

13
      state = params[:state_event]
14
15
16
17
18
19
20
21

      case state
      when 'reopen'
        MergeRequests::ReopenService.new(project, current_user, {}).execute(merge_request)
      when 'close'
        MergeRequests::CloseService.new(project, current_user, {}).execute(merge_request)
      end

22
      if params.present? && merge_request.update_attributes(params.except(:state_event))
23
24
        merge_request.reset_events_cache

25
26
27
28
        if merge_request.previous_changes.include?('milestone_id')
          create_milestone_note(merge_request)
        end

29
30
31
32
33
34
35
36
37
38
39
40
41
        if merge_request.previous_changes.include?('assignee_id')
          notification_service.reassigned_merge_request(merge_request, current_user)
          create_assignee_note(merge_request)
        end

        merge_request.notice_added_references(merge_request.project, current_user)
        execute_hooks(merge_request)
      end

      merge_request
    end
  end
end