Commit c95b205e authored by Mathieu Parent's avatar Mathieu Parent

Debian Packages

parent 11f71707
......@@ -28,7 +28,7 @@ class Packages::Package < ApplicationRecord
validates :project, 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,
uniqueness: { scope: %i[project_id version package_type] }, unless: :conan?
......@@ -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.generic_package_name_regex }, if: :generic?
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.conan_recipe_component_regex }, if: :conan?
validates :version, format: { with: Gitlab::Regex.maven_version_regex }, if: -> { version? && maven? }
......@@ -51,6 +53,11 @@ class Packages::Package < ApplicationRecord
presence: true,
format: { with: Gitlab::Regex.generic_package_version_regex },
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 }
......@@ -184,6 +191,14 @@ class Packages::Package < ApplicationRecord
tags.pluck(:name)
end
def debian_incoming?
debian? && version.nil?
end
def debian_package?
debian? && !version.nil?
end
private
def composer_tag_version?
......@@ -228,4 +243,13 @@ class Packages::Package < ApplicationRecord
errors.add(:base, _('Package already exists'))
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
......@@ -32253,6 +32253,9 @@ msgstr ""
msgid "cannot be a date in the past"
msgstr ""
msgid "cannot be changed"
msgstr ""
msgid "cannot be changed if a personal project has container registry tags."
msgstr ""
......
......@@ -22,7 +22,14 @@ FactoryBot.define do
end
factory :debian_package do
sequence(:name) { |n| "package-#{n}" }
sequence(:version) { |n| "1.0-#{n}" }
package_type { :debian }
factory :debian_incoming do
name { 'incoming' }
version { nil }
end
end
factory :npm_package do
......
......@@ -111,6 +111,24 @@ RSpec.describe Packages::Package, type: :model do
it { is_expected.not_to allow_value('%foo%bar').for(:name) }
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
subject { build_stubbed(:generic_package) }
......@@ -180,6 +198,21 @@ RSpec.describe Packages::Package, type: :model do
it { is_expected.to allow_value('2.x-dev').for(:version) }
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
subject { build_stubbed(:maven_package) }
......@@ -621,6 +654,46 @@ RSpec.describe Packages::Package, type: :model do
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
Packages::Package.package_types.keys.without('composer').each do |pt|
plan_limit_name = if pt == 'generic'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment