Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
commit5afcbe03ead9ada87621888a31a62652b10a7e4f (patch)
tree9918b67a0d0f0bafa6542e839a8be37adf73102d /lib/gitlab/gl_repository
parentc97c0201564848c1f53226fe19d71fdcc472f7d0 (diff)
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'lib/gitlab/gl_repository')
-rw-r--r--lib/gitlab/gl_repository/repo_type.rb32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/gitlab/gl_repository/repo_type.rb b/lib/gitlab/gl_repository/repo_type.rb
index 26b0ff86f67..0c0d9bafa85 100644
--- a/lib/gitlab/gl_repository/repo_type.rb
+++ b/lib/gitlab/gl_repository/repo_type.rb
@@ -2,6 +2,18 @@
module Gitlab
class GlRepository
+ class ContainerClassMismatchError < StandardError
+ def initialize(container_class, repo_type)
+ @container_class = container_class
+ @repo_type = repo_type
+ end
+
+ def message
+ "Expected container class to be #{@repo_type.container_class} for " \
+ "repo type #{@repo_type.name}, but found #{@container_class} instead."
+ end
+ end
+
class RepoType
attr_reader :name,
:access_checker_class,
@@ -53,13 +65,14 @@ module Gitlab
end
def repository_for(container)
+ check_container(container)
return unless container
- repository_resolver.call(select_container(container))
+ repository_resolver.call(container)
end
def project_for(container)
- return select_container(container) unless project_resolver
+ return container unless project_resolver
project_resolver.call(container)
end
@@ -74,13 +87,20 @@ module Gitlab
private
- def select_container(container)
- container.is_a?(::DesignManagement::Repository) ? container.project : container
- end
-
def default_container_class
Project
end
+
+ def check_container(container)
+ # Don't check container for wiki or project because these repo types
+ # accept several container types.
+ return if wiki? || project?
+
+ return unless container.present? && container_class.present?
+ return if container.is_a?(container_class)
+
+ raise ContainerClassMismatchError.new(container.class.name, self)
+ end
end
end
end