Commit d32086eb authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'properly-pluralize-offset-hours-in-teammate-danger' into 'master'

Pluralize offset hours in Teammate::Danger

See merge request gitlab-org/gitlab!36283
parents a1c1c25f 19bce20e
...@@ -72,8 +72,9 @@ module Gitlab ...@@ -72,8 +72,9 @@ module Gitlab
return "same timezone as `@#{author.username}`" if diff.zero? return "same timezone as `@#{author.username}`" if diff.zero?
ahead_or_behind = diff < 0 ? 'behind' : 'ahead' ahead_or_behind = diff < 0 ? 'behind' : 'ahead'
pluralized_hours = pluralize(diff.abs, 'hour', 'hours')
"#{diff.abs} hours #{ahead_or_behind} `@#{author.username}`" "#{pluralized_hours} #{ahead_or_behind} `@#{author.username}`"
end end
def has_capability?(project, category, kind, labels) def has_capability?(project, category, kind, labels)
...@@ -95,6 +96,12 @@ module Gitlab ...@@ -95,6 +96,12 @@ module Gitlab
def capabilities(project) def capabilities(project)
Array(projects.fetch(project, [])) Array(projects.fetch(project, []))
end end
def pluralize(count, singular, plural)
word = count == 1 || count.to_s =~ /^1(\.0+)?$/ ? singular : plural
"#{count || 0} #{word}"
end
end end
end end
end end
...@@ -178,6 +178,8 @@ RSpec.describe Gitlab::Danger::Teammate do ...@@ -178,6 +178,8 @@ RSpec.describe Gitlab::Danger::Teammate do
-10 | 2 | "12 hours behind `@mario`" -10 | 2 | "12 hours behind `@mario`"
2 | 4 | "2 hours behind `@mario`" 2 | 4 | "2 hours behind `@mario`"
4 | 2 | "2 hours ahead `@mario`" 4 | 2 | "2 hours ahead `@mario`"
2 | 3 | "1 hour behind `@mario`"
3 | 2 | "1 hour ahead `@mario`"
2 | 2 | "same timezone as `@mario`" 2 | 2 | "same timezone as `@mario`"
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