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