debian-mirror-gitlab/app/mailers/emails/pipelines.rb

51 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
module Emails
module Pipelines
2017-08-17 22:00:37 +05:30
def pipeline_success_email(pipeline, recipients)
pipeline_mail(pipeline, recipients, 'succeeded')
2016-11-03 12:29:30 +05:30
end
2017-08-17 22:00:37 +05:30
def pipeline_failed_email(pipeline, recipients)
pipeline_mail(pipeline, recipients, 'failed')
2016-11-03 12:29:30 +05:30
end
private
2017-08-17 22:00:37 +05:30
def pipeline_mail(pipeline, recipients, status)
2016-11-03 12:29:30 +05:30
@project = pipeline.project
@pipeline = pipeline
2019-07-07 11:18:12 +05:30
@merge_request = pipeline.merge_requests_as_head_pipeline.first
2016-11-03 12:29:30 +05:30
add_headers
2017-08-17 22:00:37 +05:30
# 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|
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
2016-11-03 12:29:30 +05:30
end
end
def add_headers
add_project_headers
add_pipeline_headers
end
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)
2018-11-20 20:47:30 +05:30
commit = [@pipeline.short_sha]
commit << "in #{@merge_request.to_reference}" if @merge_request
2016-11-03 12:29:30 +05:30
2018-11-20 20:47:30 +05:30
subject("Pipeline ##{@pipeline.id} has #{status} for #{@pipeline.ref}", commit.join(' '))
2016-11-03 12:29:30 +05:30
end
end
end