Commit c4fcbae0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Expose sast artifact with merge request entity

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 7eec5485
......@@ -41,6 +41,7 @@ module Ci
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
scope :codequality, ->() { where(name: %w[codequality codeclimate]) }
scope :sast, ->() { where(name: 'sast') }
scope :ref_protected, -> { where(protected: true) }
mount_uploader :artifacts_file, ArtifactUploader
......@@ -476,6 +477,11 @@ module Ci
artifacts_metadata?
end
def has_sast_json?
options.dig(:artifacts, :paths) == ['gl-sast-report.json'] &&
artifacts_metadata?
end
def serializable_hash(options = {})
super(options).merge(when: read_attribute(:when))
end
......
......@@ -485,6 +485,10 @@ module Ci
artifacts.codequality.find(&:has_codeclimate_json?)
end
def sast_artifact
artifacts.sast.find(&:has_sast_json?)
end
def latest_builds_with_artifacts
@latest_builds_with_artifacts ||= builds.latest.with_artifacts
end
......
......@@ -50,7 +50,9 @@ class License < ActiveRecord::Base
reject_unsigned_commits
].freeze
EEU_FEATURES = EEP_FEATURES
EEU_FEATURES = EEP_FEATURES + %i[
sast
].freeze
# List all features available for early adopters,
# i.e. users that started using GitLab.com before
......
......@@ -202,6 +202,14 @@ class MergeRequestEntity < IssuableEntity
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
delegate :current_user, to: :request
......
......@@ -11,6 +11,7 @@ module EE
delegate :codeclimate_artifact, to: :head_pipeline, prefix: :head, 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
def rebase_dir_path
......@@ -62,5 +63,9 @@ module EE
!!(head_codeclimate_artifact&.success? &&
base_codeclimate_artifact&.success?)
end
def has_sast_data?
sast_artifact&.success?
end
end
end
......@@ -1500,4 +1500,32 @@ describe Ci::Pipeline, :mailer do
it { expect(pipeline.codeclimate_artifact).to be_nil }
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment