Commit 6e7cc27c authored by Mathieu Parent's avatar Mathieu Parent

Add Packages::Helm::FileMetadatum model

Item 2.2 of https://gitlab.com/gitlab-org/gitlab/-/issues/18997#note_530270349
parent d7b1d778
# frozen_string_literal: true
module Packages
module Helm
def self.table_name_prefix
'packages_helm_'
end
end
end
# frozen_string_literal: true
module Packages
module Helm
class FileMetadatum < ApplicationRecord
self.primary_key = :package_file_id
belongs_to :package_file, inverse_of: :helm_file_metadatum
validates :package_file, presence: true
validate :valid_helm_package_type
validates :channel,
presence: true,
length: { maximum: 63 },
format: { with: Gitlab::Regex.helm_channel_regex }
validates :metadata,
json_schema: { filename: "helm_metadata" }
private
def valid_helm_package_type
return if package_file&.package&.helm?
errors.add(:package_file, _('Package type must be Helm'))
end
end
end
end
......@@ -6,6 +6,7 @@ class Packages::PackageFile < ApplicationRecord
delegate :project, :project_id, to: :package
delegate :conan_file_type, to: :conan_file_metadatum
delegate :file_type, :architecture, :fields, to: :debian_file_metadatum, prefix: :debian
delegate :channel, :metadata, to: :helm_file_metadatum, prefix: :helm
belongs_to :package
......@@ -13,9 +14,11 @@ class Packages::PackageFile < ApplicationRecord
has_many :package_file_build_infos, inverse_of: :package_file, class_name: 'Packages::PackageFileBuildInfo'
has_many :pipelines, through: :package_file_build_infos
has_one :debian_file_metadatum, inverse_of: :package_file, class_name: 'Packages::Debian::FileMetadatum'
has_one :helm_file_metadatum, inverse_of: :package_file, class_name: 'Packages::Helm::FileMetadatum'
accepts_nested_attributes_for :conan_file_metadatum
accepts_nested_attributes_for :debian_file_metadatum
accepts_nested_attributes_for :helm_file_metadatum
validates :package, presence: true
validates :file, presence: true
......
{
"description": "Helm metadata",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"home": {
"type": "string"
},
"sources": {
"type": "array",
"items": {
"type": "string"
}
},
"version": {
"type": "string"
},
"description": {
"type": "string"
},
"keywords": {
"type": "array",
"items": {
"type": "string"
}
},
"maintainers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"url": {
"type": "string"
}
},
"additionalProperties": false
}
},
"icon": {
"type": "string"
},
"apiVersion": {
"type": "string"
},
"condition": {
"type": "string"
},
"tags": {
"type": "string"
},
"appVersion": {
"type": "string"
},
"deprecated": {
"type": "boolean"
},
"annotations": {
"type": "object",
"patternProperties": {
".+": {
"type": "string"
},
"additionalProperties": false
}
},
"kubeVersion": {
"type": "string"
},
"dependencies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"version": {
"type": "string"
},
"repository": {
"type": "string"
},
"condition": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"enabled": {
"type": "boolean"
},
"import-values": {
"type": "array",
"items": {
}
},
"alias": {
"type": "string",
"pattern": "^[a-zA-Z0-9_-]+$"
},
"additionalProperties": false
}
}
},
"type": {
"type": "string",
"enum": ["application", "library"]
}
},
"additionalProperties": false,
"required": [
"name",
"version",
"apiVersion"
]
}
\ No newline at end of file
......@@ -23014,6 +23014,9 @@ msgstr ""
msgid "Package type must be Debian"
msgstr ""
msgid "Package type must be Helm"
msgstr ""
msgid "Package type must be Maven"
msgstr ""
......
......@@ -98,6 +98,16 @@ FactoryBot.define do
sequence(:name) { |n| "package-#{n}" }
sequence(:version) { |n| "v1.0.#{n}" }
package_type { :helm }
transient do
without_package_files { false }
end
after :create do |package, evaluator|
unless evaluator.without_package_files
create :helm_package_file, package: package
end
end
end
factory :npm_package do
......
# frozen_string_literal: true
FactoryBot.define do
factory :helm_file_metadatum, class: 'Packages::Helm::FileMetadatum' do
package_file { association(:helm_package_file, without_loaded_metadatum: true) }
channel { 'stable' }
metadata { { 'name': package_file.package.name, 'version': package_file.package.version, 'apiVersion': 'v2' } }
end
end
......@@ -201,6 +201,23 @@ FactoryBot.define do
end
end
factory :helm_package_file do
package { association(:helm_package, without_package_files: true) }
file_name { "#{package.name}-#{package.version}.tgz" }
file_fixture { "spec/fixtures/packages/helm/rook-ceph-v1.5.8.tgz" }
transient do
without_loaded_metadatum { false }
channel { 'stable' }
end
after :create do |package_file, evaluator|
unless evaluator.without_loaded_metadatum
create :helm_file_metadatum, package_file: package_file, channel: evaluator.channel
end
end
end
trait(:jar) do
file_fixture { 'spec/fixtures/packages/maven/my-app-1.0-20180724.124855-1.jar' }
file_name { 'my-app-1.0-20180724.124855-1.jar' }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Helm::FileMetadatum, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:package_file) }
end
describe 'validations' do
describe '#package_file' do
it { is_expected.to validate_presence_of(:package_file) }
end
describe '#valid_helm_package_type' do
let_it_be_with_reload(:helm_package_file) { create(:helm_package_file) }
let(:helm_file_metadatum) { helm_package_file.helm_file_metadatum }
before do
helm_package_file.package.package_type = :pypi
end
it 'validates package of type helm' do
expect(helm_file_metadatum).not_to be_valid
expect(helm_file_metadatum.errors.to_a).to contain_exactly('Package file Package type must be Helm')
end
end
describe '#channel' do
it 'validates #channel', :aggregate_failures do
is_expected.to validate_presence_of(:channel)
is_expected.to allow_value('a' * 63).for(:channel)
is_expected.not_to allow_value('a' * 64).for(:channel)
is_expected.to allow_value('release').for(:channel)
is_expected.to allow_value('my-repo').for(:channel)
is_expected.to allow_value('my-repo42').for(:channel)
# Do not allow empty
is_expected.not_to allow_value('').for(:channel)
# Do not allow Unicode
is_expected.not_to allow_value('hé').for(:channel)
end
end
describe '#metadata' do
it 'validates #metadata', :aggregate_failures do
is_expected.not_to validate_presence_of(:metadata)
is_expected.to allow_value({ 'name': 'foo', 'version': 'v1.0', 'apiVersion': 'v2' }).for(:metadata)
is_expected.not_to allow_value({}).for(:metadata)
is_expected.not_to allow_value({ 'version': 'v1.0', 'apiVersion': 'v2' }).for(:metadata)
is_expected.not_to allow_value({ 'name': 'foo', 'apiVersion': 'v2' }).for(:metadata)
is_expected.not_to allow_value({ 'name': 'foo', 'version': 'v1.0' }).for(:metadata)
end
end
end
end
......@@ -8,6 +8,7 @@ RSpec.describe Packages::PackageFile, type: :model do
it { is_expected.to have_many(:package_file_build_infos).inverse_of(:package_file) }
it { is_expected.to have_many(:pipelines).through(:package_file_build_infos) }
it { is_expected.to have_one(:debian_file_metadatum).inverse_of(:package_file).class_name('Packages::Debian::FileMetadatum') }
it { is_expected.to have_one(:helm_file_metadatum).inverse_of(:package_file).class_name('Packages::Helm::FileMetadatum') }
end
describe 'validations' do
......
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