Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
0d6e7b9d
Commit
0d6e7b9d
authored
Jan 13, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Hash to store paths and entries metadata in artifacts browser
parent
ad2b0358
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
56 deletions
+47
-56
lib/gitlab/ci/build/artifacts/metadata.rb
lib/gitlab/ci/build/artifacts/metadata.rb
+5
-6
lib/gitlab/ci/build/artifacts/metadata/entry.rb
lib/gitlab/ci/build/artifacts/metadata/entry.rb
+6
-12
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
+28
-30
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
+8
-8
No files found.
lib/gitlab/ci/build/artifacts/metadata.rb
View file @
0d6e7b9d
...
@@ -37,14 +37,14 @@ module Gitlab
...
@@ -37,14 +37,14 @@ module Gitlab
end
end
def
to_entry
def
to_entry
entries
,
metadata
=
find_entries!
entries
=
find_entries!
Entry
.
new
(
@path
,
entries
,
metadata
)
Entry
.
new
(
@path
,
entries
)
end
end
private
private
def
match_entries
(
gz
)
def
match_entries
(
gz
)
paths
,
metadata
=
[],
[]
entries
=
{}
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
until
gz
.
eof?
do
until
gz
.
eof?
do
...
@@ -56,14 +56,13 @@ module Gitlab
...
@@ -56,14 +56,13 @@ module Gitlab
next
unless
path
=~
match_pattern
next
unless
path
=~
match_pattern
next
if
path
=~
INVALID_PATH_PATTERN
next
if
path
=~
INVALID_PATH_PATTERN
paths
.
push
(
path
)
entries
.
store
(
path
,
JSON
.
parse
(
meta
,
symbolize_names:
true
))
metadata
.
push
(
JSON
.
parse
(
meta
,
symbolize_names:
true
))
rescue
JSON
::
ParserError
,
Encoding
::
CompatibilityError
rescue
JSON
::
ParserError
,
Encoding
::
CompatibilityError
next
next
end
end
end
end
[
paths
,
metadata
]
entries
end
end
def
read_version
def
read_version
...
...
lib/gitlab/ci/build/artifacts/metadata/entry.rb
View file @
0d6e7b9d
...
@@ -14,10 +14,9 @@ module Gitlab
...
@@ -14,10 +14,9 @@ module Gitlab
attr_reader
:path
,
:entries
attr_reader
:path
,
:entries
attr_accessor
:name
attr_accessor
:name
def
initialize
(
path
,
entries
,
metadata
=
[]
)
def
initialize
(
path
,
entries
)
@path
=
path
.
force_encoding
(
'UTF-8'
)
@path
=
path
.
dup
.
force_encoding
(
'UTF-8'
)
@entries
=
entries
@entries
=
entries
@metadata
=
metadata
if
path
.
include?
(
"
\0
"
)
if
path
.
include?
(
"
\0
"
)
raise
ArgumentError
,
'Path contains zero byte character!'
raise
ArgumentError
,
'Path contains zero byte character!'
...
@@ -42,7 +41,7 @@ module Gitlab
...
@@ -42,7 +41,7 @@ module Gitlab
def
parent
def
parent
return
nil
unless
has_parent?
return
nil
unless
has_parent?
new_entry
(
@path
.
chomp
(
basename
)
)
self
.
class
.
new
(
@path
.
chomp
(
basename
),
@entries
)
end
end
def
basename
def
basename
...
@@ -77,8 +76,7 @@ module Gitlab
...
@@ -77,8 +76,7 @@ module Gitlab
end
end
def
metadata
def
metadata
@index
||=
@entries
.
index
(
@path
)
@entries
[
@path
]
||
{}
@metadata
[
@index
]
||
{}
end
end
def
nodes
def
nodes
...
@@ -111,13 +109,9 @@ module Gitlab
...
@@ -111,13 +109,9 @@ module Gitlab
private
private
def
new_entry
(
path
)
self
.
class
.
new
(
path
,
@entries
,
@metadata
)
end
def
select_entries
def
select_entries
selected
=
@entries
.
select
{
|
entry
|
yield
entry
}
selected
=
@entries
.
select
{
|
entry
,
_metadata
|
yield
entry
}
selected
.
map
{
|
path
|
new_entry
(
path
)
}
selected
.
map
{
|
path
,
_metadata
|
self
.
class
.
new
(
path
,
@entries
)
}
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
View file @
0d6e7b9d
...
@@ -2,26 +2,26 @@ require 'spec_helper'
...
@@ -2,26 +2,26 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
::
Entry
do
describe
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
::
Entry
do
let
(
:entries
)
do
let
(
:entries
)
do
[
'path/'
,
{
'path/'
=>
{}
,
'path/dir_1/'
,
'path/dir_1/'
=>
{}
,
'path/dir_1/file_1'
,
'path/dir_1/file_1'
=>
{}
,
'path/dir_1/file_b'
,
'path/dir_1/file_b'
=>
{}
,
'path/dir_1/subdir/'
,
'path/dir_1/subdir/'
=>
{}
,
'path/dir_1/subdir/subfile'
,
'path/dir_1/subdir/subfile'
=>
{}
,
'path/second_dir'
,
'path/second_dir'
=>
{}
,
'path/second_dir/dir_3/file_2'
,
'path/second_dir/dir_3/file_2'
=>
{}
,
'path/second_dir/dir_3/file_3'
,
'path/second_dir/dir_3/file_3'
=>
{}
,
'another_directory/'
,
'another_directory/'
=>
{}
,
'another_file'
,
'another_file'
=>
{}
,
'/file/with/absolute_path'
]
'/file/with/absolute_path'
=>
{}
}
end
end
def
path
(
example
)
def
path
(
example
)
string_path
(
example
.
metadata
[
:path
])
entry
(
example
.
metadata
[
:path
])
end
end
def
string_path
(
string_
path
)
def
entry
(
path
)
described_class
.
new
(
string_
path
,
entries
)
described_class
.
new
(
path
,
entries
)
end
end
describe
'/file/with/absolute_path'
,
path:
'/file/with/absolute_path'
do
describe
'/file/with/absolute_path'
,
path:
'/file/with/absolute_path'
do
...
@@ -53,7 +53,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -53,7 +53,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
describe
'#parent'
do
describe
'#parent'
do
subject
{
|
example
|
path
(
example
).
parent
}
subject
{
|
example
|
path
(
example
).
parent
}
it
{
is_expected
.
to
eq
string_path
(
'path/'
)
}
it
{
is_expected
.
to
eq
entry
(
'path/'
)
}
end
end
describe
'#children'
do
describe
'#children'
do
...
@@ -61,9 +61,9 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -61,9 +61,9 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
do
it
do
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/file_1'
),
is_expected
.
to
contain_exactly
entry
(
'path/dir_1/file_1'
),
string_path
(
'path/dir_1/file_b'
),
entry
(
'path/dir_1/file_b'
),
string_path
(
'path/dir_1/subdir/'
)
entry
(
'path/dir_1/subdir/'
)
end
end
end
end
...
@@ -73,8 +73,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -73,8 +73,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
it
{
is_expected
.
to
all
(
be_file
)
}
it
{
is_expected
.
to
all
(
be_file
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
do
it
do
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/file_1'
),
is_expected
.
to
contain_exactly
entry
(
'path/dir_1/file_1'
),
string_path
(
'path/dir_1/file_b'
)
entry
(
'path/dir_1/file_b'
)
end
end
end
end
...
@@ -84,7 +84,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -84,7 +84,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
it
{
is_expected
.
to
all
(
be_directory
)
}
it
{
is_expected
.
to
all
(
be_directory
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/subdir/'
)
}
it
{
is_expected
.
to
contain_exactly
entry
(
'path/dir_1/subdir/'
)
}
end
end
context
'with option parent: true'
do
context
'with option parent: true'
do
...
@@ -93,8 +93,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -93,8 +93,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
it
{
is_expected
.
to
all
(
be_directory
)
}
it
{
is_expected
.
to
all
(
be_directory
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
do
it
do
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/subdir/'
),
is_expected
.
to
contain_exactly
entry
(
'path/dir_1/subdir/'
),
string_path
(
'path/'
)
entry
(
'path/'
)
end
end
end
end
...
@@ -154,15 +154,13 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -154,15 +154,13 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
describe
'#metadata'
do
describe
'#metadata'
do
let
(
:entries
)
do
let
(
:entries
)
do
[
'path/'
,
'path/file1'
,
'path/file2'
]
{
'path/'
=>
{
name:
'/path/'
},
end
'path/file1'
=>
{
name:
'/path/file1'
},
'path/file2'
=>
{
name:
'/path/file2'
}
}
let
(
:metadata
)
do
[{
name:
'/path/'
},
{
name:
'/path/file1'
},
{
name:
'/path/file2'
}]
end
end
subject
do
subject
do
described_class
.
new
(
'path/file1'
,
entries
,
metadata
).
metadata
[
:name
]
described_class
.
new
(
'path/file1'
,
entries
).
metadata
[
:name
]
end
end
it
{
is_expected
.
to
eq
'/path/file1'
}
it
{
is_expected
.
to
eq
'/path/file1'
}
...
...
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
View file @
0d6e7b9d
...
@@ -14,18 +14,18 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -14,18 +14,18 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
subject
{
metadata
(
''
).
find_entries!
}
subject
{
metadata
(
''
).
find_entries!
}
it
'matches correct paths'
do
it
'matches correct paths'
do
expect
(
subject
.
first
).
to
contain_exactly
'ci_artifacts.txt'
,
expect
(
subject
.
keys
).
to
contain_exactly
'ci_artifacts.txt'
,
'other_artifacts_0.1.2/'
,
'other_artifacts_0.1.2/'
,
'rails_sample.jpg'
,
'rails_sample.jpg'
,
'tests_encoding/'
'tests_encoding/'
end
end
it
'matches metadata for every path'
do
it
'matches metadata for every path'
do
expect
(
subject
.
last
.
count
).
to
eq
4
expect
(
subject
.
keys
.
count
).
to
eq
4
end
end
it
'return Hashes for each metadata'
do
it
'return Hashes for each metadata'
do
expect
(
subject
.
last
).
to
all
(
be_kind_of
(
Hash
))
expect
(
subject
.
values
).
to
all
(
be_kind_of
(
Hash
))
end
end
end
end
...
@@ -33,7 +33,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -33,7 +33,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
find_entries!
}
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
find_entries!
}
it
'matches correct paths'
do
it
'matches correct paths'
do
expect
(
subject
.
first
).
expect
(
subject
.
keys
).
to
contain_exactly
'other_artifacts_0.1.2/'
,
to
contain_exactly
'other_artifacts_0.1.2/'
,
'other_artifacts_0.1.2/doc_sample.txt'
,
'other_artifacts_0.1.2/doc_sample.txt'
,
'other_artifacts_0.1.2/another-subdirectory/'
'other_artifacts_0.1.2/another-subdirectory/'
...
@@ -44,7 +44,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -44,7 +44,7 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
find_entries!
}
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
find_entries!
}
it
'matches correct paths'
do
it
'matches correct paths'
do
expect
(
subject
.
first
).
expect
(
subject
.
keys
).
to
contain_exactly
'other_artifacts_0.1.2/another-subdirectory/'
,
to
contain_exactly
'other_artifacts_0.1.2/another-subdirectory/'
,
'other_artifacts_0.1.2/another-subdirectory/empty_directory/'
,
'other_artifacts_0.1.2/another-subdirectory/empty_directory/'
,
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment