diff --git a/app/models/integrations/chat_message/pipeline_message.rb b/app/models/integrations/chat_message/pipeline_message.rb index b3502905bf7ea7c1e83bfdaf3aff3e33038d02b9..88db40bea7f7eede7f7c20f06d2915075e9d6791 100644 --- a/app/models/integrations/chat_message/pipeline_message.rb +++ b/app/models/integrations/chat_message/pipeline_message.rb @@ -126,6 +126,14 @@ def yaml_error_field } end + def pipeline_name_field + { + title: s_("ChatMessage|Pipeline name"), + value: pipeline.name, + short: false + } + end + def attachments_fields fields = [ { @@ -143,6 +151,7 @@ def attachments_fields fields << failed_stages_field if failed_stages.any? fields << failed_jobs_field if failed_jobs.any? fields << yaml_error_field if pipeline.has_yaml_errors? + fields << pipeline_name_field if Feature.enabled?(:pipeline_name, project) && pipeline.name.present? fields end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index ddbd32200778299ab0a66c00b3d020baaacc52bf..932c64fd7897708e156e1e29036a49360d6a9d22 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -7999,6 +7999,9 @@ msgstr "" msgid "ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status}" msgstr "" +msgid "ChatMessage|Pipeline name" +msgstr "" + msgid "ChatMessage|Tag" msgstr "" diff --git a/spec/models/integrations/chat_message/pipeline_message_spec.rb b/spec/models/integrations/chat_message/pipeline_message_spec.rb index a63cc0b6d837c6d58e9ed56a963f05d16746ceb5..f3388853b378a3a773a214e204e24ebbbad5b13d 100644 --- a/spec/models/integrations/chat_message/pipeline_message_spec.rb +++ b/spec/models/integrations/chat_message/pipeline_message_spec.rb @@ -44,13 +44,18 @@ before do test_commit = double("A test commit", committer: args[:user], title: "A test commit message") - test_project = double("A test project", commit_by: test_commit, name: args[:project][:name], web_url: args[:project][:web_url]) + test_project = build(:project, name: args[:project][:name]) + + allow(test_project).to receive(:commit_by).and_return(test_commit) + allow(test_project).to receive(:web_url).and_return(args[:project][:web_url]) allow(test_project).to receive(:avatar_url).with(no_args).and_return("/avatar") allow(test_project).to receive(:avatar_url).with(only_path: false).and_return(args[:project][:avatar_url]) allow(Project).to receive(:find) { test_project } - test_pipeline = double("A test pipeline", - has_yaml_errors?: has_yaml_errors, yaml_errors: "yaml error description here") + test_pipeline = build(:ci_empty_pipeline, name: 'Build pipeline') + + allow(test_pipeline).to receive(:has_yaml_errors?).and_return(has_yaml_errors) + allow(test_pipeline).to receive(:yaml_errors).and_return("yaml error description here") allow(Ci::Pipeline).to receive(:find) { test_pipeline } allow(Gitlab::UrlBuilder).to receive(:build).with(test_commit).and_return("http://example.com/commit") @@ -69,6 +74,24 @@ ) end + it 'returns pipeline name' do + name_field = subject.attachments.first[:fields].find { |a| a[:title] == 'Pipeline name' } + + expect(name_field[:value]).to eq('Build pipeline') + end + + context 'when pipeline_name feature flag is disabled' do + before do + stub_feature_flags(pipeline_name: false) + end + + it 'does not return pipeline name' do + name_field = subject.attachments.first[:fields].find { |a| a[:title] == 'Pipeline name' } + + expect(name_field).to be nil + end + end + context "when the pipeline failed" do before do args[:object_attributes][:status] = 'failed' @@ -204,8 +227,8 @@ expect(subject.attachments.first[:title_link]).to eq("http://example.gitlab.com/-/pipelines/123") end - it "returns two attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(2) + it "returns three attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(3) end it "returns the commit message as the attachment's second field property" do @@ -232,8 +255,8 @@ ] end - it "returns four attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(4) + it "returns five attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(5) end it "returns the stage name and link to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do @@ -337,8 +360,8 @@ context "when the CI config file contains a YAML error" do let(:has_yaml_errors) { true } - it "returns three attachment fields" do - expect(subject.attachments.first[:fields].count).to eq(3) + it "returns four attachment fields" do + expect(subject.attachments.first[:fields].count).to eq(4) end it "returns the YAML error deatils as the attachment's third field property" do