Skip to content
Snippets Groups Projects

Reproduce Repository X-Ray functionality - Introduce lock file classes

Merged Leaminn Ma requested to merge introduce-lock-file-classes into master
1 unresolved thread
Files
5
@@ -11,7 +11,10 @@ module LockFiles
class Base
include Gitlab::Utils::StrongMemoize
attr_reader :path
# This value is supposed to indicate the version of Repository X-Ray we are using;
# however, it's not applicable here so we just set it to a placeholder value.
# It may be removed entirely in https://gitlab.com/gitlab-org/gitlab/-/issues/479185.
SCANNER_VERSION = '0.0.0'
Lib = Struct.new(:name, :version, keyword_init: true)
@@ -19,10 +22,14 @@ def self.file_name_glob
raise NotImplementedError
end
def self.lang
def self.lang_name
raise NotImplementedError
end
def self.lang
CodeSuggestions::ProgrammingLanguage::LANGUAGE_XRAY_NAMING[lang_name]
end
def self.matches?(path)
File.fnmatch?("**/#{file_name_glob}", path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
end
@@ -42,6 +49,7 @@ def parse!
error('format not recognized or dependencies not present') if libs.blank? && errors.empty?
end
# This hash matches the current XrayReport payload schema
def payload
return unless libs.present?
@@ -49,15 +57,10 @@ def payload
libs: formatted_libs,
checksum: checksum,
fileName: path,
scannerVersion: '0.0.0' # To match current Repository X-Ray payload schema
scannerVersion: SCANNER_VERSION
}
end
def checksum
Digest::SHA256.hexdigest(content)
end
strong_memoize_attr :checksum
def valid?
errors.empty?
end
@@ -70,7 +73,7 @@ def error_message
private
attr_reader :content, :libs, :errors
attr_reader :content, :path, :libs, :errors
def extract_libs
raise NotImplementedError
@@ -87,6 +90,11 @@ def formatted_libs
def error(message)
@errors << message
end
def checksum
Digest::SHA256.hexdigest(content)
end
strong_memoize_attr :checksum
end
end
end
Loading