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
ae8529ea
Commit
ae8529ea
authored
Dec 21, 2020
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Pipeline#can_store_security_reports? method to consolidate logic
parent
830379e8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
33 deletions
+50
-33
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+1
-1
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+49
-32
No files found.
ee/app/models/ee/ci/pipeline.rb
View file @
ae8529ea
...
@@ -53,7 +53,7 @@ module EE
...
@@ -53,7 +53,7 @@ module EE
state_machine
:status
do
state_machine
:status
do
after_transition
any
=>
::
Ci
::
Pipeline
.
completed_statuses
do
|
pipeline
|
after_transition
any
=>
::
Ci
::
Pipeline
.
completed_statuses
do
|
pipeline
|
next
unless
pipeline
.
has_reports?
(
::
Ci
::
JobArtifact
.
security_reports
.
or
(
::
Ci
::
JobArtifact
.
license_scanning_reports
))
next
unless
pipeline
.
can_store_security_reports?
pipeline
.
run_after_commit
do
pipeline
.
run_after_commit
do
StoreSecurityReportsWorker
.
perform_async
(
pipeline
.
id
)
if
pipeline
.
default_branch?
StoreSecurityReportsWorker
.
perform_async
(
pipeline
.
id
)
if
pipeline
.
default_branch?
...
...
ee/spec/models/ci/pipeline_spec.rb
View file @
ae8529ea
...
@@ -165,59 +165,76 @@ RSpec.describe Ci::Pipeline do
...
@@ -165,59 +165,76 @@ RSpec.describe Ci::Pipeline do
end
end
describe
'Store security reports worker'
do
describe
'Store security reports worker'
do
using
RSpec
::
Parameterized
::
TableSyntax
shared_examples_for
'storing the security reports'
do
|
transition
|
where
(
:state
,
:transition
)
do
:success
|
:succeed
:failed
|
:drop
:skipped
|
:skip
:cancelled
|
:cancel
end
with_them
do
context
'when pipeline has security reports and ref is the default branch of project'
do
let
(
:default_branch
)
{
pipeline
.
ref
}
let
(
:default_branch
)
{
pipeline
.
ref
}
subject
(
:transition_pipeline
)
{
pipeline
.
update!
(
status_event:
transition
)
}
before
do
before
do
create
(
:ee_ci_build
,
:sast
,
pipeline:
pipeline
,
project:
project
)
allow
(
StoreSecurityReportsWorker
).
to
receive
(
:perform_async
)
allow
(
project
).
to
receive
(
:default_branch
)
{
default_branch
}
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
default_branch
)
allow
(
pipeline
).
to
receive
(
:can_store_security_reports?
).
and_return
(
can_store_security_reports
)
end
end
context
"when transitioning to
#{
params
[
:state
]
}
"
do
context
'when the security reports can be stored for the pipeline'
do
let
(
:can_store_security_reports
)
{
true
}
context
'when the ref is the default branch of project'
do
it
'schedules store security report worker'
do
it
'schedules store security report worker'
do
expect
(
StoreSecurityReportsWorker
).
to
receive
(
:perform_async
).
with
(
pipeline
.
id
)
transition_pipeline
pipeline
.
update!
(
status_event:
transition
)
expect
(
StoreSecurityReportsWorker
).
to
have_received
(
:perform_async
).
with
(
pipeline
.
id
)
end
end
end
end
end
context
'when pipeline does NOT have security reports'
do
context
'when the ref is not the default branch of project'
do
context
"when transitioning to
#{
params
[
:state
]
}
"
do
let
(
:default_branch
)
{
'another_branch'
}
it
'does NOT schedule store security report worker'
do
expect
(
StoreSecurityReportsWorker
).
not_to
receive
(
:perform_async
).
with
(
pipeline
.
id
)
it
'does not schedule store security report worker'
do
transition_pipeline
pipeline
.
update!
(
status_event:
transition
)
expect
(
StoreSecurityReportsWorker
).
not_to
have_received
(
:perform_async
)
end
end
end
end
end
end
context
"when pipeline ref is not the project's default branch"
do
context
'when the security reports can not be stored for the pipeline'
do
let
(
:
default_branch
)
{
'another_branch'
}
let
(
:
can_store_security_reports
)
{
false
}
before
do
context
'when the ref is the default branch of project'
do
stub_licensed_features
(
sast:
true
)
it
'does not schedule store security report worker'
do
allow
(
project
).
to
receive
(
:default_branch
)
{
default_branch
}
transition_pipeline
expect
(
StoreSecurityReportsWorker
).
not_to
have_received
(
:perform_async
)
end
end
end
context
"when transitioning to
#{
params
[
:state
]
}
"
do
context
'when the ref is not the default branch of project'
do
it
'does NOT schedule store security report worker'
do
let
(
:default_branch
)
{
'another_branch'
}
expect
(
StoreSecurityReportsWorker
).
not_to
receive
(
:perform_async
).
with
(
pipeline
.
id
)
it
'does not schedule store security report worker'
do
transition_pipeline
expect
(
StoreSecurityReportsWorker
).
not_to
have_received
(
:perform_async
)
end
end
end
end
pipeline
.
update!
(
status_event:
transition
)
context
'when pipeline is succeeded'
do
it_behaves_like
'storing the security reports'
,
:succeed
end
end
context
'when pipeline is dropped'
do
it_behaves_like
'storing the security reports'
,
:drop
end
end
context
'when pipeline is skipped'
do
it_behaves_like
'storing the security reports'
,
:skip
end
end
context
'when pipeline is canceled'
do
it_behaves_like
'storing the security reports'
,
:cancel
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