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
3de8a462
Commit
3de8a462
authored
Dec 31, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse artifacts metadata stored in JSON format
parent
447f5603
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
app/controllers/projects/artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+2
-2
app/models/ci/build.rb
app/models/ci/build.rb
+6
-5
lib/gitlab/string_path.rb
lib/gitlab/string_path.rb
+9
-3
spec/lib/gitlab/string_path_spec.rb
spec/lib/gitlab/string_path_spec.rb
+16
-0
No files found.
app/controllers/projects/artifacts_controller.rb
View file @
3de8a462
...
...
@@ -18,8 +18,8 @@ class Projects::ArtifactsController < Projects::ApplicationController
return
render_404
unless
build
.
artifacts?
current_path
=
params
[
:path
]
?
"./
#{
params
[
:path
]
}
/"
:
'./'
metadata
=
build
.
artifacts_metadata_for_path
(
current_path
)
@path
=
Gitlab
::
StringPath
.
new
(
current_path
,
metadata
)
paths
,
metadata
=
build
.
artifacts_metadata_for_path
(
current_path
)
@path
=
Gitlab
::
StringPath
.
new
(
current_path
,
paths
,
metadata
)
end
private
...
...
app/models/ci/build.rb
View file @
3de8a462
...
...
@@ -350,22 +350,23 @@ module Ci
end
def
artifacts_metadata_for_path
(
path
)
return
{}
unless
artifacts_metadata
.
exists?
metadata
=
[]
return
[]
unless
artifacts_metadata
.
exists?
paths
,
metadata
=
[],
[]
meta_path
=
path
.
sub
(
/^\.\//
,
''
)
File
.
open
(
artifacts_metadata
.
path
)
do
|
file
|
gzip
=
Zlib
::
GzipReader
.
new
(
file
)
gzip
.
each_line
do
|
line
|
if
line
=~
%r{^
#{
meta_path
}
[^/]+/?
\s
}
path
,
meta
=
line
.
split
(
' '
)
metadata
<<
path
path
,
meta
=
line
.
split
(
' '
)
paths
<<
path
metadata
<<
JSON
.
parse
(
meta
)
end
end
gzip
.
close
end
metadata
[
paths
,
metadata
]
end
private
...
...
lib/gitlab/string_path.rb
View file @
3de8a462
...
...
@@ -10,10 +10,11 @@ module Gitlab
class
StringPath
attr_reader
:path
,
:universe
def
initialize
(
path
,
universe
)
def
initialize
(
path
,
universe
,
metadata
=
[]
)
@path
=
prepare
(
path
)
@universe
=
Set
.
new
(
universe
.
map
{
|
entry
|
prepare
(
entry
)
})
@universe
.
add
(
'./'
)
@universe
=
universe
.
map
{
|
entry
|
prepare
(
entry
)
}
@universe
<<
'./'
unless
@universe
.
include?
(
'./'
)
@metadata
=
metadata
end
def
to_s
...
...
@@ -84,6 +85,11 @@ module Gitlab
children
.
select
(
&
:file?
)
end
def
metadata
index
=
@universe
.
index
(
@path
)
@metadata
[
index
]
end
def
==
(
other
)
@path
==
other
.
path
&&
@universe
==
other
.
universe
end
...
...
spec/lib/gitlab/string_path_spec.rb
View file @
3de8a462
...
...
@@ -140,4 +140,20 @@ describe Gitlab::StringPath do
it
{
expect
(
subject
.
count
).
to
eq
3
}
end
end
describe
'#metadata'
do
let
(
:universe
)
do
[
'path/'
,
'path/file1'
,
'path/file2'
]
end
let
(
:metadata
)
do
[{
name:
'/path/'
},
{
name:
'/path/file1'
},
{
name:
'/path/file2'
}]
end
subject
do
described_class
.
new
(
'path/file1'
,
universe
,
metadata
).
metadata
[
:name
]
end
it
{
is_expected
.
to
eq
'/path/file1'
}
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