summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-28 15:55:55 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-10-28 15:55:55 +0300
commit440604ad1ba67dcbdd23633765b9140fae4bd4b9 (patch)
tree1fecd6c598d74aec84480b6cd93b57d1bde80159
parent3095ac0ca45b044f2055cbd44654c83891245928 (diff)
downloadgitlab-ce-dz-internal-api-fullpath.tar.gz
Refactor storage path extraction from full repo pathdz-internal-api-fullpath
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/models/repository.rb14
-rw-r--r--lib/api/internal.rb7
-rw-r--r--spec/models/repository_spec.rb10
3 files changed, 25 insertions, 6 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 4ae9c20726f..e2b0093859d 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 8b5d2259b45..ccf181402f9 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -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
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 187a1bf2d79..b8204e1bf03 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -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