Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
b0378939
Commit
b0378939
authored
Dec 18, 2017
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not generate links for private NPM modules in blob view
parent
130b03c2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
4 deletions
+74
-4
app/models/blob_viewer/dependency_manager.rb
app/models/blob_viewer/dependency_manager.rb
+10
-3
app/models/blob_viewer/package_json.rb
app/models/blob_viewer/package_json.rb
+12
-0
app/views/projects/blob/viewers/_dependency_manager.html.haml
...views/projects/blob/viewers/_dependency_manager.html.haml
+1
-1
changelogs/unreleased/36020-private-npm-modules.yml
changelogs/unreleased/36020-private-npm-modules.yml
+5
-0
spec/models/blob_viewer/package_json_spec.rb
spec/models/blob_viewer/package_json_spec.rb
+46
-0
No files found.
app/models/blob_viewer/dependency_manager.rb
View file @
b0378939
...
@@ -27,10 +27,17 @@ module BlobViewer
...
@@ -27,10 +27,17 @@ module BlobViewer
private
private
def
package_name_from_json
(
key
)
def
json_data
prepare!
@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
end
def
package_name_from_method_call
(
name
)
def
package_name_from_method_call
(
name
)
...
...
app/models/blob_viewer/package_json.rb
View file @
b0378939
...
@@ -16,8 +16,20 @@ module BlobViewer
...
@@ -16,8 +16,20 @@ module BlobViewer
@package_name
||=
package_name_from_json
(
'name'
)
@package_name
||=
package_name_from_json
(
'name'
)
end
end
def
package_type
private
?
?
'private package'
:
super
end
def
package_url
def
package_url
return
nil
if
private
?
"https://www.npmjs.com/package/
#{
package_name
}
"
"https://www.npmjs.com/package/
#{
package_name
}
"
end
end
private
def
private?
!!
json_data
[
'private'
]
end
end
end
end
end
app/views/projects/blob/viewers/_dependency_manager.html.haml
View file @
b0378939
...
@@ -6,6 +6,6 @@
...
@@ -6,6 +6,6 @@
-
if
viewer
.
package_name
-
if
viewer
.
package_name
and defines a
#{
viewer
.
package_type
}
named
and defines a
#{
viewer
.
package_type
}
named
%strong<
%strong<
=
link_to
viewer
.
package_name
,
viewer
.
package_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
_if
viewer
.
package_url
.
present?
,
viewer
.
package_name
,
viewer
.
package_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
'Learn more'
,
viewer
.
manager_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
'Learn more'
,
viewer
.
manager_url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
changelogs/unreleased/36020-private-npm-modules.yml
0 → 100644
View file @
b0378939
---
title
:
Do not generate links for private NPM modules in blob view
merge_request
:
16002
author
:
Mario de la Ossa
type
:
added
spec/models/blob_viewer/package_json_spec.rb
View file @
b0378939
...
@@ -22,4 +22,50 @@ describe BlobViewer::PackageJson do
...
@@ -22,4 +22,50 @@ describe BlobViewer::PackageJson do
expect
(
subject
.
package_name
).
to
eq
(
'module-name'
)
expect
(
subject
.
package_name
).
to
eq
(
'module-name'
)
end
end
end
end
describe
'#package_url'
do
it
'returns the package URL'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_url
).
to
eq
(
"https://www.npmjs.com/package/
#{
subject
.
package_name
}
"
)
end
end
describe
'#package_type'
do
it
'returns "package"'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_type
).
to
eq
(
'package'
)
end
end
context
'when package.json has "private": true'
do
let
(
:data
)
do
<<-
SPEC
.
strip_heredoc
{
"name": "module-name",
"version": "10.3.1",
"private": true
}
SPEC
end
let
(
:blob
)
{
fake_blob
(
path:
'package.json'
,
data:
data
)
}
subject
{
described_class
.
new
(
blob
)
}
describe
'#package_url'
do
it
'returns nil'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_url
).
to
be_nil
end
end
describe
'#package_type'
do
it
'returns "private package"'
do
expect
(
subject
).
to
receive
(
:prepare!
)
expect
(
subject
.
package_type
).
to
eq
(
'private package'
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment