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
2c7f36f4
Commit
2c7f36f4
authored
Feb 02, 2016
by
Grzegorz Bizon
Committed by
Grzegorz Bizon
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update relevant build fields when build is erased
parent
bae37010
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
15 deletions
+58
-15
app/controllers/projects/builds_controller.rb
app/controllers/projects/builds_controller.rb
+1
-1
app/models/ci/build.rb
app/models/ci/build.rb
+3
-3
app/models/ci/build/eraseable.rb
app/models/ci/build/eraseable.rb
+16
-3
spec/models/ci/build/eraseable_spec.rb
spec/models/ci/build/eraseable_spec.rb
+38
-8
No files found.
app/controllers/projects/builds_controller.rb
View file @
2c7f36f4
...
...
@@ -57,7 +57,7 @@ class Projects::BuildsController < Projects::ApplicationController
end
def
erase
@build
.
erase!
@build
.
erase!
(
erased_by:
current_user
)
redirect_to
namespace_project_build_path
(
project
.
namespace
,
project
,
@build
),
notice:
"Build #
#{
@build
.
id
}
has been sucessfully erased!"
end
...
...
app/models/ci/build.rb
View file @
2c7f36f4
...
...
@@ -39,7 +39,7 @@
module
Ci
class
Build
<
CommitStatus
include
Gitlab
::
Application
.
routes
.
url_helpers
include
Eraseable
include
Build
::
Eraseable
LAZY_ATTRIBUTES
=
[
'trace'
]
...
...
@@ -208,8 +208,8 @@ module Ci
end
end
def
trace_empty
?
raw_trace
.
blank
?
def
has_trace
?
raw_trace
.
present
?
end
def
raw_trace
...
...
app/models/ci/build/eraseable.rb
View file @
2c7f36f4
module
Ci
class
Build
module
Eraseable
include
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
def
erase!
included
do
belongs_to
:erased_by
,
class_name:
'User'
end
def
erase!
(
opts
=
{})
raise
StandardError
,
'Build not eraseable!'
unless
eraseable?
remove_artifacts_file!
remove_artifacts_metadata!
erase_trace!
update_erased!
(
opts
[
:erased_by
])
end
def
eraseable?
complete?
&&
(
artifacts
_file
.
exists?
||
!
trace_empty
?
)
complete?
&&
(
artifacts
?
||
has_trace
?
)
end
def
erase_url
...
...
@@ -25,6 +31,13 @@ module Ci
def
erase_trace!
File
.
truncate
(
path_to_trace
,
0
)
if
File
.
file?
(
path_to_trace
)
end
def
update_erased!
(
user
=
nil
)
self
.
erased_by
=
user
if
user
self
.
erased_at
=
Time
.
now
self
.
erased
=
true
self
.
save!
end
end
end
end
spec/models/ci/build/eraseable_spec.rb
View file @
2c7f36f4
require
'spec_helper'
describe
Ci
::
Build
::
Eraseable
,
models:
true
do
shared_examples
'eraseable'
do
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
it
'should set erased to true'
do
expect
(
build
.
erased?
).
to
be
true
end
it
'should set erase date'
do
expect
(
build
.
erased_at
).
to_not
be_falsy
end
end
context
'build is not eraseable'
do
let!
(
:build
)
{
create
(
:ci_build
)
}
...
...
@@ -23,18 +45,26 @@ describe Ci::Build::Eraseable, models: true do
let!
(
:build
)
{
create
(
:ci_build_with_trace
,
:success
,
:artifacts
)
}
describe
'#erase!'
do
before
{
build
.
erase!
}
before
{
build
.
erase!
(
erased_by:
user
)
}
it
'should remove artifact file'
do
expect
(
build
.
artifacts_file
.
exists?
).
to
be_falsy
end
context
'erased by user'
do
let!
(
:user
)
{
create
(
:user
,
username:
'eraser'
)
}
it
'should remove artifact metadata file'
do
expect
(
build
.
artifacts_metadata
.
exists?
).
to
be_falsy
include_examples
'eraseable'
it
'should record user who erased a build'
do
expect
(
build
.
erased_by
).
to
eq
user
end
end
it
'should erase build trace in trace file'
do
expect
(
File
.
zero?
(
build
.
path_to_trace
)).
to
eq
true
context
'erased by system'
do
let
(
:user
)
{
nil
}
include_examples
'eraseable'
it
'should not set user who erased a build'
do
expect
(
build
.
erased_by
).
to
be_nil
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