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
iv
gitlab-ce
Commits
9b0f5778
Commit
9b0f5778
authored
Jan 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add method that calculates total size for artifacts subfolder
parent
425f8d6f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
19 deletions
+46
-19
app/models/ci/build.rb
app/models/ci/build.rb
+4
-4
app/views/projects/builds/show.html.haml
app/views/projects/builds/show.html.haml
+1
-1
lib/gitlab/ci/build/artifacts/metadata.rb
lib/gitlab/ci/build/artifacts/metadata.rb
+5
-3
lib/gitlab/ci/build/artifacts/metadata/entry.rb
lib/gitlab/ci/build/artifacts/metadata/entry.rb
+7
-0
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
+10
-5
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
+15
-2
spec/models/build_spec.rb
spec/models/build_spec.rb
+4
-4
No files found.
app/models/ci/build.rb
View file @
9b0f5778
...
@@ -346,17 +346,17 @@ module Ci
...
@@ -346,17 +346,17 @@ module Ci
end
end
def
artifacts_browse_url
def
artifacts_browse_url
if
artifacts_
browser_supported
?
if
artifacts_
metadata
?
browse_namespace_project_build_artifacts_path
(
project
.
namespace
,
project
,
self
)
browse_namespace_project_build_artifacts_path
(
project
.
namespace
,
project
,
self
)
end
end
end
end
def
artifacts_
browser_supported
?
def
artifacts_
metadata
?
artifacts?
&&
artifacts_metadata
.
exists?
artifacts?
&&
artifacts_metadata
.
exists?
end
end
def
artifacts_metadata_entry
(
path
)
def
artifacts_metadata_entry
(
path
,
**
options
)
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
.
new
(
artifacts_metadata
.
path
,
path
).
to_entry
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
.
new
(
artifacts_metadata
.
path
,
path
,
**
options
).
to_entry
end
end
private
private
...
...
app/views/projects/builds/show.html.haml
View file @
9b0f5778
...
@@ -96,7 +96,7 @@
...
@@ -96,7 +96,7 @@
.center
.center
.btn-group
{
role: :group
}
.btn-group
{
role: :group
}
=
link_to
"Download"
,
@build
.
artifacts_download_url
,
class:
'btn btn-sm btn-primary'
=
link_to
"Download"
,
@build
.
artifacts_download_url
,
class:
'btn btn-sm btn-primary'
-
if
@build
.
artifacts_
browser_supported
?
-
if
@build
.
artifacts_
metadata
?
=
link_to
"Browse"
,
@build
.
artifacts_browse_url
,
class:
'btn btn-sm btn-primary'
=
link_to
"Browse"
,
@build
.
artifacts_browse_url
,
class:
'btn btn-sm btn-primary'
.build-widget
.build-widget
...
...
lib/gitlab/ci/build/artifacts/metadata.rb
View file @
9b0f5778
...
@@ -13,8 +13,8 @@ module Gitlab
...
@@ -13,8 +13,8 @@ module Gitlab
attr_reader
:file
,
:path
,
:full_version
attr_reader
:file
,
:path
,
:full_version
def
initialize
(
file
,
path
)
def
initialize
(
file
,
path
,
**
opts
)
@file
,
@path
=
file
,
path
@file
,
@path
,
@opts
=
file
,
path
,
opts
@full_version
=
read_version
@full_version
=
read_version
end
end
...
@@ -52,7 +52,9 @@ module Gitlab
...
@@ -52,7 +52,9 @@ module Gitlab
def
match_entries
(
gz
)
def
match_entries
(
gz
)
entries
=
{}
entries
=
{}
match_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
[^/]*/?$}
child_pattern
=
'[^/]*/?$'
unless
@opts
[
:recursive
]
match_pattern
=
/^
#{
Regexp
.
escape
(
@path
)
}#{
child_pattern
}
/
until
gz
.
eof?
do
until
gz
.
eof?
do
begin
begin
...
...
lib/gitlab/ci/build/artifacts/metadata/entry.rb
View file @
9b0f5778
...
@@ -95,6 +95,13 @@ module Gitlab
...
@@ -95,6 +95,13 @@ module Gitlab
children
.
empty?
children
.
empty?
end
end
def
total_size
descendant_pattern
=
%r{^
#{
Regexp
.
escape
(
@path
)
}
}
entries
.
sum
do
|
path
,
entry
|
(
entry
[
:size
]
if
path
=~
descendant_pattern
).
to_i
end
end
def
to_s
def
to_s
@path
@path
end
end
...
...
spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
View file @
9b0f5778
...
@@ -4,13 +4,13 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -4,13 +4,13 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
let
(
:entries
)
do
let
(
:entries
)
do
{
'path/'
=>
{},
{
'path/'
=>
{},
'path/dir_1/'
=>
{},
'path/dir_1/'
=>
{},
'path/dir_1/file_1'
=>
{},
'path/dir_1/file_1'
=>
{
size:
10
},
'path/dir_1/file_b'
=>
{},
'path/dir_1/file_b'
=>
{
size:
10
},
'path/dir_1/subdir/'
=>
{},
'path/dir_1/subdir/'
=>
{},
'path/dir_1/subdir/subfile'
=>
{},
'path/dir_1/subdir/subfile'
=>
{
size:
10
},
'path/second_dir'
=>
{},
'path/second_dir'
=>
{},
'path/second_dir/dir_3/file_2'
=>
{},
'path/second_dir/dir_3/file_2'
=>
{
size:
10
},
'path/second_dir/dir_3/file_3'
=>
{},
'path/second_dir/dir_3/file_3'
=>
{
size:
10
},
'another_directory/'
=>
{},
'another_directory/'
=>
{},
'another_file'
=>
{},
'another_file'
=>
{},
'/file/with/absolute_path'
=>
{}
}
'/file/with/absolute_path'
=>
{}
}
...
@@ -112,6 +112,11 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
...
@@ -112,6 +112,11 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
subject
{
|
example
|
path
(
example
).
empty?
}
subject
{
|
example
|
path
(
example
).
empty?
}
it
{
is_expected
.
to
be
false
}
it
{
is_expected
.
to
be
false
}
end
end
describe
'#total_size'
do
subject
{
|
example
|
path
(
example
).
total_size
}
it
{
is_expected
.
to
eq
(
30
)
}
end
end
end
end
end
...
...
spec/lib/gitlab/ci/build/artifacts/metadata_spec.rb
View file @
9b0f5778
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
do
describe
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
do
def
metadata
(
path
=
''
)
def
metadata
(
path
=
''
,
**
opts
)
described_class
.
new
(
metadata_file_path
,
path
)
described_class
.
new
(
metadata_file_path
,
path
,
**
opts
)
end
end
let
(
:metadata_file_path
)
do
let
(
:metadata_file_path
)
do
...
@@ -51,6 +51,19 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
...
@@ -51,6 +51,19 @@ describe Gitlab::Ci::Build::Artifacts::Metadata do
end
end
end
end
describe
'#find_entries! recursively for other_artifacts_0.1.2/'
do
subject
{
metadata
(
'other_artifacts_0.1.2/'
,
recursive:
true
).
find_entries!
}
it
'matches correct paths'
do
expect
(
subject
.
keys
).
to
contain_exactly
'other_artifacts_0.1.2/'
,
'other_artifacts_0.1.2/doc_sample.txt'
,
'other_artifacts_0.1.2/another-subdirectory/'
,
'other_artifacts_0.1.2/another-subdirectory/empty_directory/'
,
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
end
end
describe
'#to_entry'
do
describe
'#to_entry'
do
subject
{
metadata
(
''
).
to_entry
}
subject
{
metadata
(
''
).
to_entry
}
it
{
is_expected
.
to
be_an_instance_of
(
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
::
Entry
)
}
it
{
is_expected
.
to
be_an_instance_of
(
Gitlab
::
Ci
::
Build
::
Artifacts
::
Metadata
::
Entry
)
}
...
...
spec/models/build_spec.rb
View file @
9b0f5778
...
@@ -362,12 +362,12 @@ describe Ci::Build, models: true do
...
@@ -362,12 +362,12 @@ describe Ci::Build, models: true do
subject
{
build
.
artifacts_browse_url
}
subject
{
build
.
artifacts_browse_url
}
it
"should be nil if artifacts browser is unsupported"
do
it
"should be nil if artifacts browser is unsupported"
do
allow
(
build
).
to
receive
(
:artifacts_
browser_supported
?
).
and_return
(
false
)
allow
(
build
).
to
receive
(
:artifacts_
metadata
?
).
and_return
(
false
)
is_expected
.
to
be_nil
is_expected
.
to
be_nil
end
end
it
'should not be nil if artifacts browser is supported'
do
it
'should not be nil if artifacts browser is supported'
do
allow
(
build
).
to
receive
(
:artifacts_
browser_supported
?
).
and_return
(
true
)
allow
(
build
).
to
receive
(
:artifacts_
metadata
?
).
and_return
(
true
)
is_expected
.
to_not
be_nil
is_expected
.
to_not
be_nil
end
end
end
end
...
@@ -391,8 +391,8 @@ describe Ci::Build, models: true do
...
@@ -391,8 +391,8 @@ describe Ci::Build, models: true do
end
end
describe
:artifacts_
browser_supported
?
do
describe
:artifacts_
metadata
?
do
subject
{
build
.
artifacts_
browser_supported
?
}
subject
{
build
.
artifacts_
metadata
?
}
context
'artifacts metadata does not exist'
do
context
'artifacts metadata does not exist'
do
it
{
is_expected
.
to
be_falsy
}
it
{
is_expected
.
to
be_falsy
}
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