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
2016bd98
Commit
2016bd98
authored
Sep 08, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '205578-store-pkg-creator' into 'master'
Store package creator See merge request gitlab-org/gitlab!41258
parents
7cf505d5
fd97271d
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
60 additions
and
13 deletions
+60
-13
app/models/packages/package.rb
app/models/packages/package.rb
+2
-0
app/services/packages/create_package_service.rb
app/services/packages/create_package_service.rb
+8
-1
changelogs/unreleased/205578-store-pkg-creator.yml
changelogs/unreleased/205578-store-pkg-creator.yml
+5
-0
db/fixtures/development/26_packages.rb
db/fixtures/development/26_packages.rb
+4
-4
spec/factories/packages.rb
spec/factories/packages.rb
+1
-0
spec/models/packages/package_spec.rb
spec/models/packages/package_spec.rb
+1
-0
spec/services/packages/composer/create_package_service_spec.rb
...services/packages/composer/create_package_service_spec.rb
+9
-1
spec/services/packages/conan/create_package_service_spec.rb
spec/services/packages/conan/create_package_service_spec.rb
+6
-4
spec/services/packages/maven/create_package_service_spec.rb
spec/services/packages/maven/create_package_service_spec.rb
+4
-0
spec/services/packages/npm/create_package_service_spec.rb
spec/services/packages/npm/create_package_service_spec.rb
+4
-0
spec/services/packages/nuget/create_package_service_spec.rb
spec/services/packages/nuget/create_package_service_spec.rb
+4
-3
spec/services/packages/pypi/create_package_service_spec.rb
spec/services/packages/pypi/create_package_service_spec.rb
+4
-0
spec/support/shared_examples/services/packages_shared_examples.rb
...port/shared_examples/services/packages_shared_examples.rb
+8
-0
No files found.
app/models/packages/package.rb
View file @
2016bd98
...
...
@@ -5,6 +5,8 @@ class Packages::Package < ApplicationRecord
include
UsageStatistics
belongs_to
:project
belongs_to
:creator
,
class_name:
'User'
# package_files must be destroyed by ruby code in order to properly remove carrierwave uploads and update project statistics
has_many
:package_files
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:dependency_links
,
inverse_of: :package
,
class_name:
'Packages::DependencyLink'
...
...
app/services/packages/create_package_service.rb
View file @
2016bd98
...
...
@@ -8,7 +8,9 @@ module Packages
project
.
packages
.
with_package_type
(
package_type
)
.
safe_find_or_create_by!
(
name:
name
,
version:
version
)
.
safe_find_or_create_by!
(
name:
name
,
version:
version
)
do
|
pkg
|
pkg
.
creator
=
package_creator
end
end
def
create_package!
(
package_type
,
attrs
=
{})
...
...
@@ -22,9 +24,14 @@ module Packages
def
package_attrs
(
attrs
)
{
creator:
package_creator
,
name:
params
[
:name
],
version:
params
[
:version
]
}.
merge
(
attrs
)
end
def
package_creator
current_user
if
current_user
.
is_a?
(
User
)
end
end
end
changelogs/unreleased/205578-store-pkg-creator.yml
0 → 100644
View file @
2016bd98
---
title
:
Record package creator
merge_request
:
41258
author
:
type
:
added
db/fixtures/development/26_packages.rb
View file @
2016bd98
...
...
@@ -21,7 +21,7 @@ class Gitlab::Seeder::Packages
.
gsub
(
'1.0.1'
,
version
))
.
with_indifferent_access
::
Packages
::
Npm
::
CreatePackageService
.
new
(
project
,
project
.
owne
r
,
params
).
execute
::
Packages
::
Npm
::
CreatePackageService
.
new
(
project
,
project
.
creato
r
,
params
).
execute
print
'.'
end
...
...
@@ -38,7 +38,7 @@ class Gitlab::Seeder::Packages
path:
"
#{
name
}
/
#{
version
}
"
}
pkg
=
::
Packages
::
Maven
::
CreatePackageService
.
new
(
project
,
project
.
owne
r
,
params
).
execute
pkg
=
::
Packages
::
Maven
::
CreatePackageService
.
new
(
project
,
project
.
creato
r
,
params
).
execute
%w(maven-metadata.xml my-app-1.0-20180724.124855-1.pom my-app-1.0-20180724.124855-1.jar)
.
each
do
|
filename
|
with_cloned_fixture_file
(
'maven'
,
filename
)
do
|
filepath
|
...
...
@@ -68,7 +68,7 @@ class Gitlab::Seeder::Packages
package_channel:
'stable'
}
pkg
=
::
Packages
::
Conan
::
CreatePackageService
.
new
(
project
,
project
.
owne
r
,
params
).
execute
pkg
=
::
Packages
::
Conan
::
CreatePackageService
.
new
(
project
,
project
.
creato
r
,
params
).
execute
fixtures
=
{
'recipe_files'
=>
%w(conanfile.py conanmanifest.txt)
,
...
...
@@ -103,7 +103,7 @@ class Gitlab::Seeder::Packages
name
=
"MyNugetApp.Package
#{
i
}
"
version
=
"4.2.
#{
i
}
"
pkg
=
::
Packages
::
Nuget
::
CreatePackageService
.
new
(
project
,
project
.
owne
r
,
{}).
execute
pkg
=
::
Packages
::
Nuget
::
CreatePackageService
.
new
(
project
,
project
.
creato
r
,
{}).
execute
# when using ::Packages::Nuget::CreatePackageService, packages have a fixed name and a fixed version.
pkg
.
update!
(
name:
name
,
version:
version
)
...
...
spec/factories/packages.rb
View file @
2016bd98
...
...
@@ -2,6 +2,7 @@
FactoryBot
.
define
do
factory
:package
,
class:
'Packages::Package'
do
project
creator
{
project
&
.
creator
}
name
{
'my/company/app/my-app'
}
sequence
(
:version
)
{
|
n
|
"1.
#{
n
}
-SNAPSHOT"
}
package_type
{
:maven
}
...
...
spec/models/packages/package_spec.rb
View file @
2016bd98
...
...
@@ -6,6 +6,7 @@ RSpec.describe Packages::Package, type: :model do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:creator
)
}
it
{
is_expected
.
to
have_many
(
:package_files
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:dependency_links
).
inverse_of
(
:package
)
}
it
{
is_expected
.
to
have_many
(
:tags
).
inverse_of
(
:package
)
}
...
...
spec/services/packages/composer/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -37,12 +37,16 @@ RSpec.describe Packages::Composer::CreatePackageService do
expect
(
created_package
.
composer_metadatum
.
target_sha
).
to
eq
branch
.
target
expect
(
created_package
.
composer_metadatum
.
composer_json
.
to_json
).
to
eq
json
end
it_behaves_like
'assigns the package creator'
do
let
(
:package
)
{
created_package
}
end
end
context
'with a tag'
do
let
(
:tag
)
{
project
.
repository
.
find_tag
(
'v1.2.3'
)
}
before
do
before
(
:all
)
do
project
.
repository
.
add_tag
(
user
,
'v1.2.3'
,
'master'
)
end
...
...
@@ -54,6 +58,10 @@ RSpec.describe Packages::Composer::CreatePackageService do
expect
(
created_package
.
name
).
to
eq
package_name
expect
(
created_package
.
version
).
to
eq
'1.2.3'
end
it_behaves_like
'assigns the package creator'
do
let
(
:package
)
{
created_package
}
end
end
end
...
...
spec/services/packages/conan/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -5,9 +5,11 @@ RSpec.describe Packages::Conan::CreatePackageService do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
project
,
user
,
params
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
describe
'#execute'
do
subject
(
:package
)
{
service
.
execute
}
context
'valid params'
do
let
(
:params
)
do
{
...
...
@@ -19,8 +21,6 @@ RSpec.describe Packages::Conan::CreatePackageService do
end
it
'creates a new package'
do
package
=
subject
.
execute
expect
(
package
).
to
be_valid
expect
(
package
.
name
).
to
eq
(
params
[
:package_name
])
expect
(
package
.
version
).
to
eq
(
params
[
:package_version
])
...
...
@@ -28,6 +28,8 @@ RSpec.describe Packages::Conan::CreatePackageService do
expect
(
package
.
conan_metadatum
.
package_username
).
to
eq
(
params
[
:package_username
])
expect
(
package
.
conan_metadatum
.
package_channel
).
to
eq
(
params
[
:package_channel
])
end
it_behaves_like
'assigns the package creator'
end
context
'invalid params'
do
...
...
@@ -41,7 +43,7 @@ RSpec.describe Packages::Conan::CreatePackageService do
end
it
'fails'
do
expect
{
subject
.
execut
e
}.
to
raise_exception
(
ActiveRecord
::
RecordInvalid
)
expect
{
packag
e
}.
to
raise_exception
(
ActiveRecord
::
RecordInvalid
)
end
end
end
...
...
spec/services/packages/maven/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -34,6 +34,8 @@ RSpec.describe Packages::Maven::CreatePackageService do
end
it_behaves_like
'assigns build to package'
it_behaves_like
'assigns the package creator'
end
context
'without version'
do
...
...
@@ -57,6 +59,8 @@ RSpec.describe Packages::Maven::CreatePackageService do
expect
(
package
.
maven_metadatum
.
app_name
).
to
eq
(
app_name
)
expect
(
package
.
maven_metadatum
.
app_version
).
to
be
nil
end
it_behaves_like
'assigns the package creator'
end
context
'path is missing'
do
...
...
spec/services/packages/npm/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -27,6 +27,10 @@ RSpec.describe Packages::Npm::CreatePackageService do
.
and
change
{
Packages
::
Tag
.
count
}.
by
(
1
)
end
it_behaves_like
'assigns the package creator'
do
let
(
:package
)
{
subject
}
end
it
{
is_expected
.
to
be_valid
}
it
'creates a package with name and version'
do
...
...
spec/services/packages/nuget/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -9,9 +9,10 @@ RSpec.describe Packages::Nuget::CreatePackageService do
describe
'#execute'
do
subject
{
described_class
.
new
(
project
,
user
,
params
).
execute
}
let
(
:package
)
{
Packages
::
Package
.
last
}
it
'creates the package'
do
expect
{
subject
}.
to
change
{
Packages
::
Package
.
count
}.
by
(
1
)
package
=
Packages
::
Package
.
last
expect
(
package
).
to
be_valid
expect
(
package
.
name
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
TEMPORARY_PACKAGE_NAME
)
...
...
@@ -23,12 +24,12 @@ RSpec.describe Packages::Nuget::CreatePackageService do
expect
{
subject
}.
to
change
{
Packages
::
Package
.
count
}.
by
(
1
)
expect
{
described_class
.
new
(
project
,
user
,
params
).
execute
}.
to
change
{
Packages
::
Package
.
count
}.
by
(
1
)
package
=
Packages
::
Package
.
last
expect
(
package
).
to
be_valid
expect
(
package
.
name
).
to
eq
(
Packages
::
Nuget
::
CreatePackageService
::
TEMPORARY_PACKAGE_NAME
)
expect
(
package
.
version
).
to
start_with
(
Packages
::
Nuget
::
CreatePackageService
::
PACKAGE_VERSION
)
expect
(
package
.
package_type
).
to
eq
(
'nuget'
)
end
it_behaves_like
'assigns the package creator'
end
end
spec/services/packages/pypi/create_package_service_spec.rb
View file @
2016bd98
...
...
@@ -47,6 +47,10 @@ RSpec.describe Packages::Pypi::CreatePackageService do
end
end
it_behaves_like
'assigns the package creator'
do
let
(
:package
)
{
created_package
}
end
context
'with an existing package'
do
before
do
described_class
.
new
(
project
,
user
,
params
).
execute
...
...
spec/support/shared_examples/services/packages_shared_examples.rb
View file @
2016bd98
...
...
@@ -14,6 +14,14 @@ RSpec.shared_examples 'assigns build to package' do
end
end
RSpec
.
shared_examples
'assigns the package creator'
do
it
'assigns the package creator'
do
subject
expect
(
package
.
creator
).
to
eq
user
end
end
RSpec
.
shared_examples
'returns packages'
do
|
container_type
,
user_type
|
context
"for
#{
user_type
}
"
do
before
do
...
...
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