2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
2019-07-31 22:56:46 +05:30
|
|
|
class GlRepository
|
|
|
|
include Singleton
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
PROJECT = RepoType.new(
|
|
|
|
name: :project,
|
2020-06-23 00:09:42 +05:30
|
|
|
access_checker_class: Gitlab::GitAccessProject,
|
2020-11-24 15:15:51 +05:30
|
|
|
repository_resolver: -> (project) { ::Repository.new(project.full_path, project, shard: project.repository_storage, disk_path: project.disk_path) }
|
2019-07-07 11:18:12 +05:30
|
|
|
).freeze
|
|
|
|
WIKI = RepoType.new(
|
|
|
|
name: :wiki,
|
|
|
|
access_checker_class: Gitlab::GitAccessWiki,
|
2020-11-24 15:15:51 +05:30
|
|
|
repository_resolver: -> (container) { ::Repository.new(container.wiki.full_path, container, shard: container.wiki.repository_storage, disk_path: container.wiki.disk_path, repo_type: WIKI) },
|
2020-06-23 00:09:42 +05:30
|
|
|
project_resolver: -> (container) { container.is_a?(Project) ? container : nil },
|
2020-03-13 15:44:24 +05:30
|
|
|
suffix: :wiki
|
|
|
|
).freeze
|
|
|
|
SNIPPET = RepoType.new(
|
|
|
|
name: :snippet,
|
|
|
|
access_checker_class: Gitlab::GitAccessSnippet,
|
2020-11-24 15:15:51 +05:30
|
|
|
repository_resolver: -> (snippet) { ::Repository.new(snippet.full_path, snippet, shard: snippet.repository_storage, disk_path: snippet.disk_path, repo_type: SNIPPET) },
|
2020-06-23 00:09:42 +05:30
|
|
|
container_class: Snippet,
|
2020-04-08 14:13:33 +05:30
|
|
|
project_resolver: -> (snippet) { snippet&.project },
|
|
|
|
guest_read_ability: :read_snippet
|
2019-07-07 11:18:12 +05:30
|
|
|
).freeze
|
2020-05-24 23:13:21 +05:30
|
|
|
DESIGN = ::Gitlab::GlRepository::RepoType.new(
|
|
|
|
name: :design,
|
|
|
|
access_checker_class: ::Gitlab::GitAccessDesign,
|
|
|
|
repository_resolver: -> (project) { ::DesignManagement::Repository.new(project) },
|
|
|
|
suffix: :design
|
|
|
|
).freeze
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
TYPES = {
|
|
|
|
PROJECT.name.to_s => PROJECT,
|
2020-03-13 15:44:24 +05:30
|
|
|
WIKI.name.to_s => WIKI,
|
2020-05-24 23:13:21 +05:30
|
|
|
SNIPPET.name.to_s => SNIPPET,
|
|
|
|
DESIGN.name.to_s => DESIGN
|
2019-07-07 11:18:12 +05:30
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def self.types
|
2019-07-31 22:56:46 +05:30
|
|
|
instance.types
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.parse(gl_repository)
|
2020-07-28 23:09:34 +05:30
|
|
|
identifier = ::Gitlab::GlRepository::Identifier.parse(gl_repository)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
repo_type = identifier.repo_type
|
|
|
|
container = identifier.container
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
[container, repo_type.project_for(container), repo_type]
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def self.default_type
|
|
|
|
PROJECT
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
def types
|
|
|
|
TYPES
|
|
|
|
end
|
|
|
|
|
|
|
|
private_class_method :instance
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|