BigW Consortium Gitlab

merge_request_observer.rb 1.44 KB
Newer Older
Dmitriy Zaporozhets committed
1
class MergeRequestObserver < BaseObserver
2
  def after_create(merge_request)
3
    event_service.open_mr(merge_request, current_user)
4
    notification.new_merge_request(merge_request, current_user)
5
    merge_request.create_cross_references!(merge_request.project, current_user)
6
    execute_hooks(merge_request)
7 8
  end

9
  def after_close(merge_request, transition)
10
    event_service.close_mr(merge_request, current_user)
11
    notification.close_mr(merge_request, current_user)
12 13
    create_note(merge_request)
    execute_hooks(merge_request)
14 15
  end

16
  def after_reopen(merge_request, transition)
17
    event_service.reopen_mr(merge_request, current_user)
18
    create_note(merge_request)
19
    execute_hooks(merge_request)
20 21
    merge_request.reload_code
    merge_request.mark_as_unchecked
22 23 24
  end

  def after_update(merge_request)
tsl0922 committed
25
    notification.reassigned_merge_request(merge_request, current_user) if merge_request.is_being_reassigned?
26 27

    merge_request.notice_added_references(merge_request.project, current_user)
28
    execute_hooks(merge_request)
29
  end
30

31 32 33 34 35 36 37 38
  private

  # Create merge request note with service comment like 'Status changed to closed'
  def create_note(merge_request)
    Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
  end

  def execute_hooks(merge_request)
39 40 41
    if merge_request.project
      merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks)
    end
42
  end
43
end