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

61 lines
1.5 KiB
Ruby
Raw Normal View History

2018-08-15 17:45:57 -04:00
# frozen_string_literal: true
module Emails
module Pipelines
def pipeline_success_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Successful')
end
def pipeline_failed_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Failed')
end
def pipeline_fixed_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Fixed')
end
private
def pipeline_mail(pipeline, recipient, status)
raise ArgumentError if recipient.is_a?(Array)
@project = pipeline.project
@pipeline = pipeline
@merge_request = if pipeline.merge_request?
pipeline.merge_request
else
pipeline.merge_requests_as_head_pipeline.first
end
add_headers
mail(to: recipient,
subject: subject(pipeline_subject(status))) 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)
subject = []
subject << "#{status} pipeline for #{@pipeline.source_ref}"
subject << @pipeline.short_sha
subject.join(' | ')
end
end
end