2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BlobViewer
|
|
|
|
class GoMod < DependencyManager
|
|
|
|
include ServerSide
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
MODULE_REGEX = %r{
|
2020-06-23 00:09:42 +05:30
|
|
|
\A (?# beginning of file)
|
|
|
|
module\s+ (?# module directive)
|
|
|
|
(?<name>.*?) (?# module name)
|
2021-09-30 23:02:18 +05:30
|
|
|
\s*(?://.*)? (?# comment)
|
2020-06-23 00:09:42 +05:30
|
|
|
(?:\n|\z) (?# newline or end of file)
|
2021-09-30 23:02:18 +05:30
|
|
|
}x.freeze
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
self.file_types = %i(go_mod go_sum)
|
|
|
|
|
|
|
|
def manager_name
|
|
|
|
'Go Modules'
|
|
|
|
end
|
|
|
|
|
|
|
|
def manager_url
|
|
|
|
'https://golang.org/ref/mod'
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_type
|
|
|
|
'go'
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_name
|
|
|
|
strong_memoize(:package_name) do
|
|
|
|
next if blob.name != 'go.mod'
|
|
|
|
next unless match = MODULE_REGEX.match(blob.data)
|
|
|
|
|
|
|
|
match[:name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_url
|
|
|
|
Gitlab::Golang.package_url(package_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|