Use consistent email subject line for pipelines

When using the `gitlab_rails['gitlab_email_subject_suffix']`
configuration option it was not applied to all emails. This
commits add the support for email_subject_suffix to
pipeline notification emails. As a consequence of this change
the project names placement is consistent with other email subjects.
The project name is now at the beginning of the subject for pipeline
emails aswell.

Changelog: changed

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/213383
parent b359579d
...@@ -32,7 +32,7 @@ module Emails ...@@ -32,7 +32,7 @@ module Emails
# thousand times. This could be potentially expensive in a loop, and # thousand times. This could be potentially expensive in a loop, and
# recipients would contain all project watchers so it could be a lot. # recipients would contain all project watchers so it could be a lot.
mail(bcc: recipients, mail(bcc: recipients,
subject: pipeline_subject(status)) do |format| subject: subject(pipeline_subject(status))) do |format|
format.html { render layout: 'mailer' } format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' } format.text { render layout: 'mailer' }
end end
...@@ -53,7 +53,6 @@ module Emails ...@@ -53,7 +53,6 @@ module Emails
subject = [] subject = []
subject << "#{status} pipeline for #{@pipeline.source_ref}" subject << "#{status} pipeline for #{@pipeline.source_ref}"
subject << @project.name if @project
subject << @pipeline.short_sha subject << @pipeline.short_sha
subject.join(' | ') subject.join(' | ')
......
...@@ -9,12 +9,14 @@ RSpec.describe Emails::Pipelines do ...@@ -9,12 +9,14 @@ RSpec.describe Emails::Pipelines do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
shared_examples_for 'correct pipeline information' do shared_examples_for 'correct pipeline information' do
it 'has a correct information' do let(:expected_email_subject) do
expect(subject) "#{project.name} | " \
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \ "#{status} pipeline for #{pipeline.source_ref} | " \
"#{project.name} | " \ "#{pipeline.short_sha}"
"#{pipeline.short_sha}".to_s end
it 'has a correct information' do
expect(subject).to have_subject expected_email_subject
expect(subject).to have_body_text pipeline.source_ref expect(subject).to have_body_text pipeline.source_ref
expect(subject).to have_body_text status_text expect(subject).to have_body_text status_text
end end
...@@ -28,11 +30,7 @@ RSpec.describe Emails::Pipelines do ...@@ -28,11 +30,7 @@ RSpec.describe Emails::Pipelines do
end end
it 'has correct information that there is no merge request link' do it 'has correct information that there is no merge request link' do
expect(subject) expect(subject).to have_subject expected_email_subject
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
"#{project.name} | " \
"#{pipeline.short_sha}".to_s
expect(subject).to have_body_text pipeline.source_ref expect(subject).to have_body_text pipeline.source_ref
expect(subject).to have_body_text status_text expect(subject).to have_body_text status_text
end end
...@@ -48,11 +46,7 @@ RSpec.describe Emails::Pipelines do ...@@ -48,11 +46,7 @@ RSpec.describe Emails::Pipelines do
end end
it 'has correct information that there is a merge request link' do it 'has correct information that there is a merge request link' do
expect(subject) expect(subject).to have_subject expected_email_subject
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
"#{project.name} | " \
"#{pipeline.short_sha}".to_s
expect(subject).to have_body_text merge_request.to_reference expect(subject).to have_body_text merge_request.to_reference
expect(subject).to have_body_text pipeline.source_ref expect(subject).to have_body_text pipeline.source_ref
expect(subject).not_to have_body_text pipeline.ref expect(subject).not_to have_body_text pipeline.ref
...@@ -70,11 +64,7 @@ RSpec.describe Emails::Pipelines do ...@@ -70,11 +64,7 @@ RSpec.describe Emails::Pipelines do
end end
it 'has correct information that there is a merge request link' do it 'has correct information that there is a merge request link' do
expect(subject) expect(subject).to have_subject expected_email_subject
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
"#{project.name} | " \
"#{pipeline.short_sha}".to_s
expect(subject).to have_body_text merge_request.to_reference expect(subject).to have_body_text merge_request.to_reference
expect(subject).to have_body_text pipeline.source_ref expect(subject).to have_body_text pipeline.source_ref
end end
...@@ -91,6 +81,17 @@ RSpec.describe Emails::Pipelines do ...@@ -91,6 +81,17 @@ RSpec.describe Emails::Pipelines do
it_behaves_like 'correct pipeline information' do it_behaves_like 'correct pipeline information' do
let(:status) { 'Successful' } let(:status) { 'Successful' }
let(:status_text) { "Pipeline ##{pipeline.id} has passed!" } let(:status_text) { "Pipeline ##{pipeline.id} has passed!" }
let(:email_subject_suffix) { 'A Nice Suffix' }
let(:expected_email_subject) do
"#{project.name} | " \
"#{status} pipeline for #{pipeline.source_ref} | " \
"#{pipeline.short_sha} | " \
"#{email_subject_suffix}"
end
before do
stub_config_setting(email_subject_suffix: email_subject_suffix)
end
end 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