summaryrefslogtreecommitdiff
path: root/app/mailers/emails/releases.rb
blob: c9c77ab93336481e8e52535735785c3e087cab86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Emails
  module Releases
    def new_release_email(user_id, release, reason = nil)
      @release = release
      @project = @release.project
      @target_url = namespace_project_releases_url(
        namespace_id: @project.namespace,
        project_id: @project
      )

      user = User.find(user_id)

      mail(
        to: user.notification_email_for(@project.group),
        subject: subject(release_email_subject)
      )
    end

    private

    def release_email_subject
      release_info =
        if @release.name == @release.tag
          @release.tag
        else
          [@release.name, @release.tag].select(&:presence).join(' - ')
        end

      "New release: #{release_info}"
    end
  end
end