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
Kazuhiko Shiozaki
gitlab-ce
Commits
a7f99b67
Commit
a7f99b67
authored
Jan 04, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract artifacts metadata implementation to separate class
parent
df411486
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
139 additions
and
23 deletions
+139
-23
app/controllers/projects/artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+1
-4
app/models/ci/build.rb
app/models/ci/build.rb
+3
-17
lib/gitlab/ci/build/artifacts/metadata.rb
lib/gitlab/ci/build/artifacts/metadata.rb
+57
-0
lib/gitlab/string_path.rb
lib/gitlab/string_path.rb
+2
-2
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
+76
-0
No files found.
app/controllers/projects/artifacts_controller.rb
View file @
a7f99b67
...
@@ -16,10 +16,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
...
@@ -16,10 +16,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
def
browse
def
browse
return
render_404
unless
build
.
artifacts?
return
render_404
unless
build
.
artifacts?
@path
=
build
.
artifacts_metadata_string_path
(
params
[
:path
]
||
'./'
)
current_path
=
params
[
:path
]
?
"./
#{
params
[
:path
]
}
/"
:
'./'
paths
,
metadata
=
build
.
artifacts_metadata_for_path
(
current_path
)
@path
=
Gitlab
::
StringPath
.
new
(
current_path
,
paths
,
metadata
)
end
end
private
private
...
...
app/models/ci/build.rb
View file @
a7f99b67
...
@@ -349,24 +349,10 @@ module Ci
...
@@ -349,24 +349,10 @@ module Ci
artifacts?
&&
artifacts_file
.
path
.
end_with?
(
'zip'
)
&&
artifacts_metadata
.
exists?
artifacts?
&&
artifacts_file
.
path
.
end_with?
(
'zip'
)
&&
artifacts_metadata
.
exists?
end
end
def
artifacts_metadata_for_path
(
path
)
return
[]
unless
artifacts_metadata
.
exists?
paths
,
metadata
=
[],
[]
metadata_path
=
path
.
sub
(
/^\.\//
,
''
)
def
artifacts_metadata_string_path
(
path
)
File
.
open
(
artifacts_metadata
.
path
)
do
|
file
|
file
=
artifacts_metadata
.
path
gzip
=
Zlib
::
GzipReader
.
new
(
file
)
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
.
new
(
file
,
path
).
to_string_path
gzip
.
each_line
do
|
line
|
if
line
=~
%r{^
#{
Regexp
.
escape
(
metadata_path
)
}
[^/
\s
]+/?
\s
}
matched_path
,
matched_meta
=
line
.
split
(
' '
)
paths
<<
matched_path
metadata
<<
JSON
.
parse
(
matched_meta
)
end
end
gzip
.
close
end
[
paths
,
metadata
]
end
end
private
private
...
...
lib/gitlab/ci/build/artifacts/metadata.rb
0 → 100644
View file @
a7f99b67
require
'zlib'
require
'json'
module
Gitlab
module
Ci
module
Build
module
Artifacts
class
Metadata
def
initialize
(
file
,
path
)
@file
=
file
@path
=
path
.
sub
(
/^\.\//
,
''
)
@path
<<
'/'
unless
path
.
end_with?
(
'/'
)
end
def
exists?
File
.
exists?
(
@file
)
end
def
match!
raise
StandardError
,
'Metadata file not found !'
unless
exists?
paths
,
metadata
=
[],
[]
each
do
|
line
|
next
unless
line
=~
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/
\s
]+/?
\s
}
path
,
meta
=
line
.
split
(
' '
)
paths
.
push
(
path
)
metadata
.
push
(
meta
)
end
[
paths
,
metadata
.
map
{
|
meta
|
JSON
.
parse
(
meta
)
}]
end
def
to_string_path
universe
,
metadata
=
match!
::
Gitlab
::
StringPath
.
new
(
@path
,
universe
,
metadata
)
end
private
def
each
open
do
|
file
|
gzip
=
Zlib
::
GzipReader
.
new
(
file
)
gzip
.
each_line
{
|
line
|
yield
line
}
gzip
.
close
end
end
def
open
File
.
open
(
@file
)
{
|
file
|
yield
file
}
end
end
end
end
end
end
lib/gitlab/string_path.rb
View file @
a7f99b67
...
@@ -75,7 +75,7 @@ module Gitlab
...
@@ -75,7 +75,7 @@ module Gitlab
end
end
def
directories!
def
directories!
has_parent?
?
directories
.
prepend
(
parent
)
:
directories
@path
=~
%r{^
\.
/[^/]/}
?
directories
.
prepend
(
parent
)
:
directories
end
end
def
files
def
files
...
@@ -119,7 +119,7 @@ module Gitlab
...
@@ -119,7 +119,7 @@ module Gitlab
raise
ArgumentError
,
'Invalid path'
if
clean_path
.
start_with?
(
'../'
)
raise
ArgumentError
,
'Invalid path'
if
clean_path
.
start_with?
(
'../'
)
prefix
=
'./'
unless
clean_path
=~
%r{^[
\.
|/]}
prefix
=
'./'
unless
clean_path
=~
%r{^[
\.
|/]}
suffix
=
'/'
if
path
.
end_with?
(
'/'
)
||
clean_path
=~
/^[\.|\.\.]$/
suffix
=
'/'
if
path
.
end_with?
(
'/'
)
||
[
'.'
,
'..'
].
include?
(
clean_path
)
prefix
.
to_s
+
clean_path
+
suffix
.
to_s
prefix
.
to_s
+
clean_path
+
suffix
.
to_s
end
end
end
end
...
...
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
0 → 100644
View file @
a7f99b67
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
do
def
metadata
(
path
=
''
)
described_class
.
new
(
metadata_file_path
,
path
)
end
let
(
:metadata_file_path
)
do
Rails
.
root
+
'spec/fixtures/ci_build_artifacts_metadata.gz'
end
context
'metadata file exists'
do
describe
'#exists?'
do
subject
{
metadata
.
exists?
}
it
{
is_expected
.
to
be
true
}
end
describe
'#match! ./'
do
subject
{
metadata
(
'./'
).
match!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
to
contain_exactly
'ci_artifacts.txt'
,
'other_artifacts_0.1.2/'
,
'rails_sample.jpg'
end
it
'matches metadata for every path'
do
expect
(
subject
.
last
.
count
).
to
eq
3
end
it
'return Hashes for each metadata'
do
expect
(
subject
.
last
).
to
all
(
be_kind_of
(
Hash
))
end
end
describe
'#match! other_artifacts_0.1.2'
do
subject
{
metadata
(
'other_artifacts_0.1.2'
).
match!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
to
contain_exactly
'other_artifacts_0.1.2/doc_sample.txt'
,
'other_artifacts_0.1.2/another-subdirectory/'
end
end
describe
'#match! other_artifacts_0.1.2/another-subdirectory'
do
subject
{
metadata
(
'other_artifacts_0.1.2/another-subdirectory/'
).
match!
}
it
'matches correct paths'
do
expect
(
subject
.
first
).
to
contain_exactly
'other_artifacts_0.1.2/another-subdirectory/empty_directory/'
,
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
end
end
describe
'#to_string_path'
do
subject
{
metadata
(
''
).
to_string_path
}
it
{
is_expected
.
to
be_an_instance_of
(
Gitlab
::
StringPath
)
}
end
end
context
'metadata file does not exist'
do
let
(
:metadata_file_path
)
{
''
}
describe
'#exists?'
do
subject
{
metadata
.
exists?
}
it
{
is_expected
.
to
be
false
}
end
describe
'#match!'
do
it
'raises error'
do
expect
{
metadata
.
match!
}.
to
raise_error
(
StandardError
,
/Metadata file not found/
)
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