Commit 4618e538 authored by Jeroen van Baarsen's avatar Jeroen van Baarsen

Merge branch 'plural-second-slack' into 'master'

Changed the Slack build message to use the singular duration if necessary

## What does this MR do?

Previously, the Slack build notification would say "second(s)" even when the duration was only 1 second. This MR fixes that. This is my first time writing Ruby code and my first MR on Gitlab, so feedback is very much appreciated!

See merge request !4253
parents fbef0cc9 fcd723ed
...@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -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) v 8.9.0 (unreleased)
- Redesign navigation for project pages - Redesign navigation for project pages
- Use gitlab-shell v3.0.0 - 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) v 8.8.2 (unreleased)
- Fix Error 500 when accessing application settings due to nil disabled OAuth sign-in sources - Fix Error 500 when accessing application settings due to nil disabled OAuth sign-in sources
......
...@@ -35,8 +35,8 @@ class SlackService ...@@ -35,8 +35,8 @@ class SlackService
private private
def message def message
"#{project_link}: Commit #{commit_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} second(s)" "#{project_link}: Commit #{commit_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} #{'second'.pluralize(duration)}"
end end
def format(string) def format(string)
Slack::Notifier::LinkFormatter.format(string) Slack::Notifier::LinkFormatter.format(string)
......
...@@ -15,7 +15,7 @@ describe SlackService::BuildMessage do ...@@ -15,7 +15,7 @@ describe SlackService::BuildMessage do
commit: { commit: {
status: status, status: status,
author_name: 'hacker', author_name: 'hacker',
duration: 10, duration: duration,
}, },
} }
end end
...@@ -23,9 +23,10 @@ describe SlackService::BuildMessage do ...@@ -23,9 +23,10 @@ describe SlackService::BuildMessage do
context 'succeeded' do context 'succeeded' do
let(:status) { 'success' } let(:status) { 'success' }
let(:color) { 'good' } let(:color) { 'good' }
let(:duration) { 10 }
it 'returns a message with information about succeeded build' do it 'returns a message with information about succeeded build' do
message = '<somewhere.com|project_name>: Commit <somewhere.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker passed in 10 second(s)' message = '<somewhere.com|project_name>: Commit <somewhere.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker passed in 10 seconds'
expect(subject.pretext).to be_empty expect(subject.pretext).to be_empty
expect(subject.fallback).to eq(message) expect(subject.fallback).to eq(message)
expect(subject.attachments).to eq([text: message, color: color]) expect(subject.attachments).to eq([text: message, color: color])
...@@ -35,9 +36,23 @@ describe SlackService::BuildMessage do ...@@ -35,9 +36,23 @@ describe SlackService::BuildMessage do
context 'failed' do context 'failed' do
let(:status) { 'failed' } let(:status) { 'failed' }
let(:color) { 'danger' } let(:color) { 'danger' }
let(:duration) { 10 }
it 'returns a message with information about failed build' do it 'returns a message with information about failed build' do
message = '<somewhere.com|project_name>: Commit <somewhere.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker failed in 10 second(s)' message = '<somewhere.com|project_name>: Commit <somewhere.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <somewhere.com/commits/develop|develop> 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 = '<somewhere.com|project_name>: Commit <somewhere.com/commit/97de212e80737a608d939f648d959671fb0a0142/builds|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker failed in 1 second'
expect(subject.pretext).to be_empty expect(subject.pretext).to be_empty
expect(subject.fallback).to eq(message) expect(subject.fallback).to eq(message)
expect(subject.attachments).to eq([text: message, color: color]) expect(subject.attachments).to eq([text: message, color: color])
......
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