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

60 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)
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
2020-04-08 14:13:33 +05:30
def pipeline_fixed_email(pipeline, recipients)
pipeline_mail(pipeline, recipients, 'been fixed')
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-09 13:42:32 +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)
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
2019-12-21 20:55:43 +05:30
subject("Pipeline ##{@pipeline.id} has #{status} for #{@pipeline.source_ref}", commit.join(' '))
2016-11-03 12:29:30 +05:30
end
end
end