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
8642dd89
Commit
8642dd89
authored
Oct 22, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `license_management:` to use new `reports:` syntax
parent
04d83aec
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
38 additions
and
217 deletions
+38
-217
ee/app/helpers/ee/gitlab_routing_helper.rb
ee/app/helpers/ee/gitlab_routing_helper.rb
+4
-3
ee/app/models/ee/ci/build.rb
ee/app/models/ee/ci/build.rb
+0
-5
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+5
-10
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+0
-4
ee/app/serializers/ee/merge_request_widget_entity.rb
ee/app/serializers/ee/merge_request_widget_entity.rb
+6
-10
ee/app/views/projects/pipelines/_tabs_content.html.haml
ee/app/views/projects/pipelines/_tabs_content.html.haml
+1
-1
ee/spec/controllers/projects/pipelines_controller_spec.rb
ee/spec/controllers/projects/pipelines_controller_spec.rb
+2
-12
ee/spec/factories/ci/job_artifacts.rb
ee/spec/factories/ci/job_artifacts.rb
+18
-0
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+0
-65
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+0
-64
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+0
-33
ee/spec/serializers/merge_request_widget_entity_spec.rb
ee/spec/serializers/merge_request_widget_entity_spec.rb
+2
-10
No files found.
ee/app/helpers/ee/gitlab_routing_helper.rb
View file @
8642dd89
...
...
@@ -30,9 +30,10 @@ module EE
end
def
license_management_artifact_url
(
pipeline
)
raw_project_build_artifacts_url
(
pipeline
.
project
,
pipeline
.
license_management_artifact
,
path:
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
)
return
unless
pipeline
pipeline
.
present
(
current_user:
current_user
)
.
downloadable_path_for_report_type
(
:license_management
)
end
def
license_management_api_url
(
project
)
...
...
ee/app/models/ee/ci/build.rb
View file @
8642dd89
...
...
@@ -33,11 +33,6 @@ module EE
::
Gitlab
::
Database
::
LoadBalancing
::
Sticking
.
stick
(
:build
,
id
)
end
def
has_license_management_json?
name_in?
(
'license_management'
)
&&
has_artifact?
(
LICENSE_MANAGEMENT_FILE
)
end
def
log_geo_deleted_event
# It is not needed to generate a Geo deleted event
# since Legacy Artifacts are migrated to multi-build artifacts
...
...
ee/app/models/ee/ci/pipeline.rb
View file @
8642dd89
...
...
@@ -59,6 +59,10 @@ module EE
performance:
{
names:
%w(performance deploy)
,
files:
%w(performance.json)
},
license_management:
{
names:
%w(license_management)
,
files:
%w(gl-license-management-report.json)
}
}.
freeze
...
...
@@ -101,17 +105,8 @@ module EE
nil
end
def
license_management_artifact
@license_management_artifact
||=
artifacts_with_files
.
find
(
&
:has_license_management_json?
)
end
def
has_license_management_data?
license_management_artifact
&
.
success?
end
def
expose_license_management_data?
project
.
feature_available?
(
:license_management
)
&&
has_license_management_data?
any_report_artifact_for_type
(
:license_management
)
end
def
has_security_reports?
...
...
ee/app/models/ee/merge_request.rb
View file @
8642dd89
...
...
@@ -16,12 +16,8 @@ module EE
validate
:validate_approvals_before_merge
,
unless: :importing?
delegate
:license_management_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:license_management_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:sha
,
to: :head_pipeline
,
prefix: :head_pipeline
,
allow_nil:
true
delegate
:sha
,
to: :base_pipeline
,
prefix: :base_pipeline
,
allow_nil:
true
delegate
:has_license_management_data?
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:expose_license_management_data?
,
to: :head_pipeline
,
allow_nil:
true
delegate
:merge_requests_author_approval?
,
to: :target_project
,
allow_nil:
true
participant
:participant_approvers
...
...
ee/app/serializers/ee/merge_request_widget_entity.rb
View file @
8642dd89
...
...
@@ -56,17 +56,13 @@ module EE
end
end
expose
:license_management
,
if:
->
(
mr
,
_
)
{
mr
.
expose_license_management_data?
}
do
expose
:head_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:read_build
,
mr
.
head_license_management_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
source_project
,
merge_request
.
head_license_management_artifact
,
path:
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
)
expose
:license_management
,
if:
->
(
mr
,
_
)
{
head_pipeline_downloadable_path_for_report_type
(
:license_management
)
}
do
expose
:head_path
do
|
merge_request
|
head_pipeline_downloadable_path_for_report_type
(
:license_management
)
end
expose
:base_path
,
if:
->
(
mr
,
_
)
{
mr
.
base_has_license_management_data?
&&
can?
(
current_user
,
:read_build
,
mr
.
base_license_management_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
target_project
,
merge_request
.
base_license_management_artifact
,
path:
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
)
expose
:base_path
do
|
merge_request
|
base_pipeline_downloadable_path_for_report_type
(
:license_management
)
end
expose
:managed_licenses_path
do
|
merge_request
|
...
...
@@ -77,7 +73,7 @@ module EE
can?
(
current_user
,
:admin_software_license_policy
,
merge_request
)
end
expose
:license_management_settings_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:admin_software_license_policy
,
mr
.
target_project
)
}
do
|
merge_request
|
expose
:license_management_settings_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:admin_software_license_policy
,
mr
.
target_project
)
}
do
|
merge_request
|
license_management_settings_path
(
merge_request
.
target_project
)
end
...
...
ee/app/views/projects/pipelines/_tabs_content.html.haml
View file @
8642dd89
...
...
@@ -27,7 +27,7 @@
-
if
pipeline
.
expose_license_management_data?
#js-tab-licenses
.tab-pane
#js-licenses-app
{
data:
{
license_
head_path:
pipeline
.
expose_license_management_data?
?
license_management_artifact_url
(
pipeline
)
:
nil
,
#js-licenses-app
{
data:
{
license_
management_artifact_url
(
pipeline
)
,
api_url:
license_management_api_url
(
project
),
license_management_settings_path:
license_management_settings_path
,
can_manage_licenses:
can?
(
current_user
,
:admin_software_license_policy
,
project
).
to_s
}
}
ee/spec/controllers/projects/pipelines_controller_spec.rb
View file @
8642dd89
...
...
@@ -83,18 +83,8 @@ describe Projects::PipelinesController do
context
'with a license management artifact'
do
before
do
create
(
:ci_build
,
:success
,
:artifacts
,
name:
'license_management'
,
pipeline:
pipeline
,
options:
{
artifacts:
{
paths:
[
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
]
}
}
)
build
=
create
(
:ci_build
,
pipeline:
pipeline
)
create
(
:ee_ci_job_artifact
,
:license_management
,
build:
build
)
end
context
'with feature enabled'
do
...
...
ee/spec/factories/ci/job_artifacts.rb
View file @
8642dd89
...
...
@@ -21,5 +21,23 @@ FactoryBot.define do
Rails
.
root
.
join
(
'ee/spec/fixtures/reports/security/sast_with_corrupted_data.json'
),
'application/json'
)
end
end
trait
:performance
do
file_format
:raw
file_type
:performance
after
(
:build
)
do
|
artifact
,
_
|
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/trace/sample_trace'
),
'text/plain'
)
end
end
trait
:license_management
do
file_format
:raw
file_type
:license_management
after
(
:build
)
do
|
artifact
,
_
|
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/trace/sample_trace'
),
'text/plain'
)
end
end
ee/spec/models/ci/build_spec.rb
View file @
8642dd89
...
...
@@ -115,71 +115,6 @@ describe Ci::Build do
end
end
build_artifacts_methods
=
{
has_license_management_json?:
{
filename:
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
,
job_names:
%w[license_management]
}
}
build_artifacts_methods
.
each
do
|
method
,
requirements
|
filename
=
requirements
[
:filename
]
job_names
=
requirements
[
:job_names
]
describe
"#
#{
method
}
"
do
job_names
.
each
do
|
job_name
|
context
"with a job named
#{
job_name
}
and a file named
#{
filename
}
"
do
let
(
:build
)
do
create
(
:ci_build
,
:artifacts
,
name:
job_name
,
pipeline:
pipeline
,
options:
{
artifacts:
{
paths:
[
filename
,
'some-other-artifact.txt'
]
}
}
)
end
it
{
expect
(
build
.
send
(
method
)).
to
be_truthy
}
end
end
context
'with an invalid filename'
do
let
(
:build
)
do
create
(
:ci_build
,
:artifacts
,
name:
job_names
.
first
,
pipeline:
pipeline
,
options:
{}
)
end
it
{
expect
(
build
.
send
(
method
)).
to
be_falsey
}
end
context
'with an invalid job name'
do
let
(
:build
)
do
create
(
:ci_build
,
:artifacts
,
pipeline:
pipeline
,
options:
{
artifacts:
{
paths:
[
filename
,
'some-other-artifact.txt'
]
}
}
)
end
it
{
expect
(
build
.
send
(
method
)).
to
be_falsey
}
end
end
end
describe
'.with_security_reports'
do
subject
{
described_class
.
with_security_reports
}
...
...
ee/spec/models/ci/pipeline_spec.rb
View file @
8642dd89
...
...
@@ -20,70 +20,6 @@ describe Ci::Pipeline do
end
end
PIPELINE_ARTIFACTS_METHODS
=
[
{
method: :license_management_artifact
,
options:
[
Ci
::
Build
::
LICENSE_MANAGEMENT_FILE
,
'license_management'
]
}
].
freeze
PIPELINE_ARTIFACTS_METHODS
.
each
do
|
method_test
|
method
,
options
=
method_test
.
values_at
(
:method
,
:options
)
describe
method
.
to_s
do
context
'has corresponding job'
do
let!
(
:build
)
do
filename
,
name
=
options
create
(
:ci_build
,
:artifacts
,
name:
name
,
pipeline:
pipeline
,
options:
{
artifacts:
{
paths:
[
filename
]
}
}
)
end
it
{
expect
(
pipeline
.
send
(
method
)).
to
eq
(
build
)
}
end
context
'no corresponding job'
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
)
end
it
{
expect
(
pipeline
.
send
(
method
)).
to
be_nil
}
end
end
end
%w(performance license_management)
.
each
do
|
type
|
method
=
"has_
#{
type
}
_data?"
describe
"#
#{
method
}
"
do
let
(
:artifact
)
{
double
(
success?:
true
)
}
before
do
allow
(
pipeline
).
to
receive
(
:"
#{
type
}
_artifact"
).
and_return
(
artifact
)
end
it
{
expect
(
pipeline
.
send
(
method
.
to_sym
)).
to
be_truthy
}
end
end
%w(performance license_management)
.
each
do
|
type
|
method
=
"expose_
#{
type
}
_data?"
describe
"#
#{
method
}
"
do
before
do
allow
(
pipeline
).
to
receive
(
:"has_
#{
type
}
_data?"
).
and_return
(
true
)
allow
(
pipeline
.
project
).
to
receive
(
:feature_available?
).
and_return
(
true
)
end
it
{
expect
(
pipeline
.
send
(
method
.
to_sym
)).
to
be_truthy
}
end
end
describe
'#with_legacy_security_reports scope'
do
let
(
:pipeline_1
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
let
(
:pipeline_2
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
)
}
...
...
ee/spec/models/merge_request_spec.rb
View file @
8642dd89
...
...
@@ -40,37 +40,4 @@ describe MergeRequest do
it
{
expect
(
subject
.
base_pipeline
).
to
eq
(
pipeline
)
}
end
describe
'#base_license_management_artifact'
do
before
do
allow
(
subject
.
base_pipeline
).
to
receive
(
:license_management_artifact
)
.
and_return
(
1
)
end
it
'delegates to merge request diff'
do
expect
(
subject
.
base_license_management_artifact
).
to
eq
(
1
)
end
end
describe
'#head_license_management_artifact'
do
before
do
allow
(
subject
.
head_pipeline
).
to
receive
(
:license_management_artifact
)
.
and_return
(
1
)
end
it
'delegates to merge request diff'
do
expect
(
subject
.
head_license_management_artifact
).
to
eq
(
1
)
end
end
describe
'#expose_license_management_data?'
do
before
do
allow
(
subject
.
head_pipeline
).
to
receive
(
:expose_license_management_data?
)
.
and_return
(
1
)
end
it
'delegates to merge request diff'
do
expect
(
subject
.
expose_license_management_data?
).
to
eq
(
1
)
end
end
end
ee/spec/serializers/merge_request_widget_entity_spec.rb
View file @
8642dd89
...
...
@@ -76,16 +76,8 @@ describe MergeRequestWidgetEntity do
describe
'#license_management'
do
before
do
build
=
create
(
:ci_build
,
name:
'license_management'
,
pipeline:
pipeline
)
allow
(
merge_request
).
to
receive_messages
(
expose_license_management_data?:
true
,
base_has_license_management_data?:
true
,
base_license_management_artifact:
build
,
head_license_management_artifact:
build
,
head_pipeline:
pipeline
,
target_project:
project
)
build
=
create
(
:ci_build
,
pipeline:
pipeline
)
create
(
:ee_ci_job_artifact
,
:license_management
,
build:
build
)
end
it
'should not be included, if license management features are off'
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