BigW Consortium Gitlab

merge_requests.rb 2.74 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 7 8 9
      mail_new_thread(@merge_request,
                      from: sender(@merge_request.author_id),
                      to: recipient(recipient_id),
                      subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
10 11
    end

12
    def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
13 14
      setup_merge_request_mail(merge_request_id, recipient_id)

skv committed
15
      @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
16 17 18 19
      mail_answer_thread(@merge_request,
                         from: sender(updated_by_user_id),
                         to: recipient(recipient_id),
                         subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
20
    end
21 22

    def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
23 24
      setup_merge_request_mail(merge_request_id, recipient_id)

25
      @updated_by = User.find updated_by_user_id
26 27 28 29
      mail_answer_thread(@merge_request,
                         from: sender(updated_by_user_id),
                         to: recipient(recipient_id),
                         subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
30 31
    end

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

35 36 37 38
      mail_answer_thread(@merge_request,
                         from: sender(updated_by_user_id),
                         to: recipient(recipient_id),
                         subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
39
    end
40 41

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

44 45
      @mr_status = status
      @updated_by = User.find updated_by_user_id
46 47 48
      mail_answer_thread(@merge_request,
                         from: sender(updated_by_user_id),
                         to: recipient(recipient_id),
49
                         subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
50 51 52 53 54 55 56 57 58 59
    end

    private

    def setup_merge_request_mail(merge_request_id, recipient_id)
      @merge_request = MergeRequest.find(merge_request_id)
      @project = @merge_request.project
      @target_url = namespace_project_merge_request_url(@project.namespace,
                                                        @project,
                                                        @merge_request)
Douwe Maan committed
60

61
      @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key)
62
    end
63 64
  end
end