diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/models/packages | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/maven/metadatum.rb | 7 | ||||
-rw-r--r-- | app/models/packages/nuget.rb | 2 | ||||
-rw-r--r-- | app/models/packages/package.rb | 34 | ||||
-rw-r--r-- | app/models/packages/package_file.rb | 4 | ||||
-rw-r--r-- | app/models/packages/rubygems.rb | 10 | ||||
-rw-r--r-- | app/models/packages/rubygems/metadatum.rb | 1 |
6 files changed, 46 insertions, 12 deletions
diff --git a/app/models/packages/maven/metadatum.rb b/app/models/packages/maven/metadatum.rb index b7f27fb9e06..7aed274216b 100644 --- a/app/models/packages/maven/metadatum.rb +++ b/app/models/packages/maven/metadatum.rb @@ -18,6 +18,13 @@ class Packages::Maven::Metadatum < ApplicationRecord validate :maven_package_type + scope :for_package_ids, -> (package_ids) { where(package_id: package_ids) } + scope :order_created, -> { reorder('created_at ASC') } + + def self.pluck_app_name + pluck(:app_name) + end + private def maven_package_type diff --git a/app/models/packages/nuget.rb b/app/models/packages/nuget.rb index 42c167e9b7f..f152eedb8fc 100644 --- a/app/models/packages/nuget.rb +++ b/app/models/packages/nuget.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true module Packages module Nuget + TEMPORARY_PACKAGE_NAME = 'NuGet.Temporary.Package' + def self.table_name_prefix 'packages_nuget_' end diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index 391540634be..993d1123c86 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -40,11 +40,11 @@ class Packages::Package < ApplicationRecord validate :unique_debian_package_name, if: :debian_package? validate :valid_conan_package_recipe, if: :conan? - validate :valid_npm_package_name, if: :npm? validate :valid_composer_global_name, if: :composer? 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.npm_package_name_regex }, if: :npm? 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? @@ -91,6 +91,12 @@ class Packages::Package < ApplicationRecord joins(:conan_metadatum).where(packages_conan_metadata: { package_username: package_username }) end + scope :with_debian_codename, -> (codename) do + debian + .joins(:debian_distribution) + .where(Packages::Debian::ProjectDistribution.table_name => { codename: codename }) + end + scope :preload_debian_file_metadata, -> { preload(package_files: :debian_file_metadatum) } scope :with_composer_target, -> (target) do includes(:composer_metadatum) .joins(:composer_metadatum) @@ -98,12 +104,12 @@ class Packages::Package < ApplicationRecord end scope :preload_composer, -> { preload(:composer_metadatum) } - scope :without_nuget_temporary_name, -> { where.not(name: Packages::Nuget::CreatePackageService::TEMPORARY_PACKAGE_NAME) } + 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::CreatePackageService::TEMPORARY_PACKAGE_NAME) + where.not(name: Packages::Nuget::TEMPORARY_PACKAGE_NAME) ) end scope :preload_files, -> { preload(:package_files) } @@ -126,6 +132,8 @@ class Packages::Package < ApplicationRecord scope :order_project_path_desc, -> { joins(:project).reorder('projects.path DESC, id DESC') } scope :order_by_package_file, -> { joins(:package_files).order('packages_package_files.created_at ASC') } + after_commit :update_composer_cache, on: :destroy, if: -> { composer? } + def self.for_projects(projects) return none unless projects.any? @@ -218,8 +226,20 @@ class Packages::Package < ApplicationRecord end end + def sync_maven_metadata(user) + return unless maven? && version? && user + + ::Packages::Maven::Metadata::SyncWorker.perform_async(user.id, project.id, name) + end + private + def update_composer_cache + return unless composer? + + ::Packages::Composer::CacheUpdateWorker.perform_async(project_id, name, composer_metadatum.version_cache_sha) # rubocop:disable CodeReuse/Worker + end + def composer_tag_version? composer? && !Gitlab::Regex.composer_dev_version_regex.match(version.to_s) end @@ -247,14 +267,6 @@ class Packages::Package < ApplicationRecord end end - def valid_npm_package_name - return unless project&.root_namespace - - unless name =~ %r{\A@#{project.root_namespace.path}/[^/]+\z} - errors.add(:name, 'is not valid') - end - end - def package_already_taken return unless project diff --git a/app/models/packages/package_file.rb b/app/models/packages/package_file.rb index 9059f61b5de..23a7144e2bb 100644 --- a/app/models/packages/package_file.rb +++ b/app/models/packages/package_file.rb @@ -30,6 +30,10 @@ class Packages::PackageFile < ApplicationRecord scope :preload_conan_file_metadata, -> { preload(:conan_file_metadatum) } scope :preload_debian_file_metadata, -> { preload(:debian_file_metadatum) } + scope :for_rubygem_with_file_name, ->(project, file_name) do + joins(:package).merge(project.packages.rubygems).with_file_name(file_name) + end + scope :with_conan_file_type, ->(file_type) do joins(:conan_file_metadatum) .where(packages_conan_file_metadata: { conan_file_type: ::Packages::Conan::FileMetadatum.conan_file_types[file_type] }) diff --git a/app/models/packages/rubygems.rb b/app/models/packages/rubygems.rb new file mode 100644 index 00000000000..1aa6b16f47e --- /dev/null +++ b/app/models/packages/rubygems.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true +module Packages + module Rubygems + TEMPORARY_PACKAGE_NAME = 'Gem.Temporary.Package' + + def self.table_name_prefix + 'packages_rubygems_' + end + end +end diff --git a/app/models/packages/rubygems/metadatum.rb b/app/models/packages/rubygems/metadatum.rb index 42db1f3defc..d4e5feb7c98 100644 --- a/app/models/packages/rubygems/metadatum.rb +++ b/app/models/packages/rubygems/metadatum.rb @@ -3,7 +3,6 @@ module Packages module Rubygems class Metadatum < ApplicationRecord - self.table_name = 'packages_rubygems_metadata' self.primary_key = :package_id belongs_to :package, -> { where(package_type: :rubygems) }, inverse_of: :rubygems_metadatum |