merge_request_observer.rb 1.14 KB
Newer Older
1 2 3 4 5
class MergeRequestObserver < ActiveRecord::Observer
  cattr_accessor :current_user

  def after_create(merge_request)
    if merge_request.assignee && merge_request.assignee != current_user
6
      Notify.delay.new_merge_request_email(merge_request.id)
7 8 9
    end
  end

10
  def after_close(merge_request, transition)
11 12
    send_reassigned_email(merge_request) if merge_request.is_being_reassigned?

13 14 15 16 17 18 19 20 21 22 23
    Note.create_status_change_note(merge_request, current_user, merge_request.state)
  end

  def after_reopen(merge_request, transition)
    send_reassigned_email(merge_request) if merge_request.is_being_reassigned?

    Note.create_status_change_note(merge_request, current_user, merge_request.state)
  end

  def after_update(merge_request)
    send_reassigned_email(merge_request) if merge_request.is_being_reassigned?
24 25 26 27 28
  end

  protected

  def send_reassigned_email(merge_request)
29 30
    recipients_ids = merge_request.assignee_id_was, merge_request.assignee_id
    recipients_ids.delete current_user.id
31

32
    recipients_ids.each do |recipient_id|
33
      Notify.delay.reassigned_merge_request_email(recipient_id, merge_request.id, merge_request.assignee_id_was)
34
    end
35 36
  end
end