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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
c8102d93
Commit
c8102d93
authored
Feb 01, 2016
by
Grzegorz Bizon
Committed by
Grzegorz Bizon
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add build eraseable feature implementation
parent
89b18120
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
11 deletions
+90
-11
app/controllers/projects/builds_controller.rb
app/controllers/projects/builds_controller.rb
+4
-4
app/models/ci/build/eraseable.rb
app/models/ci/build/eraseable.rb
+18
-3
app/views/projects/builds/show.html.haml
app/views/projects/builds/show.html.haml
+5
-4
config/routes.rb
config/routes.rb
+1
-0
spec/models/ci/build/eraseable_spec.rb
spec/models/ci/build/eraseable_spec.rb
+62
-0
No files found.
app/controllers/projects/builds_controller.rb
View file @
c8102d93
...
...
@@ -56,10 +56,10 @@ class Projects::BuildsController < Projects::ApplicationController
render
json:
@build
.
to_json
(
only:
[
:status
,
:id
,
:sha
,
:coverage
],
methods: :sha
)
end
def
destroy
@build
.
destroy
redirect_to
namespace_project_build
s_path
(
project
.
namespace
,
project
),
notice:
"Build #
#{
@build
.
id
}
has been sucessfully
remov
ed!"
def
erase
@build
.
erase!
redirect_to
namespace_project_build
_path
(
project
.
namespace
,
project
,
@build
),
notice:
"Build #
#{
@build
.
id
}
has been sucessfully
eras
ed!"
end
private
...
...
app/models/ci/build/eraseable.rb
View file @
c8102d93
...
...
@@ -4,11 +4,26 @@ module Ci
include
ActiveSupport
::
Concern
def
erase!
raise
NotImplementedError
raise
StandardError
,
'Build not eraseable!'
unless
eraseable?
remove_artifacts_file!
remove_artifacts_metadata!
erase_trace!
end
def
erased?
raise
NotImpementedError
def
eraseable?
artifacts_file
.
exists?
||
File
.
file?
(
path_to_trace
)
end
def
erase_url
if
eraseable?
erase_namespace_project_build_path
(
project
.
namespace
,
project
,
self
)
end
end
private
def
erase_trace!
File
.
truncate
(
path_to_trace
,
0
)
if
File
.
file?
(
path_to_trace
)
end
end
end
...
...
app/views/projects/builds/show.html.haml
View file @
c8102d93
...
...
@@ -113,10 +113,11 @@
-
elsif
@build
.
retry_url
=
link_to
"Retry"
,
@build
.
retry_url
,
class:
'btn btn-sm btn-primary'
,
method: :post
=
link_to
''
,
class:
'btn btn-sm btn-danger'
,
method: :delete
,
data:
{
confirm:
'Are you sure you want to remove this?'
}
do
=
icon
(
'remove'
)
Remove
-
if
@build
.
eraseable?
=
link_to
@build
.
erase_url
,
class:
'btn btn-sm btn-warning'
,
method: :put
,
data:
{
confirm:
'Are you sure you want to erase this build?'
}
do
=
icon
(
'eraser'
)
Erase
.clearfix
-
if
@build
.
duration
...
...
config/routes.rb
View file @
c8102d93
...
...
@@ -617,6 +617,7 @@ Rails.application.routes.draw do
get
:status
post
:cancel
post
:retry
put
:erase
end
resource
:artifacts
,
only:
[]
do
...
...
spec/models/ci/build/eraseable_spec.rb
0 → 100644
View file @
c8102d93
require
'spec_helper'
describe
Ci
::
Build
::
Eraseable
,
models:
true
do
context
'build is not eraseable'
do
let!
(
:build
)
{
create
(
:ci_build
)
}
describe
'#erase!'
do
it
{
expect
{
build
.
erase!
}.
to
raise_error
(
StandardError
,
/Build not eraseable!/
)}
end
describe
'#eraseable?'
do
subject
{
build
.
eraseable?
}
it
{
is_expected
.
to
eq
false
}
end
describe
'#erase_url'
do
subject
{
build
.
erase_url
}
it
{
is_expected
.
to
be_falsy
}
end
end
context
'build is eraseable'
do
let!
(
:build
)
{
create
(
:ci_build_with_trace
,
:artifacts
)
}
describe
'#erase!'
do
before
{
build
.
erase!
}
it
'should remove artifact file'
do
expect
(
build
.
artifacts_file
.
exists?
).
to
be_falsy
end
it
'should remove artifact metadata file'
do
expect
(
build
.
artifacts_metadata
.
exists?
).
to
be_falsy
end
it
'should erase build trace in trace file'
do
expect
(
File
.
zero?
(
build
.
path_to_trace
)).
to
eq
true
end
end
describe
'#eraseable?'
do
subject
{
build
.
eraseable?
}
it
{
is_expected
.
to
eq
true
}
end
describe
'#erase_url'
do
subject
{
build
.
erase_url
}
it
{
is_expected
.
to
be_truthy
}
end
context
'metadata and build trace are not available'
do
let!
(
:build
)
{
create
(
:ci_build
,
:artifacts
)
}
before
{
build
.
remove_artifacts_metadata!
}
describe
'#erase!'
do
it
'should not raise error'
do
expect
{
build
.
erase!
}.
to_not
raise_error
end
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