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 ...@@ -15,7 +15,13 @@ module Emails
def pipeline_mail(pipeline, recipients, status) def pipeline_mail(pipeline, recipients, status)
@project = pipeline.project @project = pipeline.project
@pipeline = pipeline @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 add_headers
# We use bcc here because we don't want to generate these emails for a # 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 ...@@ -19,6 +19,25 @@ describe Emails::Pipelines do
expect(subject).to have_body_text status_text expect(subject).to have_body_text status_text
end 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 context 'when pipeline for merge requests' do
let(:pipeline) { merge_request.all_pipelines.first } let(:pipeline) { merge_request.all_pipelines.first }
...@@ -28,7 +47,7 @@ describe Emails::Pipelines do ...@@ -28,7 +47,7 @@ describe Emails::Pipelines do
target_project: project) target_project: project)
end 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) expect(subject)
.to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \ .to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \
"#{status} for #{pipeline.source_ref} | " \ "#{status} for #{pipeline.source_ref} | " \
...@@ -39,6 +58,27 @@ describe Emails::Pipelines do ...@@ -39,6 +58,27 @@ describe Emails::Pipelines do
expect(subject).not_to have_body_text pipeline.ref expect(subject).not_to have_body_text pipeline.ref
end end
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 end
describe '#pipeline_success_email' do 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