diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/models/packages | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/debian/group_distribution.rb | 10 | ||||
-rw-r--r-- | app/models/packages/debian/project_distribution.rb | 5 | ||||
-rw-r--r-- | app/models/packages/go/module.rb | 4 | ||||
-rw-r--r-- | app/models/packages/go/module_version.rb | 12 | ||||
-rw-r--r-- | app/models/packages/helm.rb | 9 | ||||
-rw-r--r-- | app/models/packages/helm/file_metadatum.rb | 30 | ||||
-rw-r--r-- | app/models/packages/package.rb | 40 | ||||
-rw-r--r-- | app/models/packages/package_file.rb | 20 |
8 files changed, 94 insertions, 36 deletions
diff --git a/app/models/packages/debian/group_distribution.rb b/app/models/packages/debian/group_distribution.rb index eea7acacc96..50c1ec9f163 100644 --- a/app/models/packages/debian/group_distribution.rb +++ b/app/models/packages/debian/group_distribution.rb @@ -6,4 +6,14 @@ class Packages::Debian::GroupDistribution < ApplicationRecord end include Packages::Debian::Distribution + + def packages + Packages::Package + .for_projects(group.all_projects.public_only) + .with_debian_codename(codename) + end + + def package_files + ::Packages::PackageFile.for_package_ids(packages.select(:id)) + end end diff --git a/app/models/packages/debian/project_distribution.rb b/app/models/packages/debian/project_distribution.rb index 22f1008b3b5..5ac60d789b3 100644 --- a/app/models/packages/debian/project_distribution.rb +++ b/app/models/packages/debian/project_distribution.rb @@ -5,8 +5,9 @@ class Packages::Debian::ProjectDistribution < ApplicationRecord :project end + include Packages::Debian::Distribution + has_many :publications, class_name: 'Packages::Debian::Publication', inverse_of: :distribution, foreign_key: :distribution_id has_many :packages, class_name: 'Packages::Package', through: :publications - - include Packages::Debian::Distribution + has_many :package_files, class_name: 'Packages::PackageFile', through: :packages end diff --git a/app/models/packages/go/module.rb b/app/models/packages/go/module.rb index b38b691ed6c..00d51c21881 100644 --- a/app/models/packages/go/module.rb +++ b/app/models/packages/go/module.rb @@ -18,8 +18,8 @@ module Packages end def version_by(ref: nil, commit: nil) - raise ArgumentError.new 'no filter specified' unless ref || commit - raise ArgumentError.new 'ref and commit are mutually exclusive' if ref && commit + raise ArgumentError, 'no filter specified' unless ref || commit + raise ArgumentError, 'ref and commit are mutually exclusive' if ref && commit if commit return version_by_sha(commit) if commit.is_a? String diff --git a/app/models/packages/go/module_version.rb b/app/models/packages/go/module_version.rb index fd575e6c96c..c442b2416f1 100644 --- a/app/models/packages/go/module_version.rb +++ b/app/models/packages/go/module_version.rb @@ -17,15 +17,15 @@ module Packages delegate :build, to: :@semver, allow_nil: true def initialize(mod, type, commit, name: nil, semver: nil, ref: nil) - raise ArgumentError.new("invalid type '#{type}'") unless VALID_TYPES.include? type - raise ArgumentError.new("mod is required") unless mod - raise ArgumentError.new("commit is required") unless commit + raise ArgumentError, "invalid type '#{type}'" unless VALID_TYPES.include? type + raise ArgumentError, "mod is required" unless mod + raise ArgumentError, "commit is required" unless commit if type == :ref - raise ArgumentError.new("ref is required") unless ref + raise ArgumentError, "ref is required" unless ref elsif type == :pseudo - raise ArgumentError.new("name is required") unless name - raise ArgumentError.new("semver is required") unless semver + raise ArgumentError, "name is required" unless name + raise ArgumentError, "semver is required" unless semver end @mod = mod diff --git a/app/models/packages/helm.rb b/app/models/packages/helm.rb new file mode 100644 index 00000000000..e021b997bf5 --- /dev/null +++ b/app/models/packages/helm.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Packages + module Helm + def self.table_name_prefix + 'packages_helm_' + end + end +end diff --git a/app/models/packages/helm/file_metadatum.rb b/app/models/packages/helm/file_metadatum.rb new file mode 100644 index 00000000000..1771003d1f9 --- /dev/null +++ b/app/models/packages/helm/file_metadatum.rb @@ -0,0 +1,30 @@ +# 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 diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index e510432be8f..36edf646658 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -6,6 +6,7 @@ class Packages::Package < ApplicationRecord include Gitlab::Utils::StrongMemoize DISPLAYABLE_STATUSES = [:default, :error].freeze + INSTALLABLE_STATUSES = [:default].freeze belongs_to :project belongs_to :creator, class_name: 'User' @@ -47,8 +48,10 @@ class Packages::Package < ApplicationRecord validate :package_already_taken, if: :npm? 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.helm_package_regex }, if: :helm? validates :name, format: { with: Gitlab::Regex.npm_package_name_regex }, if: :npm? validates :name, format: { with: Gitlab::Regex.nuget_package_name_regex }, if: :nuget? + validates :name, format: { with: Gitlab::Regex.terraform_module_package_name_regex }, if: :terraform_module? 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? @@ -56,7 +59,8 @@ class Packages::Package < ApplicationRecord validates :version, format: { with: Gitlab::Regex.maven_version_regex }, if: -> { version? && maven? } validates :version, format: { with: Gitlab::Regex.pypi_version_regex }, if: :pypi? validates :version, format: { with: Gitlab::Regex.prefixed_semver_regex }, if: :golang? - validates :version, format: { with: Gitlab::Regex.semver_regex }, if: -> { composer_tag_version? || npm? } + validates :version, format: { with: Gitlab::Regex.prefixed_semver_regex }, if: :helm? + validates :version, format: { with: Gitlab::Regex.semver_regex }, if: -> { composer_tag_version? || npm? || terraform_module? } validates :version, presence: true, @@ -70,10 +74,11 @@ class Packages::Package < ApplicationRecord enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6, generic: 7, golang: 8, debian: 9, - rubygems: 10 } + rubygems: 10, helm: 11, terraform_module: 12 } enum status: { default: 0, hidden: 1, processing: 2, error: 3 } + scope :for_projects, ->(project_ids) { where(project_id: project_ids) } scope :with_name, ->(name) { where(name: name) } scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) } scope :with_normalized_pypi_name, ->(name) { where("LOWER(regexp_replace(name, '[-_.]+', '-', 'g')) = ?", name.downcase) } @@ -81,8 +86,10 @@ class Packages::Package < ApplicationRecord scope :with_version, ->(version) { where(version: version) } scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) } scope :with_package_type, ->(package_type) { where(package_type: package_type) } + scope :without_package_type, ->(package_type) { where.not(package_type: package_type) } scope :with_status, ->(status) { where(status: status) } scope :displayable, -> { with_status(DISPLAYABLE_STATUSES) } + scope :installable, -> { with_status(INSTALLABLE_STATUSES) } scope :including_build_info, -> { includes(pipelines: :user) } scope :including_project_route, -> { includes(project: { namespace: :route }) } scope :including_tags, -> { includes(:tags) } @@ -110,25 +117,20 @@ class Packages::Package < ApplicationRecord scope :without_nuget_temporary_name, -> { where.not(name: Packages::Nuget::TEMPORARY_PACKAGE_NAME) } scope :has_version, -> { where.not(version: nil) } - scope :processed, -> do - where.not(package_type: :nuget).or( - where.not(name: Packages::Nuget::TEMPORARY_PACKAGE_NAME) - ) - end scope :preload_files, -> { preload(:package_files) } scope :last_of_each_version, -> { where(id: all.select('MAX(id) AS id').group(:version)) } scope :limit_recent, ->(limit) { order_created_desc.limit(limit) } scope :select_distinct_name, -> { select(:name).distinct } # Sorting - scope :order_created, -> { reorder('created_at ASC') } - scope :order_created_desc, -> { reorder('created_at DESC') } - scope :order_name, -> { reorder('name ASC') } - scope :order_name_desc, -> { reorder('name DESC') } - scope :order_version, -> { reorder('version ASC') } - scope :order_version_desc, -> { reorder('version DESC') } - scope :order_type, -> { reorder('package_type ASC') } - scope :order_type_desc, -> { reorder('package_type DESC') } + scope :order_created, -> { reorder(created_at: :asc) } + scope :order_created_desc, -> { reorder(created_at: :desc) } + scope :order_name, -> { reorder(name: :asc) } + scope :order_name_desc, -> { reorder(name: :desc) } + scope :order_version, -> { reorder(version: :asc) } + scope :order_version_desc, -> { reorder(version: :desc) } + scope :order_type, -> { reorder(package_type: :asc) } + scope :order_type_desc, -> { reorder(package_type: :desc) } scope :order_project_name, -> { joins(:project).reorder('projects.name ASC') } scope :order_project_name_desc, -> { joins(:project).reorder('projects.name DESC') } scope :order_project_path, -> { joins(:project).reorder('projects.path ASC, id ASC') } @@ -137,14 +139,6 @@ class Packages::Package < ApplicationRecord after_commit :update_composer_cache, on: :destroy, if: -> { composer? } - def self.for_projects(projects) - unless Feature.enabled?(:maven_packages_group_level_improvements, default_enabled: :yaml) - return none unless projects.any? - end - - where(project_id: projects) - end - def self.only_maven_packages_with_path(path, use_cte: false) if use_cte && Feature.enabled?(:maven_metadata_by_path_with_optimization_fence, default_enabled: :yaml) # This is an optimization fence which assumes that looking up the Metadatum record by path (globally) diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb index 23a7144e2bb..3d8641ca2fa 100644 --- a/app/models/packages/package_file.rb +++ b/app/models/packages/package_file.rb @@ -5,7 +5,8 @@ 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 :file_type, :component, :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 @@ -24,6 +27,7 @@ class Packages::PackageFile < ApplicationRecord validates :file_name, uniqueness: { scope: :package }, if: -> { package&.pypi? } scope :recent, -> { order(id: :desc) } + scope :for_package_ids, ->(ids) { where(package_id: ids) } scope :with_file_name, ->(file_name) { where(file_name: file_name) } scope :with_file_name_like, ->(file_name) { where(arel_table[:file_name].matches(file_name)) } scope :with_files_stored_locally, -> { where(file_store: ::Packages::PackageFileUploader::Store::LOCAL) } @@ -41,7 +45,17 @@ class Packages::PackageFile < ApplicationRecord scope :with_debian_file_type, ->(file_type) do joins(:debian_file_metadatum) - .where(packages_debian_file_metadata: { debian_file_type: ::Packages::Debian::FileMetadatum.debian_file_types[file_type] }) + .where(packages_debian_file_metadata: { file_type: ::Packages::Debian::FileMetadatum.file_types[file_type] }) + end + + scope :with_debian_component_name, ->(component_name) do + joins(:debian_file_metadatum) + .where(packages_debian_file_metadata: { component: component_name }) + end + + scope :with_debian_architecture_name, ->(architecture_name) do + joins(:debian_file_metadatum) + .where(packages_debian_file_metadata: { architecture: architecture_name }) end scope :with_conan_package_reference, ->(conan_package_reference) do @@ -66,4 +80,4 @@ class Packages::PackageFile < ApplicationRecord end end -Packages::PackageFile.prepend_if_ee('EE::Packages::PackageFile') +Packages::PackageFile.prepend_mod_with('Packages::PackageFile') |