2018-08-15 17:45:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 08:01:10 -04:00
|
|
|
module Emails
|
|
|
|
module Pipelines
|
2021-11-03 08:10:26 -04:00
|
|
|
def pipeline_success_email(pipeline, recipient)
|
|
|
|
pipeline_mail(pipeline, recipient, 'Successful')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
2021-11-03 08:10:26 -04:00
|
|
|
def pipeline_failed_email(pipeline, recipient)
|
|
|
|
pipeline_mail(pipeline, recipient, 'Failed')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
2021-11-03 08:10:26 -04:00
|
|
|
def pipeline_fixed_email(pipeline, recipient)
|
|
|
|
pipeline_mail(pipeline, recipient, 'Fixed')
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
|
2016-08-25 08:01:10 -04:00
|
|
|
private
|
|
|
|
|
2021-11-03 08:10:26 -04:00
|
|
|
def pipeline_mail(pipeline, recipient, status)
|
|
|
|
raise ArgumentError if recipient.is_a?(Array)
|
|
|
|
|
2016-09-13 07:09:53 -04:00
|
|
|
@project = pipeline.project
|
|
|
|
@pipeline = pipeline
|
2020-02-17 07:09:20 -05:00
|
|
|
|
|
|
|
@merge_request = if pipeline.merge_request?
|
|
|
|
pipeline.merge_request
|
|
|
|
else
|
|
|
|
pipeline.merge_requests_as_head_pipeline.first
|
|
|
|
end
|
|
|
|
|
2016-08-25 08:01:10 -04:00
|
|
|
add_headers
|
|
|
|
|
2021-11-03 08:10:26 -04:00
|
|
|
mail(to: recipient,
|
2021-08-18 20:11:16 -04:00
|
|
|
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' }
|
2016-10-07 19:30:42 -04:00
|
|
|
end
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_headers
|
|
|
|
add_project_headers
|
2016-08-31 09:38:02 -04:00
|
|
|
add_pipeline_headers
|
2016-08-25 08:01:10 -04:00
|
|
|
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
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_subject(status)
|
2021-01-08 07:10:35 -05:00
|
|
|
subject = []
|
2016-10-06 11:09:24 -04:00
|
|
|
|
2021-01-08 07:10:35 -05:00
|
|
|
subject << "#{status} pipeline for #{@pipeline.source_ref}"
|
|
|
|
subject << @pipeline.short_sha
|
|
|
|
|
|
|
|
subject.join(' | ')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|