debian-mirror-gitlab/app/models/blob_viewer/go_mod.rb
2020-06-23 00:09:42 +05:30

43 lines
845 B
Ruby

# frozen_string_literal: true
module BlobViewer
class GoMod < DependencyManager
include ServerSide
include Gitlab::Utils::StrongMemoize
MODULE_REGEX = /
\A (?# beginning of file)
module\s+ (?# module directive)
(?<name>.*?) (?# module name)
\s*(?:\/\/.*)? (?# comment)
(?:\n|\z) (?# newline or end of file)
/x.freeze
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