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
6d3a8f08
Commit
6d3a8f08
authored
Sep 02, 2020
by
Giorgenes Gelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor package object creation
Create a base service for package creation to centralize package creation.
parent
146c43c9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
28 deletions
+44
-28
app/services/packages/composer/create_package_service.rb
app/services/packages/composer/create_package_service.rb
+2
-5
app/services/packages/conan/create_package_service.rb
app/services/packages/conan/create_package_service.rb
+2
-3
app/services/packages/create_package_service.rb
app/services/packages/create_package_service.rb
+30
-0
app/services/packages/maven/create_package_service.rb
app/services/packages/maven/create_package_service.rb
+2
-5
app/services/packages/npm/create_package_service.rb
app/services/packages/npm/create_package_service.rb
+4
-8
app/services/packages/nuget/create_package_service.rb
app/services/packages/nuget/create_package_service.rb
+2
-2
app/services/packages/pypi/create_package_service.rb
app/services/packages/pypi/create_package_service.rb
+2
-5
No files found.
app/services/packages/composer/create_package_service.rb
View file @
6d3a8f08
...
...
@@ -2,7 +2,7 @@
module
Packages
module
Composer
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
include
::
Gitlab
::
Utils
::
StrongMemoize
def
execute
...
...
@@ -21,10 +21,7 @@ module Packages
private
def
created_package
project
.
packages
.
composer
.
safe_find_or_create_by!
(
name:
package_name
,
version:
package_version
)
find_or_create_package!
(
:composer
,
name:
package_name
,
version:
package_version
)
end
def
composer_json
...
...
app/services/packages/conan/create_package_service.rb
View file @
6d3a8f08
...
...
@@ -2,12 +2,11 @@
module
Packages
module
Conan
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
def
execute
project
.
packages
.
create!
(
create_package!
(
:conan
,
name:
params
[
:package_name
],
version:
params
[
:package_version
],
package_type: :conan
,
conan_metadatum_attributes:
{
package_username:
params
[
:package_username
],
package_channel:
params
[
:package_channel
]
...
...
app/services/packages/create_package_service.rb
0 → 100644
View file @
6d3a8f08
# frozen_string_literal: true
module
Packages
class
CreatePackageService
<
BaseService
protected
def
find_or_create_package!
(
package_type
,
name:
params
[
:name
],
version:
params
[
:version
])
project
.
packages
.
with_package_type
(
package_type
)
.
safe_find_or_create_by!
(
name:
name
,
version:
version
)
end
def
create_package!
(
package_type
,
attrs
=
{})
project
.
packages
.
with_package_type
(
package_type
)
.
create!
(
package_attrs
(
attrs
))
end
private
def
package_attrs
(
attrs
)
{
name:
params
[
:name
],
version:
params
[
:version
]
}.
merge
(
attrs
)
end
end
end
app/services/packages/maven/create_package_service.rb
View file @
6d3a8f08
# frozen_string_literal: true
module
Packages
module
Maven
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
def
execute
app_group
,
_
,
app_name
=
params
[
:name
].
rpartition
(
'/'
)
app_group
.
tr!
(
'/'
,
'.'
)
package
=
project
.
packages
.
create!
(
name:
params
[
:name
],
version:
params
[
:version
],
package_type: :maven
,
package
=
create_package!
(
:maven
,
maven_metadatum_attributes:
{
path:
params
[
:path
],
app_group:
app_group
,
...
...
app/services/packages/npm/create_package_service.rb
View file @
6d3a8f08
# frozen_string_literal: true
module
Packages
module
Npm
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
include
Gitlab
::
Utils
::
StrongMemoize
def
execute
...
...
@@ -9,17 +9,13 @@ module Packages
return
error
(
'Package already exists.'
,
403
)
if
current_package_exists?
return
error
(
'File is too large.'
,
400
)
if
file_size_exceeded?
ActiveRecord
::
Base
.
transaction
{
create_package!
}
ActiveRecord
::
Base
.
transaction
{
create_
npm_
package!
}
end
private
def
create_package!
package
=
project
.
packages
.
create!
(
name:
name
,
version:
version
,
package_type:
'npm'
)
def
create_npm_package!
package
=
create_package!
(
:npm
,
name:
name
,
version:
version
)
if
build
.
present?
package
.
create_build_info!
(
pipeline:
build
.
pipeline
)
...
...
app/services/packages/nuget/create_package_service.rb
View file @
6d3a8f08
...
...
@@ -2,12 +2,12 @@
module
Packages
module
Nuget
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
TEMPORARY_PACKAGE_NAME
=
'NuGet.Temporary.Package'
PACKAGE_VERSION
=
'0.0.0'
def
execute
project
.
packages
.
nuget
.
create!
(
create_package!
(
:nuget
,
name:
TEMPORARY_PACKAGE_NAME
,
version:
"
#{
PACKAGE_VERSION
}
-
#{
uuid
}
"
)
...
...
app/services/packages/pypi/create_package_service.rb
View file @
6d3a8f08
...
...
@@ -2,7 +2,7 @@
module
Packages
module
Pypi
class
CreatePackageService
<
Bas
eService
class
CreatePackageService
<
::
Packages
::
CreatePackag
eService
include
::
Gitlab
::
Utils
::
StrongMemoize
def
execute
...
...
@@ -20,10 +20,7 @@ module Packages
def
created_package
strong_memoize
(
:created_package
)
do
project
.
packages
.
pypi
.
safe_find_or_create_by!
(
name:
params
[
:name
],
version:
params
[
:version
])
find_or_create_package!
(
:pypi
)
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