Commit cb0ec316 authored by manojmj's avatar manojmj

Fix Pipeline failed emails not being delivered for bridge jobs

This fix corrects a bug where pipeline failed notification
emails were not being delivered if the failed pipeline has failed
bridge jobs
parent d0a3f1bc
---
title: Fix Pipeline failed notification email not being delivered if the failed job
is a bridge job
merge_request: 23668
author:
type: fixed
...@@ -15,7 +15,7 @@ describe 'notify/pipeline_failed_email.html.haml' do ...@@ -15,7 +15,7 @@ describe 'notify/pipeline_failed_email.html.haml' do
user: user, user: user,
ref: project.default_branch, ref: project.default_branch,
sha: project.commit.sha, sha: project.commit.sha,
status: :success) status: :failed)
end end
before do before do
...@@ -24,35 +24,51 @@ describe 'notify/pipeline_failed_email.html.haml' do ...@@ -24,35 +24,51 @@ describe 'notify/pipeline_failed_email.html.haml' do
assign(:merge_request, merge_request) assign(:merge_request, merge_request)
end end
context 'pipeline with user' do shared_examples_for 'renders the pipeline failed email correctly' do
it 'renders the email correctly' do context 'pipeline with user' do
render it 'renders the email correctly' do
render
expect(rendered).to have_content "Your pipeline has failed" expect(rendered).to have_content "Your pipeline has failed"
expect(rendered).to have_content pipeline.project.name expect(rendered).to have_content pipeline.project.name
expect(rendered).to have_content pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' ') expect(rendered).to have_content pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' ')
expect(rendered).to have_content pipeline.commit.author_name expect(rendered).to have_content pipeline.commit.author_name
expect(rendered).to have_content "##{pipeline.id}" expect(rendered).to have_content "##{pipeline.id}"
expect(rendered).to have_content pipeline.user.name expect(rendered).to have_content pipeline.user.name
expect(rendered).to have_content build.name
end
it_behaves_like 'correct pipeline information for pipelines for merge requests'
end end
it_behaves_like 'correct pipeline information for pipelines for merge requests' context 'pipeline without user' do
end before do
pipeline.update_attribute(:user, nil)
end
context 'pipeline without user' do it 'renders the email correctly' do
before do render
pipeline.update_attribute(:user, nil)
expect(rendered).to have_content "Your pipeline has failed"
expect(rendered).to have_content pipeline.project.name
expect(rendered).to have_content pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' ')
expect(rendered).to have_content pipeline.commit.author_name
expect(rendered).to have_content "##{pipeline.id}"
expect(rendered).to have_content "by API"
expect(rendered).to have_content build.name
end
end end
end
it 'renders the email correctly' do context 'when the pipeline contains a failed job' do
render let!(:build) { create(:ci_build, :failed, pipeline: pipeline, project: pipeline.project) }
expect(rendered).to have_content "Your pipeline has failed" it_behaves_like 'renders the pipeline failed email correctly'
expect(rendered).to have_content pipeline.project.name end
expect(rendered).to have_content pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' ')
expect(rendered).to have_content pipeline.commit.author_name context 'when the latest failed job is a bridge job' do
expect(rendered).to have_content "##{pipeline.id}" let!(:build) { create(:ci_bridge, status: :failed, pipeline: pipeline, project: pipeline.project) }
expect(rendered).to have_content "by API"
end it_behaves_like 'renders the pipeline failed email correctly'
end end
end end
...@@ -23,19 +23,31 @@ describe 'notify/pipeline_failed_email.text.erb' do ...@@ -23,19 +23,31 @@ describe 'notify/pipeline_failed_email.text.erb' do
assign(:merge_request, merge_request) assign(:merge_request, merge_request)
end end
it 'renders the email correctly' do shared_examples_for 'renders the pipeline failed email correctly' do
job = create(:ci_build, :failed, pipeline: pipeline, project: pipeline.project) it 'renders the email correctly' do
render
render
expect(rendered).to have_content('Your pipeline has failed')
expect(rendered).to have_content('Your pipeline has failed') expect(rendered).to have_content(pipeline.project.name)
expect(rendered).to have_content(pipeline.project.name) expect(rendered).to have_content(pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' '))
expect(rendered).to have_content(pipeline.git_commit_message.truncate(50).gsub(/\s+/, ' ')) expect(rendered).to have_content(pipeline.commit.author_name)
expect(rendered).to have_content(pipeline.commit.author_name) expect(rendered).to have_content("##{pipeline.id}")
expect(rendered).to have_content("##{pipeline.id}") expect(rendered).to have_content(pipeline.user.name)
expect(rendered).to have_content(pipeline.user.name) expect(rendered).to have_content(build.id)
expect(rendered).to have_content("/-/jobs/#{job.id}/raw") end
it_behaves_like 'correct pipeline information for pipelines for merge requests'
end end
it_behaves_like 'correct pipeline information for pipelines for merge requests' context 'when the pipeline contains a failed job' do
let!(:build) { create(:ci_build, :failed, pipeline: pipeline, project: pipeline.project) }
it_behaves_like 'renders the pipeline failed email correctly'
end
context 'when the latest failed job is a bridge job' do
let!(:build) { create(:ci_bridge, status: :failed, pipeline: pipeline, project: pipeline.project) }
it_behaves_like 'renders the pipeline failed email correctly'
end
end end
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