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

63 lines
1.7 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)
2021-04-17 20:07:23 +05:30
pipeline_mail(pipeline, recipients, 'Successful')
2016-11-03 12:29:30 +05:30
end
2017-08-17 22:00:37 +05:30
def pipeline_failed_email(pipeline, recipients)
2021-03-08 18:12:59 +05:30
pipeline_mail(pipeline, recipients, 'Failed')
2016-11-03 12:29:30 +05:30
end
2020-04-08 14:13:33 +05:30
def pipeline_fixed_email(pipeline, recipients)
2021-03-08 18:12:59 +05:30
pipeline_mail(pipeline, recipients, 'Fixed')
2020-04-08 14:13:33 +05:30
end
2016-11-03 12:29:30 +05:30
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
2020-03-13 15:44:24 +05:30
@merge_request = if pipeline.merge_request?
pipeline.merge_request
else
pipeline.merge_requests_as_head_pipeline.first
end
2016-11-03 12:29:30 +05:30
add_headers
2019-12-26 22:10:19 +05:30
# We use bcc here because we don't want to generate these emails for a
2017-08-17 22:00:37 +05:30
# 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-12-26 22:10:19 +05:30
subject: pipeline_subject(status)) do |format|
2017-08-17 22:00:37 +05:30
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)
2021-03-08 18:12:59 +05:30
subject = []
2016-11-03 12:29:30 +05:30
2021-03-08 18:12:59 +05:30
subject << "#{status} pipeline for #{@pipeline.source_ref}"
subject << @project.name if @project
subject << @pipeline.short_sha
subject.join(' | ')
2016-11-03 12:29:30 +05:30
end
end
end