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)
|
2021-04-29 21:17:54 +05:30
|
|
|
@tag_name = tag_name
|
|
|
|
@branch_name = branch_name
|
2020-07-28 23:09:34 +05:30
|
|
|
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?
|
2021-11-11 11:23:49 +05:30
|
|
|
branch_suffix_or_prefix(@branch_name.match(Gitlab::Regex.composer_package_version_regex))
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def branch_suffix_or_prefix(match)
|
2020-07-28 23:09:34 +05:30
|
|
|
if match
|
2021-11-11 11:23:49 +05:30
|
|
|
captures = match.captures.reject(&:blank?)
|
|
|
|
if captures[-1] == '.x'
|
|
|
|
captures[0] + '-dev'
|
2020-07-28 23:09:34 +05:30
|
|
|
else
|
2021-11-11 11:23:49 +05:30
|
|
|
captures[0] + '.x-dev'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
else
|
|
|
|
"dev-#{@branch_name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|