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
08dc37d0
Commit
08dc37d0
authored
Dec 01, 2020
by
Alan (Maciej) Paruszewski
Committed by
Jan Provaznik
Dec 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add checking if pipeline needs to be touched
parent
e733d1f4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
4 deletions
+120
-4
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+4
-0
ee/app/models/vulnerabilities/feedback.rb
ee/app/models/vulnerabilities/feedback.rb
+4
-1
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+20
-0
ee/spec/models/vulnerabilities/feedback_spec.rb
ee/spec/models/vulnerabilities/feedback_spec.rb
+79
-0
ee/spec/services/vulnerability_feedback/create_service_spec.rb
...ec/services/vulnerability_feedback/create_service_spec.rb
+13
-3
No files found.
ee/app/models/ee/ci/pipeline.rb
View file @
08dc37d0
...
@@ -80,6 +80,10 @@ module EE
...
@@ -80,6 +80,10 @@ module EE
end
end
end
end
def
needs_touch?
updated_at
<
5
.
minutes
.
ago
end
def
triggers_subscriptions?
def
triggers_subscriptions?
# Currently we trigger subscriptions only for tags.
# Currently we trigger subscriptions only for tags.
tag?
&&
project_has_subscriptions?
tag?
&&
project_has_subscriptions?
...
...
ee/app/models/vulnerabilities/feedback.rb
View file @
08dc37d0
...
@@ -88,7 +88,10 @@ module Vulnerabilities
...
@@ -88,7 +88,10 @@ module Vulnerabilities
end
end
def
touch_pipeline
def
touch_pipeline
pipeline
&
.
touch
pipeline
&
.
touch
if
pipeline
&
.
needs_touch?
rescue
ActiveRecord
::
StaleObjectError
# Often the pipeline has already been updated by creating vulnerability feedback
# in batches. In this case, we can ignore the exception as it's already been touched.
end
end
def
finding
def
finding
...
...
ee/spec/models/ci/pipeline_spec.rb
View file @
08dc37d0
...
@@ -606,4 +606,24 @@ RSpec.describe Ci::Pipeline do
...
@@ -606,4 +606,24 @@ RSpec.describe Ci::Pipeline do
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
end
describe
'#needs_touch?'
do
subject
{
pipeline
.
needs_touch?
}
context
'when pipeline was updated less than 5 minutes ago'
do
before
do
pipeline
.
updated_at
=
4
.
minutes
.
ago
end
it
{
is_expected
.
to
eq
(
false
)
}
end
context
'when pipeline was updated more than 5 minutes ago'
do
before
do
pipeline
.
updated_at
=
6
.
minutes
.
ago
end
it
{
is_expected
.
to
eq
(
true
)
}
end
end
end
end
ee/spec/models/vulnerabilities/feedback_spec.rb
View file @
08dc37d0
...
@@ -79,6 +79,85 @@ RSpec.describe Vulnerabilities::Feedback do
...
@@ -79,6 +79,85 @@ RSpec.describe Vulnerabilities::Feedback do
end
end
end
end
describe
'callbacks'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be_with_refind
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
shared_examples
'touches the pipeline'
do
context
'when feedback is for dismissal'
do
let_it_be_with_refind
(
:feedback
)
{
create
(
:vulnerability_feedback
,
:dismissal
,
project:
project
)
}
context
'when pipeline is not assigned to feedback'
do
it
'does not touch the pipeline'
do
expect
(
pipeline
).
not_to
receive
(
:touch
)
subject
end
end
context
'when pipeline is assigned to feedback'
do
before
do
feedback
.
update
(
pipeline:
pipeline
)
end
context
'when pipeline was updated less than 5 minutes ago'
do
before
do
pipeline
.
touch
(
time:
3
.
minutes
.
ago
)
end
it
'touches the pipeline'
do
expect
(
pipeline
).
not_to
receive
(
:touch
)
subject
end
end
context
'when pipeline was updated more than 5 minutes ago'
do
before
do
pipeline
.
touch
(
time:
6
.
minutes
.
ago
)
end
it
'touches the pipeline'
do
expect
(
pipeline
).
to
receive
(
:touch
)
subject
end
context
'when pipeline touch raises ActiveRecord::StaleObjectError'
do
before
do
allow
(
pipeline
).
to
receive
(
:touch
).
and_raise
(
ActiveRecord
::
StaleObjectError
)
end
it
'does not raise an error'
do
expect
{
subject
}.
not_to
raise_error
end
end
end
end
end
context
'when feedback is not for dismissal'
do
let_it_be_with_refind
(
:feedback
)
{
create
(
:vulnerability_feedback
,
:issue
)
}
context
'when pipeline is not assigned to feedback'
do
it
'does not touch the pipeline'
do
expect
(
pipeline
).
not_to
receive
(
:touch
)
subject
end
end
end
end
context
'after_save :touch_pipeline'
do
subject
{
feedback
.
update!
(
vulnerability_data:
{
category:
'dependency_scanning'
})
}
it_behaves_like
'touches the pipeline'
end
context
'after_destroy :touch_pipeline'
do
subject
{
feedback
.
destroy!
}
it_behaves_like
'touches the pipeline'
end
end
describe
'.with_category'
do
describe
'.with_category'
do
it
'filters by category'
do
it
'filters by category'
do
described_class
.
categories
.
each
do
|
category
,
_
|
described_class
.
categories
.
each
do
|
category
,
_
|
...
...
ee/spec/services/vulnerability_feedback/create_service_spec.rb
View file @
08dc37d0
...
@@ -6,7 +6,7 @@ RSpec.describe VulnerabilityFeedback::CreateService, '#execute' do
...
@@ -6,7 +6,7 @@ RSpec.describe VulnerabilityFeedback::CreateService, '#execute' do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
namespace:
group
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
namespace:
group
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
created_at:
6
.
minutes
.
ago
,
updated_at:
6
.
minutes
.
ago
)
}
let
(
:dismiss_vulnerability
)
{
true
}
let
(
:dismiss_vulnerability
)
{
true
}
before
do
before
do
...
@@ -71,8 +71,18 @@ RSpec.describe VulnerabilityFeedback::CreateService, '#execute' do
...
@@ -71,8 +71,18 @@ RSpec.describe VulnerabilityFeedback::CreateService, '#execute' do
expect
(
feedback
.
merge_request
).
to
be_nil
expect
(
feedback
.
merge_request
).
to
be_nil
end
end
it
'touches pipeline related to feedback'
do
context
'when pipeline was updated more than 5 minutes ago'
do
expect
{
result
}.
to
change
{
pipeline
.
reload
.
updated_at
}
it
'touches pipeline related to feedback'
do
expect
{
result
}.
to
change
{
pipeline
.
reload
.
updated_at
}
end
end
context
'when pipeline was updated less than 5 minutes ago'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
created_at:
4
.
minutes
.
ago
,
updated_at:
4
.
minutes
.
ago
)
}
it
'does not touch pipeline related to feedback'
do
expect
{
result
}.
not_to
change
{
pipeline
.
reload
.
updated_at
}
end
end
end
context
'when feedback params has a comment'
do
context
'when feedback params has a comment'
do
...
...
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