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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
14e80d14
Commit
14e80d14
authored
Dec 26, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move npm packages lookup into own finder
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
0425cbf5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
5 deletions
+48
-5
ee/app/finders/packages/npm_packages_finder.rb
ee/app/finders/packages/npm_packages_finder.rb
+23
-0
ee/app/models/packages/package.rb
ee/app/models/packages/package.rb
+1
-0
ee/lib/api/npm_packages.rb
ee/lib/api/npm_packages.rb
+3
-5
ee/spec/finders/packages/npm_packages_finder_spec.rb
ee/spec/finders/packages/npm_packages_finder_spec.rb
+21
-0
No files found.
ee/app/finders/packages/npm_packages_finder.rb
0 → 100644
View file @
14e80d14
# frozen_string_literal: true
class
Packages::NpmPackagesFinder
attr_reader
:project
,
:package_name
def
initialize
(
project
,
package_name
)
@project
=
project
@package_name
=
package_name
end
def
execute
packages
end
private
def
packages
project
.
packages
.
only_npm
.
with_name
(
package_name
)
.
last_of_each_version
.
preload_files
end
end
ee/app/models/packages/package.rb
View file @
14e80d14
...
...
@@ -15,6 +15,7 @@ class Packages::Package < ActiveRecord::Base
enum
package_type:
{
maven:
1
,
npm:
2
}
scope
:with_name
,
->
(
name
)
{
where
(
name:
name
)
}
scope
:only_npm
,
->
{
where
(
package_type:
'npm'
)
}
scope
:preload_files
,
->
{
preload
(
:package_files
)
}
def
self
.
for_projects
(
projects
)
...
...
ee/lib/api/npm_packages.rb
View file @
14e80d14
...
...
@@ -41,10 +41,8 @@ module API
authorize!
(
:read_package
,
project
)
forbidden!
unless
project
.
feature_available?
(
:packages
)
packages
=
project
.
packages
.
with_name
(
package_name
)
.
last_of_each_version
.
preload_files
packages
=
::
Packages
::
NpmPackagesFinder
.
new
(
project
,
package_name
).
execute
present
NpmPackagePresenter
.
new
(
project
,
package_name
,
packages
),
with:
EE
::
API
::
Entities
::
NpmPackage
...
...
@@ -69,7 +67,7 @@ module API
get
':id/packages/npm/*package_name/-/*file_name'
,
format:
false
do
authorize_download_package!
package
=
user_project
.
packages
package
=
user_project
.
packages
.
only_npm
.
by_name_and_file_name
(
params
[
:package_name
],
params
[
:file_name
])
package_file
=
::
Packages
::
PackageFileFinder
...
...
ee/spec/finders/packages/npm_packages_finder_spec.rb
0 → 100644
View file @
14e80d14
# frozen_string_literal: true
require
'spec_helper'
describe
Packages
::
NpmPackagesFinder
do
let
(
:package
)
{
create
(
:npm_package
)
}
let
(
:project
)
{
package
.
project
}
describe
'#execute!'
do
it
'returns project packages'
do
finder
=
described_class
.
new
(
project
,
package
.
name
)
expect
(
finder
.
execute
).
to
eq
([
package
])
end
it
'returns an empty collection'
do
finder
=
described_class
.
new
(
project
,
'baz'
)
expect
(
finder
.
execute
).
to
be_empty
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