diff --git a/app/models/concerns/security/latest_pipeline_information.rb b/app/models/concerns/security/latest_pipeline_information.rb new file mode 100644 index 0000000000000000000000000000000000000000..87eae3cac682cefeff972f67dccccad2f4c49ded --- /dev/null +++ b/app/models/concerns/security/latest_pipeline_information.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Security + module LatestPipelineInformation + private + + def scanner_enabled?(scan_type) + latest_builds_reports.include?(scan_type) + end + + def latest_builds_reports(only_successful_builds: false) + strong_memoize("latest_builds_reports_#{only_successful_builds}") do + builds = latest_security_builds + builds = builds.select { |build| build.status == 'success' } if only_successful_builds + builds.flat_map do |build| + build.options[:artifacts][:reports].keys + end + end + end + + def latest_security_builds + return [] unless latest_default_branch_pipeline + + ::Security::SecurityJobsFinder.new(pipeline: latest_default_branch_pipeline).execute + + ::Security::LicenseComplianceJobsFinder.new(pipeline: latest_default_branch_pipeline).execute + end + + def latest_default_branch_pipeline + strong_memoize(:pipeline) { latest_pipeline } + end + + def auto_devops_source? + latest_default_branch_pipeline&.auto_devops_source? + end + end +end diff --git a/ee/app/models/concerns/ee/project_security_scanners_information.rb b/ee/app/models/concerns/ee/project_security_scanners_information.rb index 7f0b1eab2db2ed87a1553e01bde6fc4b64d57016..4218cf1d131571bcc618db4aaaa1561c16444269 100644 --- a/ee/app/models/concerns/ee/project_security_scanners_information.rb +++ b/ee/app/models/concerns/ee/project_security_scanners_information.rb @@ -3,7 +3,7 @@ module EE module ProjectSecurityScannersInformation include ::Gitlab::Utils::StrongMemoize - include LatestPipelineInformation + include ::Security::LatestPipelineInformation def available_scanners all_security_scanners.map { |scanner| scanner.upcase.to_s if feature_available?(scanner) }.compact diff --git a/ee/app/models/concerns/latest_pipeline_information.rb b/ee/app/models/concerns/latest_pipeline_information.rb deleted file mode 100644 index db5c3fc382b8f7189f11a0b6f1a370b6980c2f93..0000000000000000000000000000000000000000 --- a/ee/app/models/concerns/latest_pipeline_information.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module LatestPipelineInformation - private - - def scanner_enabled?(scan_type) - latest_builds_reports.include?(scan_type) - end - - def latest_builds_reports(only_successful_builds: false) - strong_memoize("latest_builds_reports_#{only_successful_builds}" ) do - builds = latest_security_builds - builds = builds.select { |build| build.status == 'success' } if only_successful_builds - builds.flat_map do |build| - build.options[:artifacts][:reports].keys - end - end - end - - def latest_security_builds - return [] unless latest_default_branch_pipeline - - ::Security::SecurityJobsFinder.new(pipeline: latest_default_branch_pipeline).execute + - ::Security::LicenseComplianceJobsFinder.new(pipeline: latest_default_branch_pipeline).execute - end - - def latest_default_branch_pipeline - strong_memoize(:pipeline) { latest_pipeline } - end - - def auto_devops_source? - latest_default_branch_pipeline&.auto_devops_source? - end -end diff --git a/ee/app/presenters/projects/security/configuration_presenter.rb b/ee/app/presenters/projects/security/configuration_presenter.rb index 23680bd758fe942768504834f3e88d674642e0fa..33e2a9f02b107eae25662fd1948e0510ad6705f6 100644 --- a/ee/app/presenters/projects/security/configuration_presenter.rb +++ b/ee/app/presenters/projects/security/configuration_presenter.rb @@ -5,7 +5,7 @@ module Projects class ConfigurationPresenter < Gitlab::View::Presenter::Delegated include Gitlab::Utils::StrongMemoize include AutoDevopsHelper - include LatestPipelineInformation + include ::Security::LatestPipelineInformation delegator_override_with Gitlab::Utils::StrongMemoize # TODO: Remove `Gitlab::Utils::StrongMemoize` inclusion as it's duplicate