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

61 lines
1.4 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
2019-07-07 11:18:12 +05:30
PROJECT = RepoType.new(
name: :project,
access_checker_class: Gitlab::GitAccess,
2020-03-09 13:42:32 +05:30
repository_resolver: -> (project) { project.repository }
2019-07-07 11:18:12 +05:30
).freeze
WIKI = RepoType.new(
name: :wiki,
access_checker_class: Gitlab::GitAccessWiki,
2020-03-09 13:42:32 +05:30
repository_resolver: -> (project) { project.wiki.repository },
suffix: :wiki
).freeze
SNIPPET = RepoType.new(
name: :snippet,
access_checker_class: Gitlab::GitAccessSnippet,
repository_resolver: -> (snippet) { snippet.repository },
container_resolver: -> (id) { Snippet.find_by_id(id) }
2019-07-07 11:18:12 +05:30
).freeze
TYPES = {
PROJECT.name.to_s => PROJECT,
2020-03-09 13:42:32 +05:30
WIKI.name.to_s => WIKI,
SNIPPET.name.to_s => SNIPPET
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)
2019-07-07 11:18:12 +05:30
type_name, _id = gl_repository.split('-').first
type = types[type_name]
2020-03-09 13:42:32 +05:30
unless type
2017-08-17 22:00:37 +05:30
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
end
2020-03-09 13:42:32 +05:30
container = type.fetch_container!(gl_repository)
2019-07-07 11:18:12 +05:30
2020-03-09 13:42:32 +05:30
[container, 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
2019-12-04 20:38:33 +05:30
Gitlab::GlRepository.prepend_if_ee('::EE::Gitlab::GlRepository')