BigW Consortium Gitlab

notes.rb 1.59 KB
Newer Older
1 2 3
module Emails
  module Notes
    def note_commit_email(recipient_id, note_id)
4
      setup_note_mail(note_id, recipient_id)
5 6 7 8 9 10 11 12

      @commit = @note.noteable
      @target_url = namespace_project_commit_url(*note_target_url_options)

      mail_answer_thread(@commit,
                         from: sender(@note.author_id),
                         to: recipient(recipient_id),
                         subject: subject("#{@commit.title} (#{@commit.short_id})"))
13 14 15
    end

    def note_issue_email(recipient_id, note_id)
16
      setup_note_mail(note_id, recipient_id)
17 18 19 20

      @issue = @note.noteable
      @target_url = namespace_project_issue_url(*note_target_url_options)
      mail_answer_thread(@issue, note_thread_options(recipient_id))
21 22 23
    end

    def note_merge_request_email(recipient_id, note_id)
24
      setup_note_mail(note_id, recipient_id)
25 26 27 28

      @merge_request = @note.noteable
      @target_url = namespace_project_merge_request_url(*note_target_url_options)
      mail_answer_thread(@merge_request, note_thread_options(recipient_id))
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    end

    private

    def note_target_url_options
      [@project.namespace, @project, @note.noteable, anchor: "note_#{@note.id}"]
    end

    def note_thread_options(recipient_id)
      {
        from: sender(@note.author_id),
        to: recipient(recipient_id),
        subject: subject("#{@note.noteable.title} (##{@note.noteable.iid})")
      }
    end

45
    def setup_note_mail(note_id, recipient_id)
46 47
      @note = Note.find(note_id)
      @project = @note.project
48

49
      @sent_notification = SentNotification.record_note(@note, recipient_id, reply_key)
50 51 52
    end
  end
end