diff options
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/base_mailer.rb | 4 | ||||
-rw-r--r-- | app/mailers/ci/emails/builds.rb | 17 | ||||
-rw-r--r-- | app/mailers/ci/notify.rb | 47 | ||||
-rw-r--r-- | app/mailers/notify.rb | 4 |
4 files changed, 68 insertions, 4 deletions
diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb index aedb0889185..2b650bc6eac 100644 --- a/app/mailers/base_mailer.rb +++ b/app/mailers/base_mailer.rb @@ -1,6 +1,6 @@ class BaseMailer < ActionMailer::Base - add_template_helper ApplicationHelper - add_template_helper GitlabMarkdownHelper + add_template_helper Gitlab::ApplicationHelper + add_template_helper Gitlab::GitlabMarkdownHelper attr_accessor :current_user helper_method :current_user, :can? diff --git a/app/mailers/ci/emails/builds.rb b/app/mailers/ci/emails/builds.rb new file mode 100644 index 00000000000..6fb4fba85e5 --- /dev/null +++ b/app/mailers/ci/emails/builds.rb @@ -0,0 +1,17 @@ +module Ci + module Emails + module Builds + def build_fail_email(build_id, to) + @build = Ci::Build.find(build_id) + @project = @build.project + mail(to: to, subject: subject("Build failed for #{@project.name}", @build.short_sha)) + end + + def build_success_email(build_id, to) + @build = Ci::Build.find(build_id) + @project = @build.project + mail(to: to, subject: subject("Build success for #{@project.name}", @build.short_sha)) + end + end + end +end diff --git a/app/mailers/ci/notify.rb b/app/mailers/ci/notify.rb new file mode 100644 index 00000000000..44e490e9b36 --- /dev/null +++ b/app/mailers/ci/notify.rb @@ -0,0 +1,47 @@ +module Ci + class Notify < ActionMailer::Base + include Ci::Emails::Builds + + add_template_helper Ci::ApplicationHelper + add_template_helper Ci::GitlabHelper + + default_url_options[:host] = GitlabCi.config.gitlab_ci.host + default_url_options[:protocol] = GitlabCi.config.gitlab_ci.protocol + default_url_options[:port] = GitlabCi.config.gitlab_ci.port if GitlabCi.config.gitlab_ci_on_non_standard_port? + default_url_options[:script_name] = GitlabCi.config.gitlab_ci.relative_url_root + + default from: GitlabCi.config.gitlab_ci.email_from + + # Just send email with 3 seconds delay + def self.delay + delay_for(2.seconds) + end + + private + + # Formats arguments into a String suitable for use as an email subject + # + # extra - Extra Strings to be inserted into the subject + # + # Examples + # + # >> subject('Lorem ipsum') + # => "GitLab-CI | Lorem ipsum" + # + # # Automatically inserts Project name when @project is set + # >> @project = Project.last + # => #<Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...> + # >> subject('Lorem ipsum') + # => "GitLab-CI | Ruby on Rails | Lorem ipsum " + # + # # Accepts multiple arguments + # >> subject('Lorem ipsum', 'Dolor sit amet') + # => "GitLab-CI | Lorem ipsum | Dolor sit amet" + def subject(*extra) + subject = "GitLab-CI" + subject << (@project ? " | #{@project.name}" : "") + subject << " | " + extra.join(' | ') if extra.present? + subject + end + end +end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 5717c89e61d..38afb49c78c 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -8,8 +8,8 @@ class Notify < BaseMailer include Emails::Profile include Emails::Groups - add_template_helper MergeRequestsHelper - add_template_helper EmailsHelper + add_template_helper Gitlab::MergeRequestsHelper + add_template_helper Gitlab::EmailsHelper def test_email(recipient_email, subject, body) mail(to: recipient_email, |