2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
module Gitlab
|
2019-04-30 05:37:07 -04:00
|
|
|
class GlRepository
|
|
|
|
include Singleton
|
|
|
|
|
2019-03-18 12:51:11 -04:00
|
|
|
PROJECT = RepoType.new(
|
|
|
|
name: :project,
|
|
|
|
access_checker_class: Gitlab::GitAccess,
|
|
|
|
repository_accessor: -> (project) { project.repository }
|
|
|
|
).freeze
|
|
|
|
WIKI = RepoType.new(
|
|
|
|
name: :wiki,
|
|
|
|
access_checker_class: Gitlab::GitAccessWiki,
|
|
|
|
repository_accessor: -> (project) { project.wiki.repository }
|
|
|
|
).freeze
|
|
|
|
|
|
|
|
TYPES = {
|
|
|
|
PROJECT.name.to_s => PROJECT,
|
|
|
|
WIKI.name.to_s => WIKI
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def self.types
|
2019-04-30 05:37:07 -04:00
|
|
|
instance.types
|
2017-05-03 17:07:54 -04:00
|
|
|
end
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
def self.parse(gl_repository)
|
2019-03-18 12:51:11 -04:00
|
|
|
type_name, _id = gl_repository.split('-').first
|
|
|
|
type = types[type_name]
|
|
|
|
subject_id = type&.fetch_id(gl_repository)
|
|
|
|
|
|
|
|
unless subject_id
|
2017-04-28 12:52:09 -04:00
|
|
|
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
|
|
|
|
end
|
|
|
|
|
2019-03-18 12:51:11 -04:00
|
|
|
project = Project.find_by_id(subject_id)
|
2017-04-28 12:52:09 -04:00
|
|
|
|
2019-03-18 12:51:11 -04:00
|
|
|
[project, type]
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
2019-04-05 06:51:42 -04:00
|
|
|
|
|
|
|
def self.default_type
|
|
|
|
PROJECT
|
|
|
|
end
|
2019-04-30 05:37:07 -04:00
|
|
|
|
|
|
|
def types
|
|
|
|
TYPES
|
|
|
|
end
|
|
|
|
|
|
|
|
private_class_method :instance
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Gitlab::GlRepository.prepend_if_ee('::EE::Gitlab::GlRepository')
|