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
c4fcbae0
Commit
c4fcbae0
authored
Nov 01, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose sast artifact with merge request entity
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
7eec5485
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
1 deletion
+54
-1
app/models/ci/build.rb
app/models/ci/build.rb
+6
-0
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+4
-0
app/models/license.rb
app/models/license.rb
+3
-1
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+8
-0
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+5
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+28
-0
No files found.
app/models/ci/build.rb
View file @
c4fcbae0
...
@@ -41,6 +41,7 @@ module Ci
...
@@ -41,6 +41,7 @@ module Ci
scope
:last_month
,
->
()
{
where
(
'created_at > ?'
,
Date
.
today
-
1
.
month
)
}
scope
:last_month
,
->
()
{
where
(
'created_at > ?'
,
Date
.
today
-
1
.
month
)
}
scope
:manual_actions
,
->
()
{
where
(
when: :manual
,
status:
COMPLETED_STATUSES
+
[
:manual
])
}
scope
:manual_actions
,
->
()
{
where
(
when: :manual
,
status:
COMPLETED_STATUSES
+
[
:manual
])
}
scope
:codequality
,
->
()
{
where
(
name:
%w[codequality codeclimate]
)
}
scope
:codequality
,
->
()
{
where
(
name:
%w[codequality codeclimate]
)
}
scope
:sast
,
->
()
{
where
(
name:
'sast'
)
}
scope
:ref_protected
,
->
{
where
(
protected:
true
)
}
scope
:ref_protected
,
->
{
where
(
protected:
true
)
}
mount_uploader
:artifacts_file
,
ArtifactUploader
mount_uploader
:artifacts_file
,
ArtifactUploader
...
@@ -476,6 +477,11 @@ module Ci
...
@@ -476,6 +477,11 @@ module Ci
artifacts_metadata?
artifacts_metadata?
end
end
def
has_sast_json?
options
.
dig
(
:artifacts
,
:paths
)
==
[
'gl-sast-report.json'
]
&&
artifacts_metadata?
end
def
serializable_hash
(
options
=
{})
def
serializable_hash
(
options
=
{})
super
(
options
).
merge
(
when:
read_attribute
(
:when
))
super
(
options
).
merge
(
when:
read_attribute
(
:when
))
end
end
...
...
app/models/ci/pipeline.rb
View file @
c4fcbae0
...
@@ -485,6 +485,10 @@ module Ci
...
@@ -485,6 +485,10 @@ module Ci
artifacts
.
codequality
.
find
(
&
:has_codeclimate_json?
)
artifacts
.
codequality
.
find
(
&
:has_codeclimate_json?
)
end
end
def
sast_artifact
artifacts
.
sast
.
find
(
&
:has_sast_json?
)
end
def
latest_builds_with_artifacts
def
latest_builds_with_artifacts
@latest_builds_with_artifacts
||=
builds
.
latest
.
with_artifacts
@latest_builds_with_artifacts
||=
builds
.
latest
.
with_artifacts
end
end
...
...
app/models/license.rb
View file @
c4fcbae0
...
@@ -50,7 +50,9 @@ class License < ActiveRecord::Base
...
@@ -50,7 +50,9 @@ class License < ActiveRecord::Base
reject_unsigned_commits
reject_unsigned_commits
]
.
freeze
]
.
freeze
EEU_FEATURES
=
EEP_FEATURES
EEU_FEATURES
=
EEP_FEATURES
+
%i[
sast
]
.
freeze
# List all features available for early adopters,
# List all features available for early adopters,
# i.e. users that started using GitLab.com before
# i.e. users that started using GitLab.com before
...
...
app/serializers/merge_request_entity.rb
View file @
c4fcbae0
...
@@ -202,6 +202,14 @@ class MergeRequestEntity < IssuableEntity
...
@@ -202,6 +202,14 @@ class MergeRequestEntity < IssuableEntity
end
end
end
end
expose
:sast_path
,
if:
->
(
mr
,
_
)
{
mr
.
project
.
feature_available?
(
:sast
)
&&
mr
.
has_sast_data?
&&
can?
(
current_user
,
:read_build
,
mr
.
sast_artifact
)
}
do
|
merge_request
|
raw_project_build_artifacts_url
(
merge_request
.
source_project
,
merge_request
.
sast_artifact
,
path:
'gl-sast-report.json'
)
end
private
private
delegate
:current_user
,
to: :request
delegate
:current_user
,
to: :request
...
...
ee/app/models/ee/merge_request.rb
View file @
c4fcbae0
...
@@ -11,6 +11,7 @@ module EE
...
@@ -11,6 +11,7 @@ module EE
delegate
:codeclimate_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:codeclimate_artifact
,
to: :head_pipeline
,
prefix: :head
,
allow_nil:
true
delegate
:codeclimate_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:codeclimate_artifact
,
to: :base_pipeline
,
prefix: :base
,
allow_nil:
true
delegate
:sast_artifact
,
to: :head_pipeline
,
prefix: :false
,
allow_nil:
true
end
end
def
rebase_dir_path
def
rebase_dir_path
...
@@ -62,5 +63,9 @@ module EE
...
@@ -62,5 +63,9 @@ module EE
!!
(
head_codeclimate_artifact
&
.
success?
&&
!!
(
head_codeclimate_artifact
&
.
success?
&&
base_codeclimate_artifact
&
.
success?
)
base_codeclimate_artifact
&
.
success?
)
end
end
def
has_sast_data?
sast_artifact
&
.
success?
end
end
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
c4fcbae0
...
@@ -1500,4 +1500,32 @@ describe Ci::Pipeline, :mailer do
...
@@ -1500,4 +1500,32 @@ describe Ci::Pipeline, :mailer do
it
{
expect
(
pipeline
.
codeclimate_artifact
).
to
be_nil
}
it
{
expect
(
pipeline
.
codeclimate_artifact
).
to
be_nil
}
end
end
end
end
describe
'#sast_artifact'
do
context
'has sast job'
do
let!
(
:build
)
do
create
(
:ci_build
,
:artifacts
,
name:
'sast'
,
pipeline:
pipeline
,
options:
{
artifacts:
{
paths:
[
'gl-sast-report.json'
]
}
}
)
end
it
{
expect
(
pipeline
.
sast_artifact
).
to
eq
(
build
)
}
end
context
'no sast job'
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
)
end
it
{
expect
(
pipeline
.
sast_artifact
).
to
be_nil
}
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