Skip to content

Commit

Permalink
chore: fixup ruby 2.2 support (pact-foundation#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
konalegi authored Aug 15, 2021
1 parent 3a75963 commit 2282622
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/pact_broker/client/matrix/abbreviate_version_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class << self
def call version_number
return unless version_number

return replace_all_git_sha(version_number) if [SEMVER_REGEX, SHA1_REGEX].all?{|r| r.match?(version_number) }
return replace_all_git_sha(version_number) if [SEMVER_REGEX, SHA1_REGEX].all?{|r| regex_match?(r, version_number) }

return replace_all_git_sha(version_number) if Regexp.new("\\A#{SHA1_REGEX.source}\\z").match?(version_number)
return replace_all_git_sha(version_number) if regex_match?(Regexp.new("\\A#{SHA1_REGEX.source}\\z"), version_number)

# Trim to some meaningful value in case we couldn't match anything, just not to mess with the output
return version_number[0...60] + '...' if version_number.length > 60
Expand All @@ -22,6 +22,11 @@ def call version_number

private

# To support ruby2.2
def regex_match?(regex, value)
!regex.match(value).nil?
end

def replace_all_git_sha(version)
version.gsub(SHA1_REGEX) { |val| val[0...7] + '...' }
end
Expand Down

0 comments on commit 2282622

Please sign in to comment.