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)
|
|
|
|
pipeline_mail(pipeline, recipients, 'succeeded')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
def pipeline_failed_email(pipeline, recipients)
|
|
|
|
pipeline_mail(pipeline, recipients, 'failed')
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2016-10-14 07:54:51 -04:00
|
|
|
@merge_request = pipeline.merge_requests.first
|
2016-08-25 08:01:10 -04:00
|
|
|
add_headers
|
|
|
|
|
2016-10-18 08:02:35 -04:00
|
|
|
# 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' }
|
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)
|
2018-08-15 17:45:57 -04:00
|
|
|
commit = [@pipeline.short_sha]
|
|
|
|
commit << "in #{@merge_request.to_reference}" if @merge_request
|
2016-10-06 11:09:24 -04:00
|
|
|
|
2018-08-15 17:45:57 -04:00
|
|
|
subject("Pipeline ##{@pipeline.id} has #{status} for #{@pipeline.ref}", commit.join(' '))
|
2016-08-25 08:01:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|