Skip to content

Commit

Permalink
fix(matrix): prevent long version names overlfow the table
Browse files Browse the repository at this point in the history
  • Loading branch information
ertrzyiks committed Oct 5, 2021
1 parent 145bb37 commit cf2cd04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/pact_broker/versions/abbreviate_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module Versions
class AbbreviateNumber

def self.call version_number
if version_number
version_number.gsub(/[A-Za-z0-9]{40}/) do | val |
val[0..6]
end
return version_number unless version_number

# hard limit of max 50 characters
return version_number[0...49] + "…" if version_number.length > 50

version_number.gsub(/[A-Za-z0-9]{40}/) do | val |
val[0..6]
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/pact_broker/versions/abbreviate_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Versions
["202326572516dea6998a7f311fcaa161c0768fc2", "2023265"],
["1.2.3+areallyreallyreallylongexplanation", "1.2.3+areallyreallyreallylongexplanation"],
["2516dea6998a7f", "2516dea6998a7f"],
["1.2.3+202326572516dea6998a7f311fcaa161c0768fc2", "1.2.3+2023265"]
["1.2.3+202326572516dea6998a7f311fcaa161c0768fc2", "1.2.3+2023265"],
["this-is-very-long-text-this-is-very-long-text-this-is-very-long-text-this-is-very-long-text", "this-is-very-long-text-this-is-very-long-text-thi…"]
]

TEST_CASES.each do |(input, output)|
Expand Down

0 comments on commit cf2cd04

Please sign in to comment.