Class: PactBroker::Client::Matrix::AbbreviateVersionNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/client/matrix/abbreviate_version_number.rb

Constant Summary collapse

SEMVER_REGEX =
/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/
SHA1_REGEX =
/[A-Za-z0-9]{40}/

Class Method Summary collapse

Class Method Details

.call(version_number) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pact_broker/client/matrix/abbreviate_version_number.rb', line 10

def call version_number
  return unless 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 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

  version_number
end