Commit fcd723ed authored by Aran Koning's avatar Aran Koning

Seconds plural slack

parent baa9c660
...@@ -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,7 +35,7 @@ class SlackService ...@@ -35,7 +35,7 @@ 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)
......
...@@ -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