debian-mirror-gitlab/lib/gitlab/gl_repository.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.3 KiB
Ruby
Raw Normal View History

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
2021-01-03 14:25:43 +05:30
# TODO: Refactor these constants into proper classes
# https://gitlab.com/gitlab-org/gitlab/-/issues/259008
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,
2021-01-03 14:25:43 +05:30
repository_resolver: -> (container) do
wiki = container.is_a?(Wiki) ? container : container.wiki # Also allow passing a Project, Group, or Geo::DeletedProject
::Repository.new(wiki.full_path, wiki, shard: wiki.repository_storage, disk_path: wiki.disk_path, repo_type: WIKI)
end,
container_class: ProjectWiki,
project_resolver: -> (wiki) { wiki.try(:project) },
2021-02-22 17:27:13 +05:30
guest_read_ability: :download_wiki_code,
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,
2023-07-09 08:55:56 +05:30
repository_resolver: -> (project) { project.design_management_repository.repository },
suffix: :design,
container_class: DesignManagement::Repository
2020-05-24 23:13:21 +05:30
).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