BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+2
-2
build.rb
app/models/ci/build.rb
+6
-5
string_path.rb
lib/gitlab/string_path.rb
+9
-3
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