BigW Consortium Gitlab

merge_requests.rb 2.56 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
    def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
10 11
      setup_merge_request_mail(merge_request_id, recipient_id)

skv committed
12
      @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
13
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
14
    end
15

16
    def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id)
17
      setup_merge_request_mail(merge_request_id, recipient_id)
18

19
      @label_names = label_names
20 21
      @labels_url = namespace_project_labels_url(@project.namespace, @project)
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
22 23
    end

24
    def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
25 26
      setup_merge_request_mail(merge_request_id, recipient_id)

27
      @updated_by = User.find(updated_by_user_id)
28
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
29 30
    end

31
    def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
32 33
      setup_merge_request_mail(merge_request_id, recipient_id)

34
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
35
    end
36 37

    def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id)
38 39
      setup_merge_request_mail(merge_request_id, recipient_id)

40
      @mr_status = status
41
      @updated_by = User.find(updated_by_user_id)
42
      mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
43 44 45 46
    end

    private

47
    def setup_merge_request_mail(merge_request_id, recipient_id)
48 49
      @merge_request = MergeRequest.find(merge_request_id)
      @project = @merge_request.project
50 51
      @target_url = namespace_project_merge_request_url(@project.namespace, @project, @merge_request)

52
      @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
53
    end
Douwe Maan committed
54

55 56 57 58
    def merge_request_thread_options(sender_id, recipient_id)
      {
        from: sender(sender_id),
        to: recipient(recipient_id),
59
        subject: subject("#{@merge_request.title} (#{@merge_request.to_reference})")
60
      }
61
    end
62 63
  end
end