gitlab-org--gitlab-foss/app/mailers/emails/pipelines.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

module Emails
module Pipelines
def pipeline_success_email(pipeline, to)
pipeline_mail(pipeline, to, 'succeeded')
end
def pipeline_failed_email(pipeline, to)
pipeline_mail(pipeline, to, 'failed')
end
private
def pipeline_mail(pipeline, to, status)
@project = pipeline.project
@pipeline = pipeline
@merge_request = @project.merge_requests.opened.
find_by(source_project: @project,
source_branch: @pipeline.ref,
target_branch: @project.default_branch)
add_headers
2016-08-31 09:38:25 +00:00
mail(to: to, subject: pipeline_subject(status))
end
def add_headers
add_project_headers
2016-08-31 13:38:02 +00:00
add_pipeline_headers
end
2016-08-31 13:38:02 +00: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
end
def pipeline_subject(status)
ref = @pipeline.short_sha
ref << " in #{@merge_request.to_reference}" if @merge_request
subject("Pipeline ##{@pipeline.id} has #{status}", ref)
end
end
end