Commit 57668696 authored by Balasankar "Balu" C's avatar Balasankar "Balu" C

Make VersionFetcher class DRY

Signed-off-by: Balasankar "Balu" C's avatarBalasankar "Balu" C <balasankar@gitlab.com>
parent 04431c92
......@@ -4,42 +4,44 @@ require 'open-uri'
require 'uri'
class VersionFetcher
class << self
def initialize(version, repo)
@version = Version.new(version)
@repo = repo
end
# GitLab Shell Version
def gitlab_shell(version, repo)
return version if version == 'master'
# GitLab Shell Version
def gitlab_shell
return @version if @version == 'master'
url = "#{repo}/raw/#{ref(version)}/GITLAB_SHELL_VERSION"
new_version = URI.parse(url).read.strip
$stdout.puts "# Shell appVersion: #{new_version}"
new_version
end
url = "#{@repo}/raw/#{ref(@version)}/GITLAB_SHELL_VERSION"
new_version = URI.parse(url).read.strip
$stdout.puts "# Shell appVersion: #{new_version}"
new_version
end
# Gitaly Version
def gitaly(version, repo)
return version if version == 'master'
# Gitaly Version
def gitaly
return @version if @version == 'master'
url = "#{repo}/raw/#{ref(version)}/GITALY_SERVER_VERSION"
new_version = URI.parse(url).read.strip
$stdout.puts "# Gitaly appVersion: #{new_version}"
new_version
end
url = "#{@repo}/raw/#{ref(@version)}/GITALY_SERVER_VERSION"
new_version = URI.parse(url).read.strip
$stdout.puts "# Gitaly appVersion: #{new_version}"
new_version
end
def fetch(chart_name, ref, repo)
chart_name = chart_name.tr('-', '_').to_sym
return ref unless respond_to?(chart_name)
Version.new(send(chart_name, ref, repo)) if ref
end
def fetch(chart_name)
chart_name = chart_name.tr('-', '_').to_sym
return @version unless respond_to?(chart_name)
Version.new(send(chart_name)) if @version
end
private
private
def ref(version)
if version.valid?
version.tag(ee: true)
else
version.to_s
end
def ref(version)
if version.valid?
version.tag(ee: true)
else
version.to_s
end
end
end
......@@ -162,7 +162,8 @@ class VersionUpdater
def populate_subchart_versions
@subchart_versions = subcharts.map do |sub_chart|
[ sub_chart, VersionFetcher.fetch(sub_chart.name, @app_version, @options.gitlab_repo) ]
version_fetcher = VersionFetcher.new(@app_version, @options.gitlab_repo)
[ sub_chart, version_fetcher.fetch(sub_chart.name) ]
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment