gitlab-org--gitlab-foss/app/mailers/emails/pipelines.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

module Emails
module Pipelines
def pipeline_success_email(pipeline, recipients)
pipeline_mail(pipeline, recipients, 'succeeded')
end
def pipeline_failed_email(pipeline, recipients)
pipeline_mail(pipeline, recipients, 'failed')
end
private
def pipeline_mail(pipeline, recipients, status)
@project = pipeline.project
@pipeline = pipeline
@merge_request = pipeline.merge_requests.first
add_headers
# We use bcc here because we don't want to generate this emails for a
# thousand times. This could be potentially expensive in a loop, and
# recipients would contain all project watchers so it could be a lot.
mail(bcc: recipients,
subject: pipeline_subject(status),
skip_premailer: true) do |format|
2017-02-06 14:15:25 -05:00
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
end
end
def add_headers
add_project_headers
2016-08-31 09:38:02 -04:00
add_pipeline_headers
end
2016-08-31 09:38:02 -04:00
def add_pipeline_headers
headers['X-GitLab-Pipeline-Id'] = @pipeline.id
headers['X-GitLab-Pipeline-Ref'] = @pipeline.ref
headers['X-GitLab-Pipeline-Status'] = @pipeline.status
end
def pipeline_subject(status)
2016-10-06 11:12:59 -04:00
commit = @pipeline.short_sha
commit << " in #{@merge_request.to_reference}" if @merge_request
2016-10-06 11:12:59 -04:00
subject("Pipeline ##{@pipeline.id} has #{status} for #{@pipeline.ref}", commit)
end
end
end