BigW Consortium Gitlab

merge_requests.rb 3.14 KB
Newer Older
1 2
module Emails
  module MergeRequests
3
    def new_merge_request_email(recipient_id, merge_request_id)
4 5
      setup_merge_request_mail(merge_request_id, recipient_id)

6
      mail_new_thread(@merge_request, merge_request_thread_options(@merge_request.author_id, recipient_id))
7 8
    end

9 10 11 12 13
    def new_mention_in_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
      setup_merge_request_mail(merge_request_id, recipient_id)
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
    end

14
    def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
15 16
      setup_merge_request_mail(merge_request_id, recipient_id)

skv committed
17
      @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
18
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
19
    end
20

21
    def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id)
22
      setup_merge_request_mail(merge_request_id, recipient_id)
23

24
      @label_names = label_names
25 26
      @labels_url = namespace_project_labels_url(@project.namespace, @project)
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
27 28
    end

29
    def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
30 31
      setup_merge_request_mail(merge_request_id, recipient_id)

32
      @updated_by = User.find(updated_by_user_id)
33
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
34 35
    end

36
    def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
37 38
      setup_merge_request_mail(merge_request_id, recipient_id)

39
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
40
    end
41 42

    def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id)
43 44
      setup_merge_request_mail(merge_request_id, recipient_id)

45
      @mr_status = status
46
      @updated_by = User.find(updated_by_user_id)
47
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
48 49
    end

50 51 52 53 54 55 56
    def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id)
      setup_merge_request_mail(merge_request_id, recipient_id)

      @resolved_by = User.find(resolved_by_user_id)
      mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, recipient_id))
    end

57 58
    private

59
    def setup_merge_request_mail(merge_request_id, recipient_id)
60 61
      @merge_request = MergeRequest.find(merge_request_id)
      @project = @merge_request.project
62 63
      @target_url = namespace_project_merge_request_url(@project.namespace, @project, @merge_request)

64
      @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
65
    end
Douwe Maan committed
66

67 68 69 70
    def merge_request_thread_options(sender_id, recipient_id)
      {
        from: sender(sender_id),
        to: recipient(recipient_id),
71
        subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})")
72
      }
73
    end
74 75
  end
end