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

44 lines
964 B
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
module GlRepository
2019-05-18 00:54:41 +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
TYPES
2017-08-17 22:00:37 +05:30
end
def self.parse(gl_repository)
2019-05-18 00:54:41 +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-05-18 00:54:41 +05:30
project = Project.find_by_id(subject_id)
[project, type]
end
2017-08-17 22:00:37 +05:30
2019-05-18 00:54:41 +05:30
def self.default_type
PROJECT
2017-08-17 22:00:37 +05:30
end
end
end