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

59 lines
1.4 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
2021-12-11 22:18:48 +05:30
def pipeline_success_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Successful')
2016-11-03 12:29:30 +05:30
end
2021-12-11 22:18:48 +05:30
def pipeline_failed_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Failed')
2016-11-03 12:29:30 +05:30
end
2021-12-11 22:18:48 +05:30
def pipeline_fixed_email(pipeline, recipient)
pipeline_mail(pipeline, recipient, 'Fixed')
2020-04-08 14:13:33 +05:30
end
2016-11-03 12:29:30 +05:30
private
2021-12-11 22:18:48 +05:30
def pipeline_mail(pipeline, recipient, status)
raise ArgumentError if recipient.is_a?(Array)
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
2022-07-23 23:45:48 +05:30
email_with_layout(
to: recipient,
subject: subject(pipeline_subject(status)))
2016-11-03 12:29:30 +05:30
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 << @pipeline.short_sha
subject.join(' | ')
2016-11-03 12:29:30 +05:30
end
end
end