debian-mirror-gitlab/app/services/packages/composer/version_parser_service.rb

34 lines
767 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Composer
class VersionParserService
def initialize(tag_name: nil, branch_name: nil)
@tag_name, @branch_name = tag_name, branch_name
end
def execute
if @tag_name.present?
2021-01-29 00:20:46 +05:30
@tag_name.delete_prefix('v')
2020-07-28 23:09:34 +05:30
elsif @branch_name.present?
branch_sufix_or_prefix(@branch_name.match(Gitlab::Regex.composer_package_version_regex))
end
end
private
def branch_sufix_or_prefix(match)
if match
if match.captures[1] == '.x'
match.captures[0] + '-dev'
else
match.captures[0] + '.x-dev'
end
else
"dev-#{@branch_name}"
end
end
end
end
end