summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb25
-rw-r--r--lib/api/entities/email.rb9
-rw-r--r--lib/api/entities/identity.rb9
-rw-r--r--lib/api/entities/membership.rb14
-rw-r--r--lib/api/entities/user_status.rb13
-rw-r--r--lib/api/helpers/internal_helpers.rb2
-rw-r--r--lib/gitlab/gl_repository.rb12
-rw-r--r--lib/gitlab/gl_repository/repo_type.rb43
-rw-r--r--lib/gitlab/repo_path.rb14
-rw-r--r--lib/gitlab/workhorse.rb2
10 files changed, 97 insertions, 46 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 62eb30f2edf..f68365e6325 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -2,31 +2,6 @@
module API
module Entities
- class Membership < Grape::Entity
- expose :source_id
- expose :source_name do |member|
- member.source.name
- end
- expose :source_type
- expose :access_level
- end
-
- class Identity < Grape::Entity
- expose :provider, :extern_uid
- end
-
- class UserStatus < Grape::Entity
- expose :emoji
- expose :message
- expose :message_html do |entity|
- MarkupHelper.markdown_field(entity, :message)
- end
- end
-
- class Email < Grape::Entity
- expose :id, :email
- end
-
class Hook < Grape::Entity
expose :id, :url, :created_at, :push_events, :tag_push_events, :merge_requests_events, :repository_update_events
expose :enable_ssl_verification
diff --git a/lib/api/entities/email.rb b/lib/api/entities/email.rb
new file mode 100644
index 00000000000..5ba425def3d
--- /dev/null
+++ b/lib/api/entities/email.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Email < Grape::Entity
+ expose :id, :email
+ end
+ end
+end
diff --git a/lib/api/entities/identity.rb b/lib/api/entities/identity.rb
new file mode 100644
index 00000000000..8969a0256c7
--- /dev/null
+++ b/lib/api/entities/identity.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Identity < Grape::Entity
+ expose :provider, :extern_uid
+ end
+ end
+end
diff --git a/lib/api/entities/membership.rb b/lib/api/entities/membership.rb
new file mode 100644
index 00000000000..2e3e6a0d8ba
--- /dev/null
+++ b/lib/api/entities/membership.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Membership < Grape::Entity
+ expose :source_id
+ expose :source_name do |member|
+ member.source.name
+ end
+ expose :source_type
+ expose :access_level
+ end
+ end
+end
diff --git a/lib/api/entities/user_status.rb b/lib/api/entities/user_status.rb
new file mode 100644
index 00000000000..9bc4cbf240f
--- /dev/null
+++ b/lib/api/entities/user_status.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserStatus < Grape::Entity
+ expose :emoji
+ expose :message
+ expose :message_html do |entity|
+ MarkupHelper.markdown_field(entity, :message)
+ end
+ end
+ end
+end
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index cc9d45dcae4..b17cb2633d8 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -116,7 +116,7 @@ module API
# Project id to pass between components that don't share/don't have
# access to the same filesystem mounts
def gl_repository
- repo_type.identifier_for_repositorable(project)
+ repo_type.identifier_for_container(project)
end
def gl_project_path
diff --git a/lib/gitlab/gl_repository.rb b/lib/gitlab/gl_repository.rb
index 99bf4258c07..347084e779c 100644
--- a/lib/gitlab/gl_repository.rb
+++ b/lib/gitlab/gl_repository.rb
@@ -7,12 +7,13 @@ module Gitlab
PROJECT = RepoType.new(
name: :project,
access_checker_class: Gitlab::GitAccess,
- repository_accessor: -> (project) { project.repository }
+ repository_resolver: -> (project) { project.repository }
).freeze
WIKI = RepoType.new(
name: :wiki,
access_checker_class: Gitlab::GitAccessWiki,
- repository_accessor: -> (project) { project.wiki.repository }
+ repository_resolver: -> (project) { project.wiki.repository },
+ suffix: :wiki
).freeze
TYPES = {
@@ -27,15 +28,14 @@ module Gitlab
def self.parse(gl_repository)
type_name, _id = gl_repository.split('-').first
type = types[type_name]
- subject_id = type&.fetch_id(gl_repository)
- unless subject_id
+ unless type
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
end
- project = Project.find_by_id(subject_id)
+ container = type.fetch_container!(gl_repository)
- [project, type]
+ [container, type]
end
def self.default_type
diff --git a/lib/gitlab/gl_repository/repo_type.rb b/lib/gitlab/gl_repository/repo_type.rb
index 6918344aa40..20a0dd48468 100644
--- a/lib/gitlab/gl_repository/repo_type.rb
+++ b/lib/gitlab/gl_repository/repo_type.rb
@@ -5,16 +5,25 @@ module Gitlab
class RepoType
attr_reader :name,
:access_checker_class,
- :repository_accessor
+ :repository_resolver,
+ :container_resolver,
+ :suffix
- def initialize(name:, access_checker_class:, repository_accessor:)
+ def initialize(
+ name:,
+ access_checker_class:,
+ repository_resolver:,
+ container_resolver: default_container_resolver,
+ suffix: nil)
@name = name
@access_checker_class = access_checker_class
- @repository_accessor = repository_accessor
+ @repository_resolver = repository_resolver
+ @container_resolver = container_resolver
+ @suffix = suffix
end
- def identifier_for_repositorable(repositorable)
- "#{name}-#{repositorable.id}"
+ def identifier_for_container(container)
+ "#{name}-#{container.id}"
end
def fetch_id(identifier)
@@ -22,6 +31,14 @@ module Gitlab
match[:id] if match
end
+ def fetch_container!(identifier)
+ id = fetch_id(identifier)
+
+ raise ArgumentError, "Invalid GL Repository \"#{identifier}\"" unless id
+
+ container_resolver.call(id)
+ end
+
def wiki?
self == WIKI
end
@@ -31,11 +48,21 @@ module Gitlab
end
def path_suffix
- project? ? "" : ".#{name}"
+ suffix ? ".#{suffix}" : ''
end
- def repository_for(repositorable)
- repository_accessor.call(repositorable)
+ def repository_for(container)
+ repository_resolver.call(container)
+ end
+
+ def valid?(repository_path)
+ repository_path.end_with?(path_suffix)
+ end
+
+ private
+
+ def default_container_resolver
+ -> (id) { Project.find_by_id(id) }
end
end
end
diff --git a/lib/gitlab/repo_path.rb b/lib/gitlab/repo_path.rb
index 1baa2a9e461..e8c749cac14 100644
--- a/lib/gitlab/repo_path.rb
+++ b/lib/gitlab/repo_path.rb
@@ -4,8 +4,9 @@ module Gitlab
module RepoPath
NotFoundError = Class.new(StandardError)
- def self.parse(repo_path)
- project_path = repo_path.sub(/\.git\z/, '').sub(%r{\A/}, '')
+ def self.parse(path)
+ repo_path = path.sub(/\.git\z/, '').sub(%r{\A/}, '')
+ redirected_path = nil
# Detect the repo type based on the path, the first one tried is the project
# type, which does not have a suffix.
@@ -14,10 +15,13 @@ module Gitlab
# type.
# We'll always try to find a project with an empty suffix (for the
# `Gitlab::GlRepository::PROJECT` type.
- next unless project_path.end_with?(type.path_suffix)
+ next unless type.valid?(repo_path)
- project, was_redirected = find_project(project_path.chomp(type.path_suffix))
- redirected_path = project_path if was_redirected
+ # Removing the suffix (.wiki, .design, ...) from the project path
+ full_path = repo_path.chomp(type.path_suffix)
+
+ project, was_redirected = find_project(full_path)
+ redirected_path = repo_path if was_redirected
# If we found a matching project, then the type was matched, no need to
# continue looking.
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index e377c690d51..8696e23cbc7 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -24,7 +24,7 @@ module Gitlab
attrs = {
GL_ID: Gitlab::GlId.gl_id(user),
- GL_REPOSITORY: repo_type.identifier_for_repositorable(repository.project),
+ GL_REPOSITORY: repo_type.identifier_for_container(repository.project),
GL_USERNAME: user&.username,
ShowAllRefs: show_all_refs,
Repository: repository.gitaly_repository.to_h,