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
03e60db8
Commit
03e60db8
authored
Oct 01, 2019
by
Tetiana Chupryna
Committed by
Mayra Cabrera
Oct 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass artifact to the service
Remove public send and pass relation
parent
0cd22231
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
13 deletions
+128
-13
ee/app/controllers/projects/security/dependencies_controller.rb
.../controllers/projects/security/dependencies_controller.rb
+7
-12
ee/app/services/security/report_fetch_service.rb
ee/app/services/security/report_fetch_service.rb
+34
-0
ee/lib/api/dependencies.rb
ee/lib/api/dependencies.rb
+1
-1
ee/spec/services/security/report_fetch_service_spec.rb
ee/spec/services/security/report_fetch_service_spec.rb
+86
-0
No files found.
ee/app/controllers/projects/security/dependencies_controller.rb
View file @
03e60db8
...
...
@@ -10,24 +10,15 @@ module Projects
format
.
json
do
::
Gitlab
::
UsageCounters
::
DependencyList
.
increment
(
project
.
id
)
render
json:
serializer
.
represent
(
dependencies
,
build:
build
)
render
json:
serializer
.
represent
(
dependencies
,
build:
report_service
.
build
)
end
end
end
private
def
build
return
unless
pipeline
return
@build
if
@build
@build
=
pipeline
.
builds
.
latest
.
with_reports
(
::
Ci
::
JobArtifact
.
dependency_list_reports
)
.
last
end
def
collect_dependencies
found_dependencies
=
build
&
.
success
?
?
service
.
execute
:
[]
found_dependencies
=
report_service
.
able_to_fetch
?
?
service
.
execute
:
[]
::
Gitlab
::
DependenciesCollection
.
new
(
found_dependencies
)
end
...
...
@@ -46,7 +37,7 @@ module Projects
end
def
pipeline
@pipeline
||=
project
.
all_pipelines
.
latest_successful_for_ref
(
project
.
default_branch
)
@pipeline
||=
report_service
.
pipeline
end
def
query_params
...
...
@@ -55,6 +46,10 @@ module Projects
end
end
def
report_service
@report_service
||=
::
Security
::
ReportFetchService
.
new
(
project
,
::
Ci
::
JobArtifact
.
dependency_list_reports
)
end
def
serializer
serializer
=
::
DependencyListSerializer
.
new
(
project:
project
,
user:
current_user
)
serializer
=
serializer
.
with_pagination
(
request
,
response
)
if
params
[
:page
]
...
...
ee/app/services/security/report_fetch_service.rb
0 → 100644
View file @
03e60db8
# frozen_string_literal: true
module
Security
class
ReportFetchService
def
initialize
(
project
,
artifact
)
@project
=
project
@artifact
=
artifact
end
def
self
.
pipeline_for
(
project
)
project
.
all_pipelines
.
latest_successful_for_ref
(
project
.
default_branch
)
end
def
pipeline
@pipeline
||=
self
.
class
.
pipeline_for
(
project
)
end
def
build
return
unless
pipeline
@build
||=
pipeline
.
builds
.
latest
.
with_reports
(
artifact
)
.
last
end
def
able_to_fetch?
build
&
.
success?
end
private
attr_reader
:project
,
:artifact
end
end
ee/lib/api/dependencies.rb
View file @
03e60db8
...
...
@@ -4,7 +4,7 @@ module API
class
Dependencies
<
Grape
::
API
helpers
do
def
dependencies_by
(
params
)
pipeline
=
user_project
.
all_pipelines
.
latest_successful_for_ref
(
user_project
.
default_branch
)
pipeline
=
::
Security
::
ReportFetchService
.
pipeline_for
(
user_project
)
return
[]
unless
pipeline
...
...
ee/spec/services/security/report_fetch_service_spec.rb
0 → 100644
View file @
03e60db8
# frozen_string_literal: true
require
'spec_helper'
describe
Security
::
ReportFetchService
do
set
(
:project
)
{
create
(
:project
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
artifact
)
}
let
(
:artifact
)
{
::
Ci
::
JobArtifact
.
dependency_list_reports
}
describe
'.pipeline_for'
do
subject
{
described_class
.
pipeline_for
(
project
)
}
context
'with found pipeline'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_dependency_list_report
,
project:
project
)
}
it
{
is_expected
.
to
eq
(
pipeline
)
}
end
context
'without any pipelines'
do
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#pipeline'
do
subject
{
service
.
pipeline
}
context
'with found pipeline'
do
let!
(
:pipeline1
)
{
create
(
:ee_ci_pipeline
,
:with_dependency_list_report
,
project:
project
)
}
let!
(
:pipeline2
)
{
create
(
:ee_ci_pipeline
,
:with_dependency_list_report
,
project:
project
)
}
it
{
is_expected
.
to
eq
(
pipeline2
)
}
end
context
'without any pipelines'
do
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#build'
do
subject
{
service
.
build
}
context
'with right artifacts'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_dependency_list_report
,
project:
project
)
}
let
(
:build
)
{
pipeline
.
builds
.
last
}
it
{
is_expected
.
to
eq
(
build
)
}
end
context
'without right kind of artifacts'
do
let!
(
:pipeline
)
{
create
(
:ee_ci_pipeline
,
:with_sast_report
,
project:
project
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'without found pipeline'
do
it
{
is_expected
.
to
be_nil
}
end
end
describe
'#able_to_fetch?'
do
subject
{
service
.
able_to_fetch?
}
before
do
allow
(
service
).
to
receive
(
:build
).
and_return
(
build
)
end
context
'with successful build'
do
let
(
:build
)
{
create
(
:ci_build
,
:success
)
}
it
{
is_expected
.
to
be_truthy
}
end
context
'with failed build'
do
let
(
:build
)
{
create
(
:ci_build
,
:failed
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'without build'
do
let
(
:build
)
{
nil
}
it
{
is_expected
.
to
be_falsey
}
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