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
c95b205e
Commit
c95b205e
authored
Nov 27, 2020
by
Mathieu Parent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debian Packages
parent
11f71707
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
1 deletion
+108
-1
app/models/packages/package.rb
app/models/packages/package.rb
+25
-1
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/factories/packages.rb
spec/factories/packages.rb
+7
-0
spec/models/packages/package_spec.rb
spec/models/packages/package_spec.rb
+73
-0
No files found.
app/models/packages/package.rb
View file @
c95b205e
...
@@ -28,7 +28,7 @@ class Packages::Package < ApplicationRecord
...
@@ -28,7 +28,7 @@ class Packages::Package < ApplicationRecord
validates
:project
,
presence:
true
validates
:project
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
package_name_regex
},
unless:
->
{
conan?
||
generic?
}
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
package_name_regex
},
unless:
->
{
conan?
||
generic?
||
debian?
}
validates
:name
,
validates
:name
,
uniqueness:
{
scope:
%i[project_id version package_type]
},
unless: :conan?
uniqueness:
{
scope:
%i[project_id version package_type]
},
unless: :conan?
...
@@ -40,6 +40,8 @@ class Packages::Package < ApplicationRecord
...
@@ -40,6 +40,8 @@ class Packages::Package < ApplicationRecord
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
generic_package_name_regex
},
if: :generic?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
generic_package_name_regex
},
if: :generic?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
nuget_package_name_regex
},
if: :nuget?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
nuget_package_name_regex
},
if: :nuget?
validates
:name
,
format:
{
with:
Gitlab
::
Regex
.
debian_package_name_regex
},
if: :debian_package?
validates
:name
,
inclusion:
{
in:
%w[incoming]
},
if: :debian_incoming?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
nuget_version_regex
},
if: :nuget?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
nuget_version_regex
},
if: :nuget?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
conan_recipe_component_regex
},
if: :conan?
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
maven_version_regex
},
if:
->
{
version?
&&
maven?
}
validates
:version
,
format:
{
with:
Gitlab
::
Regex
.
maven_version_regex
},
if:
->
{
version?
&&
maven?
}
...
@@ -51,6 +53,11 @@ class Packages::Package < ApplicationRecord
...
@@ -51,6 +53,11 @@ class Packages::Package < ApplicationRecord
presence:
true
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
generic_package_version_regex
},
format:
{
with:
Gitlab
::
Regex
.
generic_package_version_regex
},
if: :generic?
if: :generic?
validates
:version
,
presence:
true
,
format:
{
with:
Gitlab
::
Regex
.
debian_version_regex
},
if: :debian_package?
validate
:forbidden_debian_changes
,
if: :debian?
enum
package_type:
{
maven:
1
,
npm:
2
,
conan:
3
,
nuget:
4
,
pypi:
5
,
composer:
6
,
generic:
7
,
golang:
8
,
debian:
9
}
enum
package_type:
{
maven:
1
,
npm:
2
,
conan:
3
,
nuget:
4
,
pypi:
5
,
composer:
6
,
generic:
7
,
golang:
8
,
debian:
9
}
...
@@ -184,6 +191,14 @@ class Packages::Package < ApplicationRecord
...
@@ -184,6 +191,14 @@ class Packages::Package < ApplicationRecord
tags
.
pluck
(
:name
)
tags
.
pluck
(
:name
)
end
end
def
debian_incoming?
debian?
&&
version
.
nil?
end
def
debian_package?
debian?
&&
!
version
.
nil?
end
private
private
def
composer_tag_version?
def
composer_tag_version?
...
@@ -228,4 +243,13 @@ class Packages::Package < ApplicationRecord
...
@@ -228,4 +243,13 @@ class Packages::Package < ApplicationRecord
errors
.
add
(
:base
,
_
(
'Package already exists'
))
errors
.
add
(
:base
,
_
(
'Package already exists'
))
end
end
end
end
def
forbidden_debian_changes
return
unless
persisted?
# Debian incoming
if
version_was
.
nil?
||
version
.
nil?
errors
.
add
(
:version
,
_
(
'cannot be changed'
))
if
version_changed?
end
end
end
end
locale/gitlab.pot
View file @
c95b205e
...
@@ -32253,6 +32253,9 @@ msgstr ""
...
@@ -32253,6 +32253,9 @@ msgstr ""
msgid "cannot be a date in the past"
msgid "cannot be a date in the past"
msgstr ""
msgstr ""
msgid "cannot be changed"
msgstr ""
msgid "cannot be changed if a personal project has container registry tags."
msgid "cannot be changed if a personal project has container registry tags."
msgstr ""
msgstr ""
...
...
spec/factories/packages.rb
View file @
c95b205e
...
@@ -22,7 +22,14 @@ FactoryBot.define do
...
@@ -22,7 +22,14 @@ FactoryBot.define do
end
end
factory
:debian_package
do
factory
:debian_package
do
sequence
(
:name
)
{
|
n
|
"package-
#{
n
}
"
}
sequence
(
:version
)
{
|
n
|
"1.0-
#{
n
}
"
}
package_type
{
:debian
}
package_type
{
:debian
}
factory
:debian_incoming
do
name
{
'incoming'
}
version
{
nil
}
end
end
end
factory
:npm_package
do
factory
:npm_package
do
...
...
spec/models/packages/package_spec.rb
View file @
c95b205e
...
@@ -111,6 +111,24 @@ RSpec.describe Packages::Package, type: :model do
...
@@ -111,6 +111,24 @@ RSpec.describe Packages::Package, type: :model do
it
{
is_expected
.
not_to
allow_value
(
'%foo%bar'
).
for
(
:name
)
}
it
{
is_expected
.
not_to
allow_value
(
'%foo%bar'
).
for
(
:name
)
}
end
end
context
'debian package'
do
subject
{
build
(
:debian_package
)
}
it
{
is_expected
.
to
allow_value
(
'0ad'
).
for
(
:name
)
}
it
{
is_expected
.
to
allow_value
(
'g++'
).
for
(
:name
)
}
it
{
is_expected
.
not_to
allow_value
(
'a_b'
).
for
(
:name
)
}
end
context
'debian incoming'
do
subject
{
create
(
:debian_incoming
)
}
# Only 'incoming' is accepted
it
{
is_expected
.
to
allow_value
(
'incoming'
).
for
(
:name
)
}
it
{
is_expected
.
not_to
allow_value
(
'0ad'
).
for
(
:name
)
}
it
{
is_expected
.
not_to
allow_value
(
'g++'
).
for
(
:name
)
}
it
{
is_expected
.
not_to
allow_value
(
'a_b'
).
for
(
:name
)
}
end
context
'generic package'
do
context
'generic package'
do
subject
{
build_stubbed
(
:generic_package
)
}
subject
{
build_stubbed
(
:generic_package
)
}
...
@@ -180,6 +198,21 @@ RSpec.describe Packages::Package, type: :model do
...
@@ -180,6 +198,21 @@ RSpec.describe Packages::Package, type: :model do
it
{
is_expected
.
to
allow_value
(
'2.x-dev'
).
for
(
:version
)
}
it
{
is_expected
.
to
allow_value
(
'2.x-dev'
).
for
(
:version
)
}
end
end
context
'debian package'
do
subject
{
build
(
:debian_package
)
}
it
{
is_expected
.
to
allow_value
(
'2:4.9.5+dfsg-5+deb10u1'
).
for
(
:version
)
}
it
{
is_expected
.
not_to
allow_value
(
'1_0'
).
for
(
:version
)
}
end
context
'debian incoming'
do
subject
{
create
(
:debian_incoming
)
}
it
{
is_expected
.
to
allow_value
(
nil
).
for
(
:version
)
}
it
{
is_expected
.
not_to
allow_value
(
'2:4.9.5+dfsg-5+deb10u1'
).
for
(
:version
)
}
it
{
is_expected
.
not_to
allow_value
(
'1_0'
).
for
(
:version
)
}
end
context
'maven package'
do
context
'maven package'
do
subject
{
build_stubbed
(
:maven_package
)
}
subject
{
build_stubbed
(
:maven_package
)
}
...
@@ -621,6 +654,46 @@ RSpec.describe Packages::Package, type: :model do
...
@@ -621,6 +654,46 @@ RSpec.describe Packages::Package, type: :model do
end
end
end
end
describe
'#debian_incoming?'
do
let
(
:package
)
{
build
(
:package
)
}
subject
{
package
.
debian_incoming?
}
it
{
is_expected
.
to
eq
(
false
)
}
context
'with debian_incoming'
do
let
(
:package
)
{
create
(
:debian_incoming
)
}
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'with debian_package'
do
let
(
:package
)
{
create
(
:debian_package
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
describe
'#debian_package?'
do
let
(
:package
)
{
build
(
:package
)
}
subject
{
package
.
debian_package?
}
it
{
is_expected
.
to
eq
(
false
)
}
context
'with debian_incoming'
do
let
(
:package
)
{
create
(
:debian_incoming
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
context
'with debian_package'
do
let
(
:package
)
{
create
(
:debian_package
)
}
it
{
is_expected
.
to
eq
(
true
)
}
end
end
describe
'plan_limits'
do
describe
'plan_limits'
do
Packages
::
Package
.
package_types
.
keys
.
without
(
'composer'
).
each
do
|
pt
|
Packages
::
Package
.
package_types
.
keys
.
without
(
'composer'
).
each
do
|
pt
|
plan_limit_name
=
if
pt
==
'generic'
plan_limit_name
=
if
pt
==
'generic'
...
...
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