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
a0d9e943
Commit
a0d9e943
authored
May 18, 2018
by
Olivier Gonzalez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support both new and old artifact name for code quality
parent
3081b265
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
126 additions
and
15 deletions
+126
-15
ee/app/models/ee/ci/build.rb
ee/app/models/ee/ci/build.rb
+12
-3
ee/app/models/ee/ci/pipeline.rb
ee/app/models/ee/ci/pipeline.rb
+16
-1
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+9
-0
ee/app/serializers/ee/merge_request_widget_entity.rb
ee/app/serializers/ee/merge_request_widget_entity.rb
+18
-2
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+24
-5
ee/spec/models/ci/pipeline_spec.rb
ee/spec/models/ci/pipeline_spec.rb
+5
-4
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+17
-0
ee/spec/serializers/merge_request_widget_entity_spec.rb
ee/spec/serializers/merge_request_widget_entity_spec.rb
+25
-0
No files found.
ee/app/models/ee/ci/build.rb
View file @
a0d9e943
...
...
@@ -7,7 +7,9 @@ module EE
module
Build
extend
ActiveSupport
::
Concern
CODEQUALITY_FILE
=
'gl-code-quality-report.json'
.
freeze
# CODECLIMATE_FILE is deprecated and replaced with CODE_QUALITY_FILE (#5779)
CODECLIMATE_FILE
=
'codeclimate.json'
.
freeze
CODE_QUALITY_FILE
=
'gl-code-quality-report.json'
.
freeze
DEPENDENCY_SCANNING_FILE
=
'gl-dependency-scanning-report.json'
.
freeze
LICENSE_MANAGEMENT_FILE
=
'gl-license-report.json'
.
freeze
SAST_FILE
=
'gl-sast-report.json'
.
freeze
...
...
@@ -18,7 +20,9 @@ module EE
DAST_FILE
=
'gl-dast-report.json'
.
freeze
included
do
scope
:codequality
,
->
{
where
(
name:
%w[code_quality codequality]
)
}
# codeclimate is deprecated and replaced with code_quality (#5779)
scope
:codeclimate
,
->
{
where
(
name:
%w[codeclimate codequality]
)
}
scope
:code_quality
,
->
{
where
(
name:
'code_quality'
)
}
scope
:performance
,
->
{
where
(
name:
%w[performance deploy]
)
}
scope
:sast
,
->
{
where
(
name:
'sast'
)
}
scope
:dependency_scanning
,
->
{
where
(
name:
'dependency_scanning'
)
}
...
...
@@ -46,8 +50,13 @@ module EE
::
Gitlab
::
Database
::
LoadBalancing
::
Sticking
.
stick
(
:build
,
id
)
end
# has_codeclimate_json? is deprecated and replaced with has_code_quality_json? (#5779)
def
has_codeclimate_json?
has_artifact?
(
CODEQUALITY_FILE
)
has_artifact?
(
CODECLIMATE_FILE
)
end
def
has_code_quality_json?
has_artifact?
(
CODE_QUALITY_FILE
)
end
def
has_performance_json?
...
...
ee/app/models/ee/ci/pipeline.rb
View file @
a0d9e943
...
...
@@ -12,8 +12,13 @@ module EE
has_one
:chat_data
,
class_name:
'Ci::PipelineChatData'
end
# codeclimate_artifact is deprecated and replaced with code_quality_artifact (#5779)
def
codeclimate_artifact
@codeclimate_artifact
||=
artifacts
.
codequality
.
find
(
&
:has_codeclimate_json?
)
@codeclimate_artifact
||=
artifacts
.
codeclimate
.
find
(
&
:has_codeclimate_json?
)
end
def
code_quality_artifact
@code_quality_artifact
||=
artifacts
.
code_quality
.
find
(
&
:has_code_quality_json?
)
end
def
performance_artifact
...
...
@@ -78,10 +83,15 @@ module EE
performance_artifact
&
.
success?
end
# has_codeclimate_data? is deprecated and replaced with has_code_quality_data? (#5779)
def
has_codeclimate_data?
codeclimate_artifact
&
.
success?
end
def
has_code_quality_data?
code_quality_artifact
&
.
success?
end
def
expose_sast_data?
project
.
feature_available?
(
:sast
)
&&
has_sast_data?
...
...
@@ -118,9 +128,14 @@ module EE
has_performance_data?
end
# expose_codeclimate_data? is deprecated and replaced with expose_code_quality_data? (#5779)
def
expose_codeclimate_data?
has_codeclimate_data?
end
def
expose_code_quality_data?
has_code_quality_data?
end
end
end
end
ee/app/models/ee/merge_request.rb
View file @
a0d9e943
...
...
@@ -10,8 +10,11 @@ module EE
has_many
:approvers
,
as: :target
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
has_many
:approver_groups
,
as: :target
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
# codeclimate_artifact is deprecated and replaced with code_quality_artifact (#5779)
delegate
:codeclimate_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:codeclimate_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:code_quality_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:code_quality_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:performance_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:performance_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:sast_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
...
...
@@ -61,11 +64,17 @@ module EE
false
end
# expose_codeclimate_data? is deprecated and replaced with expose_code_quality_data? (#5779)
def
expose_codeclimate_data?
!!
(
head_pipeline
&
.
expose_codeclimate_data?
&&
base_pipeline
&
.
expose_codeclimate_data?
)
end
def
expose_code_quality_data?
!!
(
head_pipeline
&
.
expose_code_quality_data?
&&
base_pipeline
&
.
expose_code_quality_data?
)
end
def
expose_performance_data?
!!
(
head_pipeline
&
.
expose_performance_data?
&&
base_pipeline
&
.
expose_performance_data?
)
...
...
ee/app/serializers/ee/merge_request_widget_entity.rb
View file @
a0d9e943
...
...
@@ -13,17 +13,33 @@ module EE
end
end
# expose_codeclimate_data? is deprecated and replaced with expose_code_quality_data?
expose
:codeclimate
,
if:
->
(
mr
,
_
)
{
mr
.
expose_codeclimate_data?
}
do
expose
:head_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:read_build
,
mr
.
head_codeclimate_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
source_project
,
merge_request
.
head_codeclimate_artifact
,
path:
Ci
::
Build
::
CODE
QUALITY
_FILE
)
path:
Ci
::
Build
::
CODE
CLIMATE
_FILE
)
end
expose
:base_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:read_build
,
mr
.
base_codeclimate_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
target_project
,
merge_request
.
base_codeclimate_artifact
,
path:
Ci
::
Build
::
CODEQUALITY_FILE
)
path:
Ci
::
Build
::
CODECLIMATE_FILE
)
end
end
# We still expose it as `codeclimate` to keep compatibility with Frontend
expose
:codeclimate
,
if:
->
(
mr
,
_
)
{
mr
.
expose_code_quality_data?
}
do
expose
:head_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:read_build
,
mr
.
head_code_quality_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
source_project
,
merge_request
.
head_code_quality_artifact
,
path:
Ci
::
Build
::
CODE_QUALITY_FILE
)
end
expose
:base_path
,
if:
->
(
mr
,
_
)
{
can?
(
current_user
,
:read_build
,
mr
.
base_code_quality_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
target_project
,
merge_request
.
base_code_quality_artifact
,
path:
Ci
::
Build
::
CODE_QUALITY_FILE
)
end
end
...
...
ee/spec/models/ci/build_spec.rb
View file @
a0d9e943
...
...
@@ -13,11 +13,12 @@ describe Ci::Build do
let
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
describe
'.codequality'
do
subject
{
described_class
.
codequality
}
# .codeclimate is deprecated and replaced with .code_quality_artifact (#5779)
describe
'.codeclimate'
do
subject
{
described_class
.
codeclimate
}
context
'when a job name is code
_quality
'
do
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'code
_quality
'
)
}
context
'when a job name is code
climate
'
do
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'code
climate
'
)
}
it
{
is_expected
.
to
include
(
job
)
}
end
...
...
@@ -35,6 +36,22 @@ describe Ci::Build do
end
end
describe
'.code_quality'
do
subject
{
described_class
.
code_quality
}
context
'when a job name is code_quality'
do
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'code_quality'
)
}
it
{
is_expected
.
to
include
(
job
)
}
end
context
'when a job name is irrelevant'
do
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
'codechecker'
)
}
it
{
is_expected
.
not_to
include
(
job
)
}
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
subject
{
job
.
shared_runners_minutes_limit_enabled?
}
...
...
@@ -138,7 +155,9 @@ describe Ci::Build do
end
BUILD_ARTIFACTS_METHODS
=
{
has_codeclimate_json?:
Ci
::
Build
::
CODEQUALITY_FILE
,
# has_codeclimate_json? is deprecated and replaced with code_quality_artifact (#5779)
has_codeclimate_json?:
Ci
::
Build
::
CODECLIMATE_FILE
,
has_code_quality_json?:
Ci
::
Build
::
CODE_QUALITY_FILE
,
has_performance_json?:
Ci
::
Build
::
PERFORMANCE_FILE
,
has_sast_json?:
Ci
::
Build
::
SAST_FILE
,
has_dependency_scanning_json?:
Ci
::
Build
::
DEPENDENCY_SCANNING_FILE
,
...
...
ee/spec/models/ci/pipeline_spec.rb
View file @
a0d9e943
...
...
@@ -18,7 +18,8 @@ describe Ci::Pipeline do
end
PIPELINE_ARTIFACTS_METHODS
=
[
{
method: :codeclimate_artifact
,
options:
[
Ci
::
Build
::
CODEQUALITY_FILE
,
'codequality'
]
},
{
method: :codeclimate_artifact
,
options:
[
Ci
::
Build
::
CODECLIMATE_FILE
,
'codequality'
]
},
{
method: :code_quality_artifact
,
options:
[
Ci
::
Build
::
CODEQUALITY_FILE
,
'code_quality'
]
},
{
method: :performance_artifact
,
options:
[
Ci
::
Build
::
PERFORMANCE_FILE
,
'performance'
]
},
{
method: :sast_artifact
,
options:
[
Ci
::
Build
::
SAST_FILE
,
'sast'
]
},
{
method: :dependency_scanning_artifact
,
options:
[
Ci
::
Build
::
DEPENDENCY_SCANNING_FILE
,
'dependency_scanning'
]
},
...
...
@@ -54,7 +55,7 @@ describe Ci::Pipeline do
it
{
expect
(
pipeline
.
send
(
method
)).
to
eq
(
build
)
}
end
context
'no co
de_quality
job'
do
context
'no co
rresponding
job'
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
)
end
...
...
@@ -64,7 +65,7 @@ describe Ci::Pipeline do
end
end
%w(sast d
ast performance sast_container container_scanning
)
.
each
do
|
type
|
%w(sast d
ependency_scanning dast performance sast_container container_scanning codeclimate code_quality
)
.
each
do
|
type
|
method
=
"has_
#{
type
}
_data?"
describe
"#
#{
method
}
"
do
...
...
@@ -78,7 +79,7 @@ describe Ci::Pipeline do
end
end
%w(sast d
ast performance sast_container container_scanning
)
.
each
do
|
type
|
%w(sast d
ependency_scanning dast performance sast_container container_scanning codeclimate code_quality
)
.
each
do
|
type
|
method
=
"expose_
#{
type
}
_data?"
describe
"#
#{
method
}
"
do
...
...
ee/spec/models/merge_request_spec.rb
View file @
a0d9e943
...
...
@@ -188,6 +188,23 @@ describe MergeRequest do
end
end
describe
'#expose_code_quality_data?'
do
context
'with code_quality data'
do
let
(
:pipeline
)
{
double
(
expose_code_quality_data?:
true
)
}
before
do
allow
(
subject
).
to
receive
(
:head_pipeline
).
and_return
(
pipeline
)
allow
(
subject
).
to
receive
(
:base_pipeline
).
and_return
(
pipeline
)
end
it
{
expect
(
subject
.
expose_code_quality_data?
).
to
be_truthy
}
end
context
'without code_quality data'
do
it
{
expect
(
subject
.
expose_code_quality_data?
).
to
be_falsey
}
end
end
describe
'#expose_performance_data?'
do
context
'with performance data'
do
let
(
:pipeline
)
{
double
(
expose_performance_data?:
true
)
}
...
...
ee/spec/serializers/merge_request_widget_entity_spec.rb
View file @
a0d9e943
...
...
@@ -26,6 +26,31 @@ describe MergeRequestWidgetEntity do
expect
(
subject
.
as_json
[
:blob_path
]).
to
include
(
:head_path
)
end
# methods for old artifact are deprecated and replaced with ones for the new name (#5779)
it
'has codeclimate data (with old artifact name codeclimate,json)'
do
build
=
create
(
:ci_build
,
name:
'job'
)
allow
(
merge_request
).
to
receive_messages
(
expose_codeclimate_data?:
true
,
base_codeclimate_artifact:
build
,
head_codeclimate_artifact:
build
)
expect
(
subject
.
as_json
).
to
include
(
:codeclimate
)
end
it
'has codeclimate data (with new artifact name gl-code-quality-report.json)'
do
build
=
create
(
:ci_build
,
name:
'job'
)
allow
(
merge_request
).
to
receive_messages
(
expose_code_quality_data?:
true
,
base_code_quality_artifact:
build
,
head_code_quality_artifact:
build
)
expect
(
subject
.
as_json
).
to
include
(
:codeclimate
)
end
it
'has performance data'
do
build
=
create
(
:ci_build
,
name:
'job'
)
...
...
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