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

54 lines
1.1 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,
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-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]
subject_id = type&.fetch_id(gl_repository)
unless subject_id
2017-08-17 22:00:37 +05:30
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
end
2019-07-07 11:18:12 +05:30
project = Project.find_by_id(subject_id)
[project, type]
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')