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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
member
do
get
:status
get
:download
post
:cancel
post
:retry
end
resource
:artifacts
,
only:
[]
do
get
:download
get
'browse(/*path)'
,
action: :browse
,
as
: :browse
,
format:
false
get
'file/*path'
,
action: :file
,
as
: :file
,
format:
false
get
:browse
,
path:
'browse(/*path)'
,
action
: :browse
,
format:
false
get
:file
,
path:
'file/*path'
,
action
: :file
,
format:
false
end
end
...
...
lib/gitlab/ci/build/artifacts/metadata.rb
View file @
ad2b0358
...
...
@@ -6,7 +6,9 @@ module Gitlab
module
Build
module
Artifacts
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
def
initialize
(
file
,
path
)
...
...
@@ -15,7 +17,7 @@ module Gitlab
end
def
version
@full_version
.
match
(
/
#{
VERSION_PATTERN
}
/
).
captures
.
first
@full_version
.
match
(
VERSION_PATTERN
)[
1
]
end
def
errors
...
...
@@ -27,7 +29,7 @@ module Gitlab
end
end
def
match
!
def
find_entries
!
gzip
do
|
gz
|
2
.
times
{
read_string
(
gz
)
}
# version and errors fields
match_entries
(
gz
)
...
...
@@ -35,8 +37,8 @@ module Gitlab
end
def
to_entry
ent
ires
,
metadata
=
match
!
Entry
.
new
(
@path
,
ent
ir
es
,
metadata
)
ent
ries
,
metadata
=
find_entries
!
Entry
.
new
(
@path
,
ent
ri
es
,
metadata
)
end
private
...
...
@@ -44,7 +46,6 @@ module Gitlab
def
match_entries
(
gz
)
paths
,
metadata
=
[],
[]
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
invalid_pattern
=
%r{(^
\.
?
\.
?/)|(/
\.
?
\.
?/)}
until
gz
.
eof?
do
begin
...
...
@@ -53,7 +54,7 @@ module Gitlab
next
unless
path
.
valid_encoding?
&&
meta
.
valid_encoding?
next
unless
path
=~
match_pattern
next
if
path
=~
invalid_pattern
next
if
path
=~
INVALID_PATH_PATTERN
paths
.
push
(
path
)
metadata
.
push
(
JSON
.
parse
(
meta
,
symbolize_names:
true
))
...
...
@@ -73,7 +74,7 @@ module Gitlab
raise
StandardError
,
'Artifacts metadata file empty!'
end
unless
version_string
=~
/^
#{
VERSION_PATTERN
}
/
unless
version_string
=~
VERSION_PATTERN
raise
StandardError
,
'Invalid version!'
end
...
...
@@ -92,19 +93,8 @@ module Gitlab
gz
.
read
(
string_size
)
end
def
gzip
open
do
|
file
|
gzip
=
Zlib
::
GzipReader
.
new
(
file
)
begin
yield
gzip
ensure
gzip
.
close
end
end
end
def
open
File
.
open
(
@file
)
{
|
file
|
yield
file
}
def
gzip
(
&
block
)
Zlib
::
GzipReader
.
open
(
@file
,
&
block
)
end
end
end
...
...
lib/gitlab/ci/build/artifacts/metadata/entry.rb
View file @
ad2b0358
...
...
@@ -11,12 +11,12 @@ module Gitlab
# This class is working only with UTF-8 encoded paths.
#
class
Entry
attr_reader
:path
,
:ent
ir
es
attr_reader
:path
,
:ent
ri
es
attr_accessor
:name
def
initialize
(
path
,
ent
ir
es
,
metadata
=
[])
def
initialize
(
path
,
ent
ri
es
,
metadata
=
[])
@path
=
path
.
force_encoding
(
'UTF-8'
)
@ent
ires
=
entir
es
@ent
ries
=
entri
es
@metadata
=
metadata
if
path
.
include?
(
"
\0
"
)
...
...
@@ -42,7 +42,7 @@ module Gitlab
def
parent
return
nil
unless
has_parent?
new
(
@path
.
chomp
(
basename
))
new
_entry
(
@path
.
chomp
(
basename
))
end
def
basename
...
...
@@ -58,7 +58,7 @@ module Gitlab
return
@children
if
@children
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
def
directories
(
opts
=
{})
...
...
@@ -77,7 +77,7 @@ module Gitlab
end
def
metadata
@index
||=
@ent
ir
es
.
index
(
@path
)
@index
||=
@ent
ri
es
.
index
(
@path
)
@metadata
[
@index
]
||
{}
end
...
...
@@ -90,7 +90,7 @@ module Gitlab
end
def
exists?
blank_node?
||
@ent
ir
es
.
include?
(
@path
)
blank_node?
||
@ent
ri
es
.
include?
(
@path
)
end
def
empty?
...
...
@@ -102,7 +102,7 @@ module Gitlab
end
def
==
(
other
)
@path
==
other
.
path
&&
@ent
ires
==
other
.
entir
es
@path
==
other
.
path
&&
@ent
ries
==
other
.
entri
es
end
def
inspect
...
...
@@ -111,13 +111,13 @@ module Gitlab
private
def
new
(
path
)
self
.
class
.
new
(
path
,
@ent
ir
es
,
@metadata
)
def
new
_entry
(
path
)
self
.
class
.
new
(
path
,
@ent
ri
es
,
@metadata
)
end
def
select_ent
ir
es
selected
=
@ent
ir
es
.
select
{
|
entry
|
yield
entry
}
selected
.
map
{
|
path
|
new
(
path
)
}
def
select_ent
ri
es
selected
=
@ent
ri
es
.
select
{
|
entry
|
yield
entry
}
selected
.
map
{
|
path
|
new
_entry
(
path
)
}
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
end
context
'metadata file exists'
do
describe
'#
match
! empty string'
do
subject
{
metadata
(
''
).
match
!
}
describe
'#
find_entries
! empty string'
do
subject
{
metadata
(
''
).
find_entries
!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
to
contain_exactly
'ci_artifacts.txt'
,
...
...
@@ -29,8 +29,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
describe
'#
match
! other_artifacts_0.1.2/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
match
!
}
describe
'#
find_entries
! other_artifacts_0.1.2/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/'
).
find_entries
!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
...
...
@@ -40,8 +40,8 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
describe
'#
match
! other_artifacts_0.1.2/another-subdirectory/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
match
!
}
describe
'#
find_entries
! other_artifacts_0.1.2/another-subdirectory/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
find_entries
!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
...
...
@@ -75,9 +75,9 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
context
'metadata file does not exist'
do
let
(
:metadata_file_path
)
{
''
}
describe
'#
match
!'
do
describe
'#
find_entries
!'
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
...
...
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