Commit 440604ad authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor storage path extraction from full repo path

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 3095ac0c
......@@ -11,6 +11,20 @@ class Repository
attr_accessor :path_with_namespace, :project
def self.storages
Gitlab.config.repositories.storages
end
def self.remove_storage_from_path(repo_path)
storages.find do |_, storage_path|
if repo_path.start_with?(storage_path)
return repo_path.sub(storage_path, '')
end
end
repo_path
end
def initialize(path_with_namespace, project)
@path_with_namespace = path_with_namespace
@project = project
......
......@@ -20,12 +20,7 @@ module API
def project_path
@project_path ||= begin
project_path = params[:project].sub(/\.git\z/, '')
Gitlab.config.repositories.storages.each do |_, storage_path|
project_path.sub!(storage_path, '')
end
project_path
Repository.remove_storage_from_path(project_path)
end
end
......
......@@ -1472,4 +1472,14 @@ describe Repository, models: true do
end.to raise_error(Repository::CommitError)
end
end
describe '#remove_storage_from_path' do
let(:storage_path) { project.repository_storage_path }
let(:project_path) { project.path_with_namespace }
let(:full_path) { File.join(storage_path, project_path) }
it { expect(Repository.remove_storage_from_path(full_path)).to eq(project_path) }
it { expect(Repository.remove_storage_from_path(project_path)).to eq(project_path) }
it { expect(Repository.remove_storage_from_path(storage_path)).to eq('') }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment