Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/components/instance_path.rb')
-rw-r--r--lib/gitlab/ci/components/instance_path.rb57
1 files changed, 12 insertions, 45 deletions
diff --git a/lib/gitlab/ci/components/instance_path.rb b/lib/gitlab/ci/components/instance_path.rb
index 17c784c4d54..551284d9099 100644
--- a/lib/gitlab/ci/components/instance_path.rb
+++ b/lib/gitlab/ci/components/instance_path.rb
@@ -7,19 +7,17 @@ module Gitlab
include Gitlab::Utils::StrongMemoize
LATEST_VERSION_KEYWORD = '~latest'
- TEMPLATES_DIR = 'templates'
def self.match?(address)
address.include?('@') && address.start_with?(Settings.gitlab_ci['component_fqdn'])
end
- attr_reader :host, :project_file_path
+ attr_reader :host
- def initialize(address:, content_filename:)
+ def initialize(address:)
@full_path, @version = address.to_s.split('@', 2)
- @content_filename = content_filename
@host = Settings.gitlab_ci['component_fqdn']
- @project_file_path = nil
+ @component_project = ::Ci::Catalog::ComponentsProject.new(project, sha)
end
def fetch_content!(current_user:)
@@ -28,7 +26,7 @@ module Gitlab
raise Gitlab::Access::AccessDeniedError unless Ability.allowed?(current_user, :download_code, project)
- content(simple_template_path) || content(complex_template_path) || content(legacy_template_path)
+ @component_project.fetch_component(component_name)
end
def project
@@ -46,16 +44,7 @@ module Gitlab
private
- attr_reader :version, :path
-
- def instance_path
- @full_path.delete_prefix(host)
- end
-
- def component_path
- instance_path.delete_prefix(project.full_path).delete_prefix('/')
- end
- strong_memoize_attr :component_path
+ attr_reader :version
# Given a path like "my-org/sub-group/the-project/path/to/component"
# find the project "my-org/sub-group/the-project" by looking at all possible paths.
@@ -65,45 +54,23 @@ module Gitlab
while index = path.rindex('/') # find index of last `/` in a path
possible_paths << (path = path[0..index - 1])
end
-
# remove shortest path as it is group
possible_paths.pop
::Project.where_full_path_in(possible_paths).take # rubocop: disable CodeReuse/ActiveRecord
end
- def latest_version_sha
- project.releases.latest&.sha
- end
-
- # A simple template consists of a single file
- def simple_template_path
- # Extract this line and move to fetch_content once we remove legacy fetching
- return unless templates_dir_exists? && component_path.index('/').nil?
-
- @project_file_path = File.join(TEMPLATES_DIR, "#{component_path}.yml")
- end
-
- # A complex template is directory-based and may consist of multiple files.
- # Given a path like "my-org/sub-group/the-project/templates/component"
- # returns the entry point path: "templates/component/template.yml".
- def complex_template_path
- # Extract this line and move to fetch_content once we remove legacy fetching
- return unless templates_dir_exists? && component_path.index('/').nil?
-
- @project_file_path = File.join(TEMPLATES_DIR, component_path, @content_filename)
- end
-
- def legacy_template_path
- @project_file_path = File.join(component_path, @content_filename).delete_prefix('/')
+ def instance_path
+ @full_path.delete_prefix(host)
end
- def templates_dir_exists?
- project.repository.tree.trees.map(&:name).include?(TEMPLATES_DIR)
+ def component_name
+ instance_path.delete_prefix(project.full_path).delete_prefix('/')
end
+ strong_memoize_attr :component_name
- def content(path)
- project.repository.blob_data_at(sha, path)
+ def latest_version_sha
+ project.releases.latest&.sha
end
end
end