2018-08-15 17:45:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 08:01:10 -04:00
|
|
|
module Emails
|
|
|
|
module Pipelines
|
2016-10-18 08:02:35 -04:00
|
|
|
def pipeline_success_email(pipeline, recipients)
|
2021-03-09 16:09:15 -05:00
|
|
|
pipeline_mail(pipeline, recipients, 'Successful')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
def pipeline_failed_email(pipeline, recipients)
|
2021-01-08 07:10:35 -05:00
|
|
|
pipeline_mail(pipeline, recipients, 'Failed')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
2020-02-27 13:09:21 -05:00
|
|
|
def pipeline_fixed_email(pipeline, recipients)
|
2021-01-08 07:10:35 -05:00
|
|
|
pipeline_mail(pipeline, recipients, 'Fixed')
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
|
2016-08-25 08:01:10 -04:00
|
|
|
private
|
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
def pipeline_mail(pipeline, recipients, status)
|
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
|
|
|
|
|
2019-11-12 16:06:30 -05:00
|
|
|
# We use bcc here because we don't want to generate these emails for a
|
2016-10-18 08:02:35 -04:00
|
|
|
# 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,
|
2019-11-12 16:06:30 -05:00
|
|
|
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 << @project.name if @project
|
|
|
|
subject << @pipeline.short_sha
|
|
|
|
|
|
|
|
subject.join(' | ')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|