diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-12-19 16:43:19 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-12-19 16:43:19 +0000 |
commit | 0be4b0b74e785a6ea18db0b13d1390608d828aa6 (patch) | |
tree | f175b1cce30eddda9b76354e97808c91574db2d1 /app/models | |
parent | ac22576d80b6d043c4991ad39172976566465693 (diff) | |
parent | d02059ddf3fef105a8e835024b589d9eac2140f0 (diff) | |
download | gitlab-ce-0be4b0b74e785a6ea18db0b13d1390608d828aa6.tar.gz |
Merge branch '36020-private-npm-modules' into 'master'
Do not generate links for private NPM modules in blob view
Closes #36020
See merge request gitlab-org/gitlab-ce!16002
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob_viewer/dependency_manager.rb | 13 | ||||
-rw-r--r-- | app/models/blob_viewer/package_json.rb | 18 |
2 files changed, 28 insertions, 3 deletions
diff --git a/app/models/blob_viewer/dependency_manager.rb b/app/models/blob_viewer/dependency_manager.rb index a8d9be945dc..cc4950240af 100644 --- a/app/models/blob_viewer/dependency_manager.rb +++ b/app/models/blob_viewer/dependency_manager.rb @@ -27,10 +27,17 @@ module BlobViewer private - def package_name_from_json(key) - prepare! + def json_data + @json_data ||= begin + prepare! + JSON.parse(blob.data) + rescue + {} + end + end - JSON.parse(blob.data)[key] rescue nil + def package_name_from_json(key) + json_data[key] end def package_name_from_method_call(name) diff --git a/app/models/blob_viewer/package_json.rb b/app/models/blob_viewer/package_json.rb index 09221efb56c..46cd2f04f4d 100644 --- a/app/models/blob_viewer/package_json.rb +++ b/app/models/blob_viewer/package_json.rb @@ -16,7 +16,25 @@ module BlobViewer @package_name ||= package_name_from_json('name') end + def package_type + private? ? 'private package' : super + end + def package_url + private? ? homepage : npm_url + end + + private + + def private? + !!json_data['private'] + end + + def homepage + json_data['homepage'] + end + + def npm_url "https://www.npmjs.com/package/#{package_name}" end end |