Commit 62f7edde authored by DJ Mountney's avatar DJ Mountney

Merge branch '1197-configurable-gitlab-repo-url' into 'master'

Make URL for GitLab repo used by manage versions script configurable

Closes #1197

See merge request charts/gitlab!711
parents 0b03408d 474d430f
Pipeline #50847833 passed with stages
in 35 minutes and 50 seconds
......@@ -4,40 +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)
return version if version == 'master'
# GitLab Shell Version
def gitlab_shell
return @version if @version == 'master'
new_version = URI.parse("https://gitlab.com/gitlab-org/gitlab-ee/raw/#{ref(version)}/GITLAB_SHELL_VERSION").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)
return version if version == 'master'
# Gitaly Version
def gitaly
return @version if @version == 'master'
new_version = URI.parse("https://gitlab.com/gitlab-org/gitlab-ee/raw/#{ref(version)}/GITALY_SERVER_VERSION").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)
chart_name = chart_name.tr('-', '_').to_sym
return ref unless respond_to?(chart_name)
Version.new(send(chart_name, ref)) 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
......@@ -9,6 +9,7 @@ require_relative 'lib/version_mapping'
Options = Struct.new(
:working_dir,
:gitlab_repo,
:app_version,
:chart_version,
:include_subcharts,
......@@ -23,6 +24,7 @@ class VersionOptionsParser
# defaults
options.working_dir = Dir.pwd
options.include_subcharts = false
options.gitlab_repo = "https://gitlab.com/gitlab-org/gitlab-ee"
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options] \n\n"
......@@ -39,6 +41,10 @@ class VersionOptionsParser
options.working_dir = value
end
opts.on("--gitlab-repo [string]", String, "URL of GitLab repo to fetch component versions from") do |value|
options.gitlab_repo = value
end
opts.on("-a", "--include-subcharts", "Attempt to update subcharts as well") do |value|
options.include_subcharts = value
end
......@@ -156,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) ]
version_fetcher = VersionFetcher.new(@app_version, @options.gitlab_repo)
[ sub_chart, version_fetcher.fetch(sub_chart.name) ]
end
end
......
require 'spec_helper'
require_relative '../../../scripts/lib/version_fetcher.rb'
describe VersionFetcher do
let(:repo_url) { 'https://gitlab.com/gitlab-org/gitlab-ce' }
let(:uri_response) { URI.parse(repo_url) }
let(:version_fetcher) { VersionFetcher.new('v11.8.0', repo_url) }
before do
allow(URI).to receive(:parse).and_return(uri_response)
allow(uri_response).to receive(:read).and_return("1.2.3\n")
allow(version_fetcher).to receive(:gitlab_shell).and_call_original
allow(version_fetcher).to receive(:gitaly).and_call_original
end
describe '#gitlab_shell' do
it 'returns correct value' do
expect(version_fetcher.gitlab_shell).to eq('1.2.3')
end
describe '#gitaly' do
it 'returns correct value' do
expect(version_fetcher.fetch('gitaly')).to eq('1.2.3')
end
end
describe '#fetch' do
it 'callse subchart methods' do
expect(version_fetcher).to receive(:gitlab_shell)
expect(version_fetcher).to receive(:gitaly)
version_fetcher.fetch('gitlab-shell')
version_fetcher.fetch('gitaly')
end
end
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