Commit 31a5da40 authored by Shinya Maeda's avatar Shinya Maeda

Fix wrong MR link in pipeline failure email

This MR fixes the pipeline failure email bug
parent ce2fdf32
......@@ -15,7 +15,13 @@ module Emails
def pipeline_mail(pipeline, recipients, status)
@project = pipeline.project
@pipeline = pipeline
@merge_request = pipeline.all_merge_requests.first
@merge_request = if pipeline.merge_request?
pipeline.merge_request
else
pipeline.merge_requests_as_head_pipeline.first
end
add_headers
# We use bcc here because we don't want to generate these emails for a
......
---
title: Fix wrong MR link is shown on pipeline failure email
merge_request:
author:
type: fixed
......@@ -19,6 +19,25 @@ describe Emails::Pipelines do
expect(subject).to have_body_text status_text
end
context 'when pipeline on master branch has a merge request' do
let(:pipeline) { create(:ci_pipeline, ref: 'master', sha: sha, project: project) }
let!(:merge_request) do
create(:merge_request, source_branch: 'master', target_branch: 'feature',
source_project: project, target_project: project)
end
it 'has correct information that there is no merge request link' do
expect(subject)
.to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \
"#{status} for #{pipeline.source_ref} | " \
"#{pipeline.short_sha}".to_s
expect(subject).to have_body_text pipeline.source_ref
expect(subject).to have_body_text status_text
end
end
context 'when pipeline for merge requests' do
let(:pipeline) { merge_request.all_pipelines.first }
......@@ -28,7 +47,7 @@ describe Emails::Pipelines do
target_project: project)
end
it 'has a correct information with merge request link' do
it 'has correct information that there is a merge request link' do
expect(subject)
.to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \
"#{status} for #{pipeline.source_ref} | " \
......@@ -39,6 +58,27 @@ describe Emails::Pipelines do
expect(subject).not_to have_body_text pipeline.ref
end
end
context 'when branch pipeline is set to a merge request as a head pipeline' do
let(:pipeline) do
create(:ci_pipeline, project: project, ref: ref, sha: sha,
merge_requests_as_head_pipeline: [merge_request])
end
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project)
end
it 'has correct information that there is a merge request link' do
expect(subject)
.to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \
"#{status} for #{pipeline.source_ref} | " \
"#{pipeline.short_sha} in !#{merge_request.iid}".to_s
expect(subject).to have_body_text merge_request.to_reference
expect(subject).to have_body_text pipeline.source_ref
end
end
end
describe '#pipeline_success_email' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment