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
75616e2a
Commit
75616e2a
authored
May 19, 2020
by
Sashi
Committed by
Mayra Cabrera
May 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revamp conan packages factory
Applied from patch by @10io
parent
23193ed0
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
99 additions
and
32 deletions
+99
-32
changelogs/unreleased/sk-216910-validate-package-type.yml
changelogs/unreleased/sk-216910-validate-package-type.yml
+5
-0
ee/app/models/packages/conan/file_metadatum.rb
ee/app/models/packages/conan/file_metadatum.rb
+9
-0
ee/app/models/packages/conan/metadatum.rb
ee/app/models/packages/conan/metadatum.rb
+1
-1
ee/app/models/packages/maven/metadatum.rb
ee/app/models/packages/maven/metadatum.rb
+1
-1
ee/app/models/packages/pypi/metadatum.rb
ee/app/models/packages/pypi/metadatum.rb
+10
-0
ee/spec/factories/packages.rb
ee/spec/factories/packages.rb
+41
-18
ee/spec/models/packages/conan/file_metadatum_spec.rb
ee/spec/models/packages/conan/file_metadatum_spec.rb
+12
-5
ee/spec/models/packages/conan/metadatum_spec.rb
ee/spec/models/packages/conan/metadatum_spec.rb
+2
-2
ee/spec/models/packages/maven/metadatum_spec.rb
ee/spec/models/packages/maven/metadatum_spec.rb
+2
-2
ee/spec/models/packages/package_file_spec.rb
ee/spec/models/packages/package_file_spec.rb
+3
-3
ee/spec/models/packages/pypi/metadatum_spec.rb
ee/spec/models/packages/pypi/metadatum_spec.rb
+10
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
changelogs/unreleased/sk-216910-validate-package-type.yml
0 → 100644
View file @
75616e2a
---
title
:
Validate package types in package metadatum models
merge_request
:
32091
author
:
Sashi Kumar
type
:
other
ee/app/models/packages/conan/file_metadatum.rb
View file @
75616e2a
...
...
@@ -14,10 +14,19 @@ class Packages::Conan::FileMetadatum < ApplicationRecord
validates
:conan_package_reference
,
absence:
true
,
if: :recipe_file?
validates
:conan_package_reference
,
format:
{
with:
Gitlab
::
Regex
.
conan_package_reference_regex
},
if: :package_file?
validate
:conan_package_type
enum
conan_file_type:
{
recipe_file:
1
,
package_file:
2
}
RECIPE_FILES
=
%w[conanfile.py conanmanifest.txt]
.
freeze
PACKAGE_FILES
=
%w[conaninfo.txt conanmanifest.txt conan_package.tgz]
.
freeze
PACKAGE_BINARY
=
'conan_package.tgz'
private
def
conan_package_type
unless
package_file
&
.
package
&
.
conan?
errors
.
add
(
:base
,
_
(
'Package type must be Conan'
))
end
end
end
ee/app/models/packages/conan/metadatum.rb
View file @
75616e2a
...
...
@@ -34,7 +34,7 @@ class Packages::Conan::Metadatum < ApplicationRecord
private
def
conan_package_type
unless
package
&&
package
.
conan?
unless
package
&
.
conan?
errors
.
add
(
:base
,
_
(
'Package type must be Conan'
))
end
end
...
...
ee/app/models/packages/maven/metadatum.rb
View file @
75616e2a
...
...
@@ -21,7 +21,7 @@ class Packages::Maven::Metadatum < ApplicationRecord
private
def
maven_package_type
unless
package
&&
package
.
maven?
unless
package
&
.
maven?
errors
.
add
(
:base
,
_
(
'Package type must be Maven'
))
end
end
...
...
ee/app/models/packages/pypi/metadatum.rb
View file @
75616e2a
...
...
@@ -6,4 +6,14 @@ class Packages::Pypi::Metadatum < ApplicationRecord
belongs_to
:package
,
->
{
where
(
package_type: :pypi
)
},
inverse_of: :pypi_metadatum
validates
:package
,
presence:
true
validate
:pypi_package_type
private
def
pypi_package_type
unless
package
&
.
pypi?
errors
.
add
(
:base
,
_
(
'Package type must be PyPi'
))
end
end
end
ee/spec/factories/packages.rb
View file @
75616e2a
...
...
@@ -76,6 +76,10 @@ FactoryBot.define do
factory
:conan_package
do
conan_metadatum
transient
do
without_package_files
{
false
}
end
after
:build
do
|
package
|
package
.
conan_metadatum
.
package_username
=
Packages
::
Conan
::
Metadatum
.
package_username_from
(
full_path:
package
.
project
.
full_path
...
...
@@ -86,13 +90,15 @@ FactoryBot.define do
version
{
'1.0.0'
}
package_type
{
:conan
}
after
:create
do
|
package
|
after
:create
do
|
package
,
evaluator
|
unless
evaluator
.
without_package_files
create
:conan_package_file
,
:conan_recipe_file
,
package:
package
create
:conan_package_file
,
:conan_recipe_manifest
,
package:
package
create
:conan_package_file
,
:conan_package_info
,
package:
package
create
:conan_package_file
,
:conan_package_manifest
,
package:
package
create
:conan_package_file
,
:conan_package
,
package:
package
end
end
trait
(
:without_loaded_metadatum
)
do
conan_metadatum
{
build
(
:conan_metadatum
,
package:
nil
)
}
...
...
@@ -107,10 +113,18 @@ FactoryBot.define do
package
factory
:conan_package_file
do
package
{
create
(
:conan_package
,
without_package_files:
true
)
}
transient
do
without_loaded_metadatum
{
false
}
end
trait
(
:conan_recipe_file
)
do
after
:create
do
|
package_file
|
after
:create
do
|
package_file
,
evaluator
|
unless
evaluator
.
without_loaded_metadatum
create
:conan_file_metadatum
,
:recipe_file
,
package_file:
package_file
end
end
file
{
fixture_file_upload
(
'ee/spec/fixtures/conan/recipe_files/conanfile.py'
)
}
file_name
{
'conanfile.py'
}
...
...
@@ -120,9 +134,11 @@ FactoryBot.define do
end
trait
(
:conan_recipe_manifest
)
do
after
:create
do
|
package_file
|
after
:create
do
|
package_file
,
evaluator
|
unless
evaluator
.
without_loaded_metadatum
create
:conan_file_metadatum
,
:recipe_file
,
package_file:
package_file
end
end
file
{
fixture_file_upload
(
'ee/spec/fixtures/conan/recipe_files/conanmanifest.txt'
)
}
file_name
{
'conanmanifest.txt'
}
...
...
@@ -132,9 +148,11 @@ FactoryBot.define do
end
trait
(
:conan_package_manifest
)
do
after
:create
do
|
package_file
|
after
:create
do
|
package_file
,
evaluator
|
unless
evaluator
.
without_loaded_metadatum
create
:conan_file_metadatum
,
:package_file
,
package_file:
package_file
end
end
file
{
fixture_file_upload
(
'ee/spec/fixtures/conan/package_files/conanmanifest.txt'
)
}
file_name
{
'conanmanifest.txt'
}
...
...
@@ -144,9 +162,11 @@ FactoryBot.define do
end
trait
(
:conan_package_info
)
do
after
:create
do
|
package_file
|
after
:create
do
|
package_file
,
evaluator
|
unless
evaluator
.
without_loaded_metadatum
create
:conan_file_metadatum
,
:package_file
,
package_file:
package_file
end
end
file
{
fixture_file_upload
(
'ee/spec/fixtures/conan/package_files/conaninfo.txt'
)
}
file_name
{
'conaninfo.txt'
}
...
...
@@ -156,9 +176,11 @@ FactoryBot.define do
end
trait
(
:conan_package
)
do
after
:create
do
|
package_file
|
after
:create
do
|
package_file
,
evaluator
|
unless
evaluator
.
without_loaded_metadatum
create
:conan_file_metadatum
,
:package_file
,
package_file:
package_file
end
end
file
{
fixture_file_upload
(
'ee/spec/fixtures/conan/package_files/conan_package.tgz'
)
}
file_name
{
'conan_package.tgz'
}
...
...
@@ -238,7 +260,7 @@ FactoryBot.define do
end
factory
:conan_metadatum
,
class:
'Packages::Conan::Metadatum'
do
association
:package
,
factory:
[
:conan_package
,
:without_loaded_metadatum
]
association
:package
,
factory:
[
:conan_package
,
:without_loaded_metadatum
]
,
without_package_files:
true
package_username
{
'username'
}
package_channel
{
'stable'
}
end
...
...
@@ -257,7 +279,7 @@ FactoryBot.define do
end
factory
:conan_file_metadatum
,
class:
'Packages::Conan::FileMetadatum'
do
package_file
package_file
{
create
(
:conan_package_file
,
:conan_recipe_file
,
without_loaded_metadatum:
true
)
}
recipe_revision
{
'0'
}
trait
(
:recipe_file
)
do
...
...
@@ -265,6 +287,7 @@ FactoryBot.define do
end
trait
(
:package_file
)
do
package_file
{
create
(
:conan_package_file
,
:conan_package
,
without_loaded_metadatum:
true
)
}
conan_file_type
{
'package_file'
}
package_revision
{
'0'
}
conan_package_reference
{
'123456789'
}
...
...
ee/spec/models/packages/conan/file_metadatum_spec.rb
View file @
75616e2a
...
...
@@ -8,11 +8,7 @@ RSpec.describe Packages::Conan::FileMetadatum, type: :model do
end
describe
'validations'
do
let
(
:package_file
)
do
create
(
:package_file
,
file:
fixture_file_upload
(
'ee/spec/fixtures/conan/recipe_files/conanfile.py'
),
file_name:
'conanfile.py'
)
end
let
(
:package_file
)
{
create
(
:conan_package_file
,
:conan_recipe_file
)
}
it
{
is_expected
.
to
validate_presence_of
(
:package_file
)
}
it
{
is_expected
.
to
validate_presence_of
(
:recipe_revision
)
}
...
...
@@ -95,5 +91,16 @@ RSpec.describe Packages::Conan::FileMetadatum, type: :model do
end
end
end
describe
'#conan_package_type'
do
it
'validates package of type conan'
do
package
=
build
(
'package'
)
package_file
=
build
(
'package_file'
,
package:
package
)
conan_file_metadatum
=
build
(
'conan_file_metadatum'
,
package_file:
package_file
)
expect
(
conan_file_metadatum
).
not_to
be_valid
expect
(
conan_file_metadatum
.
errors
.
to_a
).
to
contain_exactly
(
'Package type must be Conan'
)
end
end
end
end
ee/spec/models/packages/conan/metadatum_spec.rb
View file @
75616e2a
...
...
@@ -46,12 +46,12 @@ RSpec.describe Packages::Conan::Metadatum, type: :model do
end
describe
'#conan_package_type'
do
it
"will not allow a package with a different package_type"
do
it
'will not allow a package with a different package_type'
do
package
=
build
(
'package'
)
conan_metadatum
=
build
(
'conan_metadatum'
,
package:
package
)
expect
(
conan_metadatum
).
not_to
be_valid
expect
(
conan_metadatum
.
errors
.
to_a
).
to
include
(
"Package type must be Conan"
)
expect
(
conan_metadatum
.
errors
.
to_a
).
to
include
(
'Package type must be Conan'
)
end
end
end
...
...
ee/spec/models/packages/maven/metadatum_spec.rb
View file @
75616e2a
...
...
@@ -28,12 +28,12 @@ RSpec.describe Packages::Maven::Metadatum, type: :model do
end
describe
'#maven_package_type'
do
it
"will not allow a package with a different package_type"
do
it
'will not allow a package with a different package_type'
do
package
=
build
(
'conan_package'
)
maven_metadatum
=
build
(
'maven_metadatum'
,
package:
package
)
expect
(
maven_metadatum
).
not_to
be_valid
expect
(
maven_metadatum
.
errors
.
to_a
).
to
include
(
"Package type must be Maven"
)
expect
(
maven_metadatum
.
errors
.
to_a
).
to
include
(
'Package type must be Maven'
)
end
end
end
...
...
ee/spec/models/packages/package_file_spec.rb
View file @
75616e2a
...
...
@@ -42,12 +42,12 @@ RSpec.describe Packages::PackageFile, type: :model do
describe
'.with_conan_package_reference'
do
let_it_be
(
:non_matching_package_file
)
{
create
(
:package_file
,
:nuget
)
}
let_it_be
(
:
package_file
)
{
create
(
:conan_package_file
,
:conan_packag
e
)
}
let_it_be
(
:reference
)
{
package_file
.
conan_file_
metadatum
.
conan_package_reference
}
let_it_be
(
:
metadatum
)
{
create
(
:conan_file_metadatum
,
:package_fil
e
)
}
let_it_be
(
:reference
)
{
metadatum
.
conan_package_reference
}
it
'returns matching packages'
do
expect
(
described_class
.
with_conan_package_reference
(
reference
))
.
to
eq
([
package_file
])
.
to
eq
([
metadatum
.
package_file
])
end
end
...
...
ee/spec/models/packages/pypi/metadatum_spec.rb
View file @
75616e2a
...
...
@@ -8,5 +8,15 @@ RSpec.describe Packages::Pypi::Metadatum, type: :model do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:package
)
}
describe
'#pypi_package_type'
do
it
'will not allow a package with a different package_type'
do
package
=
build
(
'package'
)
pypi_metadatum
=
build
(
'pypi_metadatum'
,
package:
package
)
expect
(
pypi_metadatum
).
not_to
be_valid
expect
(
pypi_metadatum
.
errors
.
to_a
).
to
include
(
'Package type must be PyPi'
)
end
end
end
end
locale/gitlab.pot
View file @
75616e2a
...
...
@@ -14962,6 +14962,9 @@ msgstr ""
msgid "Package type must be NuGet"
msgstr ""
msgid "Package type must be PyPi"
msgstr ""
msgid "Package was removed"
msgstr ""
...
...
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