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
Léo-Paul Géneau
gitlab-ce
Commits
ad2b0358
Commit
ad2b0358
authored
Jan 13, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve readability of artifacts `Metadata` related code
parent
6b0a43af
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
45 deletions
+34
-45
config/routes.rb
config/routes.rb
+2
-3
lib/gitlab/ci/build/artifacts/metadata.rb
lib/gitlab/ci/build/artifacts/metadata.rb
+11
-21
lib/gitlab/ci/build/artifacts/metadata/entry.rb
lib/gitlab/ci/build/artifacts/metadata/entry.rb
+13
-13
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
+8
-8
No files found.
config/routes.rb
View file @
ad2b0358
...
@@ -603,15 +603,14 @@ Rails.application.routes.draw do
...
@@ -603,15 +603,14 @@ Rails.application.routes.draw do
member
do
member
do
get
:status
get
:status
get
:download
post
:cancel
post
:cancel
post
:retry
post
:retry
end
end
resource
:artifacts
,
only:
[]
do
resource
:artifacts
,
only:
[]
do
get
:download
get
:download
get
'browse(/*path)'
,
action: :browse
,
as
: :browse
,
format:
false
get
:browse
,
path:
'browse(/*path)'
,
action
: :browse
,
format:
false
get
'file/*path'
,
action: :file
,
as
: :file
,
format:
false
get
:file
,
path:
'file/*path'
,
action
: :file
,
format:
false
end
end
end
end
...
...
lib/gitlab/ci/build/artifacts/metadata.rb
View file @
ad2b0358
...
@@ -6,7 +6,9 @@ module Gitlab
...
@@ -6,7 +6,9 @@ module Gitlab
module
Build
module
Build
module
Artifacts
module
Artifacts
class
Metadata
class
Metadata
VERSION_PATTERN
=
'[\w\s]+(\d+\.\d+\.\d+)'
VERSION_PATTERN
=
/^[\w\s]+(\d+\.\d+\.\d+)/
INVALID_PATH_PATTERN
=
%r{(^
\.
?
\.
?/)|(/
\.
?
\.
?/)}
attr_reader
:file
,
:path
,
:full_version
attr_reader
:file
,
:path
,
:full_version
def
initialize
(
file
,
path
)
def
initialize
(
file
,
path
)
...
@@ -15,7 +17,7 @@ module Gitlab
...
@@ -15,7 +17,7 @@ module Gitlab
end
end
def
version
def
version
@full_version
.
match
(
/
#{
VERSION_PATTERN
}
/
).
captures
.
first
@full_version
.
match
(
VERSION_PATTERN
)[
1
]
end
end
def
errors
def
errors
...
@@ -27,7 +29,7 @@ module Gitlab
...
@@ -27,7 +29,7 @@ module Gitlab
end
end
end
end
def
match
!
def
find_entries
!
gzip
do
|
gz
|
gzip
do
|
gz
|
2
.
times
{
read_string
(
gz
)
}
# version and errors fields
2
.
times
{
read_string
(
gz
)
}
# version and errors fields
match_entries
(
gz
)
match_entries
(
gz
)
...
@@ -35,8 +37,8 @@ module Gitlab
...
@@ -35,8 +37,8 @@ module Gitlab
end
end
def
to_entry
def
to_entry
ent
ires
,
metadata
=
match
!
ent
ries
,
metadata
=
find_entries
!
Entry
.
new
(
@path
,
ent
ir
es
,
metadata
)
Entry
.
new
(
@path
,
ent
ri
es
,
metadata
)
end
end
private
private
...
@@ -44,7 +46,6 @@ module Gitlab
...
@@ -44,7 +46,6 @@ module Gitlab
def
match_entries
(
gz
)
def
match_entries
(
gz
)
paths
,
metadata
=
[],
[]
paths
,
metadata
=
[],
[]
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
invalid_pattern
=
%r{(^
\.
?
\.
?/)|(/
\.
?
\.
?/)}
until
gz
.
eof?
do
until
gz
.
eof?
do
begin
begin
...
@@ -53,7 +54,7 @@ module Gitlab
...
@@ -53,7 +54,7 @@ module Gitlab
next
unless
path
.
valid_encoding?
&&
meta
.
valid_encoding?
next
unless
path
.
valid_encoding?
&&
meta
.
valid_encoding?
next
unless
path
=~
match_pattern
next
unless
path
=~
match_pattern
next
if
path
=~
invalid_pattern
next
if
path
=~
INVALID_PATH_PATTERN
paths
.
push
(
path
)
paths
.
push
(
path
)
metadata
.
push
(
JSON
.
parse
(
meta
,
symbolize_names:
true
))
metadata
.
push
(
JSON
.
parse
(
meta
,
symbolize_names:
true
))
...
@@ -73,7 +74,7 @@ module Gitlab
...
@@ -73,7 +74,7 @@ module Gitlab
raise
StandardError
,
'Artifacts metadata file empty!'
raise
StandardError
,
'Artifacts metadata file empty!'
end
end
unless
version_string
=~
/^
#{
VERSION_PATTERN
}
/
unless
version_string
=~
VERSION_PATTERN
raise
StandardError
,
'Invalid version!'
raise
StandardError
,
'Invalid version!'
end
end
...
@@ -92,19 +93,8 @@ module Gitlab
...
@@ -92,19 +93,8 @@ module Gitlab
gz
.
read
(
string_size
)
gz
.
read
(
string_size
)
end
end
def
gzip
def
gzip
(
&
block
)
open
do
|
file
|
Zlib
::
GzipReader
.
open
(
@file
,
&
block
)
gzip
=
Zlib
::
GzipReader
.
new
(
file
)
begin
yield
gzip
ensure
gzip
.
close
end
end
end
def
open
File
.
open
(
@file
)
{
|
file
|
yield
file
}
end
end
end
end
end
end
...
...
lib/gitlab/ci/build/artifacts/metadata/entry.rb
View file @
ad2b0358
...
@@ -11,12 +11,12 @@ module Gitlab
...
@@ -11,12 +11,12 @@ module Gitlab
# This class is working only with UTF-8 encoded paths.
# This class is working only with UTF-8 encoded paths.
#
#
class
Entry
class
Entry
attr_reader
:path
,
:ent
ir
es
attr_reader
:path
,
:ent
ri
es
attr_accessor
:name
attr_accessor
:name
def
initialize
(
path
,
ent
ir
es
,
metadata
=
[])
def
initialize
(
path
,
ent
ri
es
,
metadata
=
[])
@path
=
path
.
force_encoding
(
'UTF-8'
)
@path
=
path
.
force_encoding
(
'UTF-8'
)
@ent
ires
=
entir
es
@ent
ries
=
entri
es
@metadata
=
metadata
@metadata
=
metadata
if
path
.
include?
(
"
\0
"
)
if
path
.
include?
(
"
\0
"
)
...
@@ -42,7 +42,7 @@ module Gitlab
...
@@ -42,7 +42,7 @@ module Gitlab
def
parent
def
parent
return
nil
unless
has_parent?
return
nil
unless
has_parent?
new
(
@path
.
chomp
(
basename
))
new
_entry
(
@path
.
chomp
(
basename
))
end
end
def
basename
def
basename
...
@@ -58,7 +58,7 @@ module Gitlab
...
@@ -58,7 +58,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_ent
ir
es
{
|
entry
|
entry
=~
child_pattern
}
@children
=
select_ent
ri
es
{
|
entry
|
entry
=~
child_pattern
}
end
end
def
directories
(
opts
=
{})
def
directories
(
opts
=
{})
...
@@ -77,7 +77,7 @@ module Gitlab
...
@@ -77,7 +77,7 @@ module Gitlab
end
end
def
metadata
def
metadata
@index
||=
@ent
ir
es
.
index
(
@path
)
@index
||=
@ent
ri
es
.
index
(
@path
)
@metadata
[
@index
]
||
{}
@metadata
[
@index
]
||
{}
end
end
...
@@ -90,7 +90,7 @@ module Gitlab
...
@@ -90,7 +90,7 @@ module Gitlab
end
end
def
exists?
def
exists?
blank_node?
||
@ent
ir
es
.
include?
(
@path
)
blank_node?
||
@ent
ri
es
.
include?
(
@path
)
end
end
def
empty?
def
empty?
...
@@ -102,7 +102,7 @@ module Gitlab
...
@@ -102,7 +102,7 @@ module Gitlab
end
end
def
==
(
other
)
def
==
(
other
)
@path
==
other
.
path
&&
@ent
ires
==
other
.
entir
es
@path
==
other
.
path
&&
@ent
ries
==
other
.
entri
es
end
end
def
inspect
def
inspect
...
@@ -111,13 +111,13 @@ module Gitlab
...
@@ -111,13 +111,13 @@ module Gitlab
private
private
def
new
(
path
)
def
new
_entry
(
path
)
self
.
class
.
new
(
path
,
@ent
ir
es
,
@metadata
)
self
.
class
.
new
(
path
,
@ent
ri
es
,
@metadata
)
end
end
def
select_ent
ir
es
def
select_ent
ri
es
selected
=
@ent
ir
es
.
select
{
|
entry
|
yield
entry
}
selected
=
@ent
ri
es
.
select
{
|
entry
|
yield
entry
}
selected
.
map
{
|
path
|
new
(
path
)
}
selected
.
map
{
|
path
|
new
_entry
(
path
)
}
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
View file @
ad2b0358
...
@@ -10,8 +10,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -10,8 +10,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
context
'metadata file exists'
do
context
'metadata file exists'
do
describe
'#
match
! empty string'
do
describe
'#
find_entries
! empty string'
do
subject
{
metadata
(
''
).
match
!
}
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
.
first
).
to
contain_exactly
'ci_artifacts.txt'
,
...
@@ -29,8 +29,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -29,8 +29,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
end
end
describe
'#
match
! other_artifacts_0.1.2/'
do
describe
'#
find_entries
! other_artifacts_0.1.2/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
match
!
}
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
find_entries
!
}
it
'matches correct paths'
do
it
'matches correct paths'
do
expect
(
subject
.
first
).
expect
(
subject
.
first
).
...
@@ -40,8 +40,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -40,8 +40,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
end
end
describe
'#
match
! other_artifacts_0.1.2/another-subdirectory/'
do
describe
'#
find_entries
! other_artifacts_0.1.2/another-subdirectory/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
match
!
}
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
.
first
).
...
@@ -75,9 +75,9 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -75,9 +75,9 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
context
'metadata file does not exist'
do
context
'metadata file does not exist'
do
let
(
:metadata_file_path
)
{
''
}
let
(
:metadata_file_path
)
{
''
}
describe
'#
match
!'
do
describe
'#
find_entries
!'
do
it
'raises error'
do
it
'raises error'
do
expect
{
metadata
.
match
!
}.
to
raise_error
(
Errno
::
ENOENT
)
expect
{
metadata
.
find_entries
!
}.
to
raise_error
(
Errno
::
ENOENT
)
end
end
end
end
end
end
...
...
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