Commit be764a3a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Minor improvements in build arfifacts browser

Added also a `Gitlab::Ci::Build::Artifacts::Metadata::ParserError`
exception class.
parent 76e578fd
...@@ -6,6 +6,6 @@ ...@@ -6,6 +6,6 @@
%td %td
= number_to_human_size(file.metadata[:size], precision: 2) = number_to_human_size(file.metadata[:size], precision: 2)
%td %td
= link_to file_namespace_project_build_artifacts_path(path: file.path), = link_to file_namespace_project_build_artifacts_path(@project.namespace, @project, @build, path: file.path),
class: 'btn btn-xs btn-default artifact-download' do class: 'btn btn-xs btn-default artifact-download' do
= icon('download') = icon('download')
...@@ -609,8 +609,8 @@ Rails.application.routes.draw do ...@@ -609,8 +609,8 @@ Rails.application.routes.draw do
resource :artifacts, only: [] do resource :artifacts, only: [] do
get :download get :download
get :browse, path: 'browse(/*path)', action: :browse, format: false get :browse, path: 'browse(/*path)', format: false
get :file, path: 'file/*path', action: :file, format: false get :file, path: 'file/*path', format: false
end end
end end
......
...@@ -6,6 +6,8 @@ module Gitlab ...@@ -6,6 +6,8 @@ module Gitlab
module Build module Build
module Artifacts module Artifacts
class Metadata class Metadata
class ParserError < StandardError; end
VERSION_PATTERN = /^[\w\s]+(\d+\.\d+\.\d+)/ VERSION_PATTERN = /^[\w\s]+(\d+\.\d+\.\d+)/
INVALID_PATH_PATTERN = %r{(^\.?\.?/)|(/\.?\.?/)} INVALID_PATH_PATTERN = %r{(^\.?\.?/)|(/\.?\.?/)}
...@@ -24,8 +26,13 @@ module Gitlab ...@@ -24,8 +26,13 @@ module Gitlab
gzip do |gz| gzip do |gz|
read_string(gz) # version read_string(gz) # version
errors = read_string(gz) errors = read_string(gz)
raise StandardError, 'Errors field not found!' unless errors raise ParserError, 'Errors field not found!' unless errors
JSON.parse(errors)
begin
JSON.parse(errors)
rescue JSON::ParserError
raise ParserError, 'Invalid errors field!'
end
end end
end end
...@@ -56,7 +63,7 @@ module Gitlab ...@@ -56,7 +63,7 @@ module Gitlab
next unless path =~ match_pattern next unless path =~ match_pattern
next if path =~ INVALID_PATH_PATTERN next if path =~ INVALID_PATH_PATTERN
entries.store(path, JSON.parse(meta, symbolize_names: true)) entries[path] = JSON.parse(meta, symbolize_names: true)
rescue JSON::ParserError, Encoding::CompatibilityError rescue JSON::ParserError, Encoding::CompatibilityError
next next
end end
...@@ -70,11 +77,11 @@ module Gitlab ...@@ -70,11 +77,11 @@ module Gitlab
version_string = read_string(gz) version_string = read_string(gz)
unless version_string unless version_string
raise StandardError, 'Artifacts metadata file empty!' raise ParserError, 'Artifacts metadata file empty!'
end end
unless version_string =~ VERSION_PATTERN unless version_string =~ VERSION_PATTERN
raise StandardError, 'Invalid version!' raise ParserError, 'Invalid version!'
end end
version_string.chomp version_string.chomp
......
...@@ -57,7 +57,7 @@ module Gitlab ...@@ -57,7 +57,7 @@ module Gitlab
return @children if @children return @children if @children
child_pattern = %r{^#{Regexp.escape(@path)}[^/]+/?$} child_pattern = %r{^#{Regexp.escape(@path)}[^/]+/?$}
@children = select_entries { |entry| entry =~ child_pattern } @children = select_entries { |path| path =~ child_pattern }
end end
def directories(opts = {}) def directories(opts = {})
...@@ -110,7 +110,7 @@ module Gitlab ...@@ -110,7 +110,7 @@ module Gitlab
private private
def select_entries def select_entries
selected = @entries.select { |entry, _metadata| yield entry } selected = @entries.select { |path, _metadata| yield path }
selected.map { |path, _metadata| self.class.new(path, @entries) } selected.map { |path, _metadata| self.class.new(path, @entries) }
end end
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