diff --git a/CHANGELOG b/CHANGELOG index a79c3048b79..104f41e6034 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.9.0 (unreleased) - Redesign navigation for project pages - Use gitlab-shell v3.0.0 + - Changed the Slack build message to use the singular duration if necessary (Aran Koning) v 8.8.2 (unreleased) - Fix Error 500 when accessing application settings due to nil disabled OAuth sign-in sources diff --git a/app/models/project_services/slack_service/build_message.rb b/app/models/project_services/slack_service/build_message.rb index c124cad4afd..69c21b3fc38 100644 --- a/app/models/project_services/slack_service/build_message.rb +++ b/app/models/project_services/slack_service/build_message.rb @@ -35,8 +35,8 @@ class SlackService private def message - "#{project_link}: Commit #{commit_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} second(s)" - end + "#{project_link}: Commit #{commit_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} #{'second'.pluralize(duration)}" + end def format(string) Slack::Notifier::LinkFormatter.format(string) diff --git a/spec/models/project_services/slack_service/build_message_spec.rb b/spec/models/project_services/slack_service/build_message_spec.rb index 621c83c0cda..7fcfdf0eacd 100644 --- a/spec/models/project_services/slack_service/build_message_spec.rb +++ b/spec/models/project_services/slack_service/build_message_spec.rb @@ -15,7 +15,7 @@ describe SlackService::BuildMessage do commit: { status: status, author_name: 'hacker', - duration: 10, + duration: duration, }, } end @@ -23,9 +23,10 @@ describe SlackService::BuildMessage do context 'succeeded' do let(:status) { 'success' } let(:color) { 'good' } - + let(:duration) { 10 } + it 'returns a message with information about succeeded build' do - message = ': Commit of branch by hacker passed in 10 second(s)' + message = ': Commit of branch by hacker passed in 10 seconds' expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color]) @@ -35,9 +36,23 @@ describe SlackService::BuildMessage do context 'failed' do let(:status) { 'failed' } let(:color) { 'danger' } + let(:duration) { 10 } it 'returns a message with information about failed build' do - message = ': Commit of branch by hacker failed in 10 second(s)' + message = ': Commit of branch by hacker failed in 10 seconds' + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end + + describe '#seconds_name' do + let(:status) { 'failed' } + let(:color) { 'danger' } + let(:duration) { 1 } + + it 'returns seconds as singular when there is only one' do + message = ': Commit of branch by hacker failed in 1 second' expect(subject.pretext).to be_empty expect(subject.fallback).to eq(message) expect(subject.attachments).to eq([text: message, color: color])