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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2015-12-31 14:21:56 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-14 14:48:15 +0300
commit3de8a4620a70c886c815576dc0a30a745cbb8ccb (patch)
tree7cad0174855a338bab620068f005f78fa804fce7
parent447f56036e837fc9a9c2bcaf382d38dc513a9733 (diff)
Parse artifacts metadata stored in JSON format
-rw-r--r--app/controllers/projects/artifacts_controller.rb4
-rw-r--r--app/models/ci/build.rb11
-rw-r--r--lib/gitlab/string_path.rb12
-rw-r--r--spec/lib/gitlab/string_path_spec.rb16
4 files changed, 33 insertions, 10 deletions
diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb
index 3a112587f72..5bd0c8cd780 100644
--- a/app/controllers/projects/artifacts_controller.rb
+++ b/app/controllers/projects/artifacts_controller.rb
@@ -18,8 +18,8 @@ class Projects::ArtifactsController < Projects::ApplicationController
return render_404 unless build.artifacts?
current_path = params[:path] ? "./#{params[:path]}/" : './'
- metadata = build.artifacts_metadata_for_path(current_path)
- @path = Gitlab::StringPath.new(current_path, metadata)
+ paths, metadata = build.artifacts_metadata_for_path(current_path)
+ @path = Gitlab::StringPath.new(current_path, paths, metadata)
end
private
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 2c389bbdf61..f6783e21d90 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -350,22 +350,23 @@ module Ci
end
def artifacts_metadata_for_path(path)
- return {} unless artifacts_metadata.exists?
- metadata = []
+ return [] unless artifacts_metadata.exists?
+ paths, metadata = [], []
meta_path = path.sub(/^\.\//, '')
File.open(artifacts_metadata.path) do |file|
gzip = Zlib::GzipReader.new(file)
gzip.each_line do |line|
if line =~ %r{^#{meta_path}[^/]+/?\s}
- path, meta = line.split(' ')
- metadata << path
+ path, meta = line.split(' ')
+ paths << path
+ metadata << JSON.parse(meta)
end
end
gzip.close
end
- metadata
+ [paths, metadata]
end
private
diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb
index bfeb0f852f0..ad68a8ff2d6 100644
--- a/lib/gitlab/string_path.rb
+++ b/lib/gitlab/string_path.rb
@@ -10,10 +10,11 @@ module Gitlab
class StringPath
attr_reader :path, :universe
- def initialize(path, universe)
+ def initialize(path, universe, metadata = [])
@path = prepare(path)
- @universe = Set.new(universe.map { |entry| prepare(entry) })
- @universe.add('./')
+ @universe = universe.map { |entry| prepare(entry) }
+ @universe << './' unless @universe.include?('./')
+ @metadata = metadata
end
def to_s
@@ -84,6 +85,11 @@ module Gitlab
children.select(&:file?)
end
+ def metadata
+ index = @universe.index(@path)
+ @metadata[index]
+ end
+
def ==(other)
@path == other.path && @universe == other.universe
end
diff --git a/spec/lib/gitlab/string_path_spec.rb b/spec/lib/gitlab/string_path_spec.rb
index 8290aab7701..af46f9754ac 100644
--- a/spec/lib/gitlab/string_path_spec.rb
+++ b/spec/lib/gitlab/string_path_spec.rb
@@ -140,4 +140,20 @@ describe Gitlab::StringPath do
it { expect(subject.count).to eq 3 }
end
end
+
+ describe '#metadata' do
+ let(:universe) do
+ ['path/', 'path/file1', 'path/file2']
+ end
+
+ let(:metadata) do
+ [{ name: '/path/'}, { name: '/path/file1' }, { name: '/path/file2' }]
+ end
+
+ subject do
+ described_class.new('path/file1', universe, metadata).metadata[:name]
+ end
+
+ it { is_expected.to eq '/path/file1' }
+ end
end