Skip to content

Commit

Permalink
fix(matrix): prevent long version names overlfow the table (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
ertrzyiks authored Oct 7, 2021
1 parent 80b1895 commit 3c27955
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 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,14 @@ 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
version_length = version_number.length
return version_number[0...39] + "…" + version_number[version_length - 10...version_length] if version_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-lon…-long-text"]
]

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

0 comments on commit 3c27955

Please sign in to comment.