diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/mailers/emails/pipelines.rb | 27 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 18 | ||||
-rw-r--r-- | app/services/notification_service.rb | 18 | ||||
-rw-r--r-- | app/views/notify/pipeline_success_email.html.haml | 2 | ||||
-rw-r--r-- | app/views/notify/pipeline_success_email.text.erb | 2 |
5 files changed, 49 insertions, 18 deletions
diff --git a/app/mailers/emails/pipelines.rb b/app/mailers/emails/pipelines.rb index 9460a6cd2be..ba3f7eaf216 100644 --- a/app/mailers/emails/pipelines.rb +++ b/app/mailers/emails/pipelines.rb @@ -1,11 +1,29 @@ module Emails module Pipelines - def pipeline_success_email(pipeline, recipients) - pipeline_mail(pipeline, recipients, 'succeeded') + def self.prepare_email(mailer, pipeline) + status = pipeline.detailed_status(nil) + template = status.pipeline_email_template + + return unless template + + recipients = yield + + return unless recipients.any? + + mailer.public_send( + template, + pipeline, + recipients, + status.pipeline_email_status + ).deliver_later + end + + def pipeline_success_email(pipeline, recipients, status) + pipeline_mail(pipeline, recipients, status) end - def pipeline_failed_email(pipeline, recipients) - pipeline_mail(pipeline, recipients, 'failed') + def pipeline_failed_email(pipeline, recipients, status) + pipeline_mail(pipeline, recipients, status) end private @@ -13,6 +31,7 @@ module Emails def pipeline_mail(pipeline, recipients, status) @project = pipeline.project @pipeline = pipeline + @status = status @merge_request = pipeline.merge_requests.first add_headers diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 48354cdbefb..359c517b27b 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -254,6 +254,24 @@ module Ci builds.latest.failed_but_allowed.any? end + def recovered? + success? && previous_pipeline.try(:failed?) + end + + def first_success? + success? && previous_pipeline.nil? + end + + def previous_pipeline + return @previous_pipeline if defined?(@previous_pipeline) + + @previous_pipeline = + project.pipelines. + where(ref: ref). + where("#{self.class.quoted_table_name}.id < ?", id). + order(id: :desc).first + end + def config_processor return nil unless ci_yaml_file return @config_processor if defined?(@config_processor) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 9a7af5730d2..b99e4c21229 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -312,18 +312,12 @@ class NotificationService end def pipeline_finished(pipeline, recipients = nil) - email_template = "pipeline_#{pipeline.status}_email" - - return unless mailer.respond_to?(email_template) - - recipients ||= build_recipients( - pipeline, - pipeline.project, - nil, # The acting user, who won't be added to recipients - action: pipeline.status).map(&:notification_email) - - if recipients.any? - mailer.public_send(email_template, pipeline, recipients).deliver_later + Emails::Pipelines.prepare_email(mailer, pipeline) do + build_recipients( + pipeline, + pipeline.project, + nil, # The acting user, who won't be added to recipients + action: pipeline.status).map(&:notification_email) end end diff --git a/app/views/notify/pipeline_success_email.html.haml b/app/views/notify/pipeline_success_email.html.haml index 56c1949ab2b..c805c4a0425 100644 --- a/app/views/notify/pipeline_success_email.html.haml +++ b/app/views/notify/pipeline_success_email.html.haml @@ -65,7 +65,7 @@ %td{style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;vertical-align:middle;color:#ffffff;text-align:center;padding-right:5px;"} %img{alt: "✓", height: "13", src: image_url('mailers/ci_pipeline_notif_v1/icon-check-green-inverted.gif'), style: "display:block;", width: "13"}/ %td{style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;vertical-align:middle;color:#ffffff;text-align:center;"} - Your pipeline has passed. + = "Your pipeline has #{@status}." %tr.spacer %td{style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;height:18px;font-size:18px;line-height:18px;"} diff --git a/app/views/notify/pipeline_success_email.text.erb b/app/views/notify/pipeline_success_email.text.erb index 40e5e306426..66a86b0f5d6 100644 --- a/app/views/notify/pipeline_success_email.text.erb +++ b/app/views/notify/pipeline_success_email.text.erb @@ -1,4 +1,4 @@ -Your pipeline has passed. +Your pipeline has <%= @status %>. Project: <%= @project.name %> ( <%= project_url(@project) %> ) Branch: <%= @pipeline.ref %> ( <%= commits_url(@pipeline) %> ) |