debian-mirror-gitlab/app/models/blob_viewer/package_json.rb

45 lines
740 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module BlobViewer
class PackageJson < DependencyManager
include ServerSide
self.file_types = %i(package_json)
def manager_name
'npm'
end
def manager_url
'https://www.npmjs.com/'
end
def package_name
@package_name ||= package_name_from_json('name')
end
2018-03-17 18:26:18 +05:30
def package_type
private? ? 'private package' : super
end
2017-09-10 17:25:29 +05:30
def package_url
2018-03-17 18:26:18 +05:30
private? ? homepage : npm_url
end
private
def private?
!!json_data['private']
end
def homepage
2018-11-08 19:23:39 +05:30
url = json_data['homepage']
url if Gitlab::UrlSanitizer.valid?(url)
2018-03-17 18:26:18 +05:30
end
def npm_url
2017-09-10 17:25:29 +05:30
"https://www.npmjs.com/package/#{package_name}"
end
end
end