diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/models/packages | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/conan/file_metadatum.rb | 3 | ||||
-rw-r--r-- | app/models/packages/package.rb | 14 | ||||
-rw-r--r-- | app/models/packages/pypi/metadatum.rb | 1 |
3 files changed, 17 insertions, 1 deletions
diff --git a/app/models/packages/conan/file_metadatum.rb b/app/models/packages/conan/file_metadatum.rb index e1ef62b3959..de54580e948 100644 --- a/app/models/packages/conan/file_metadatum.rb +++ b/app/models/packages/conan/file_metadatum.rb @@ -3,6 +3,9 @@ class Packages::Conan::FileMetadatum < ApplicationRecord belongs_to :package_file, inverse_of: :conan_file_metadatum + DEFAULT_PACKAGE_REVISION = '0'.freeze + DEFAULT_RECIPE_REVISION = '0'.freeze + validates :package_file, presence: true validates :recipe_revision, diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index d6633456de4..bda11160957 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -5,6 +5,8 @@ class Packages::Package < ApplicationRecord include UsageStatistics belongs_to :project + belongs_to :creator, class_name: 'User' + # package_files must be destroyed by ruby code in order to properly remove carrierwave uploads and update project statistics has_many :package_files, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :dependency_links, inverse_of: :package, class_name: 'Packages::DependencyLink' @@ -37,8 +39,13 @@ class Packages::Package < ApplicationRecord validates :name, 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.pypi_version_regex }, if: :pypi? + validates :version, + presence: true, + format: { with: Gitlab::Regex.generic_package_version_regex }, + if: :generic? - enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6 } + enum package_type: { maven: 1, npm: 2, conan: 3, nuget: 4, pypi: 5, composer: 6, generic: 7 } scope :with_name, ->(name) { where(name: name) } scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) } @@ -46,6 +53,9 @@ 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 :including_build_info, -> { includes(build_info: { pipeline: :user }) } + scope :including_project_route, -> { includes(project: { namespace: :route }) } + scope :including_tags, -> { includes(:tags) } scope :with_conan_channel, ->(package_channel) do joins(:conan_metadatum).where(packages_conan_metadata: { package_channel: package_channel }) @@ -138,6 +148,8 @@ class Packages::Package < ApplicationRecord def versions project.packages + .including_build_info + .including_tags .with_name(name) .where.not(version: version) .with_package_type(package_type) diff --git a/app/models/packages/pypi/metadatum.rb b/app/models/packages/pypi/metadatum.rb index 7e6456ad964..2e4d61eaf53 100644 --- a/app/models/packages/pypi/metadatum.rb +++ b/app/models/packages/pypi/metadatum.rb @@ -6,6 +6,7 @@ class Packages::Pypi::Metadatum < ApplicationRecord belongs_to :package, -> { where(package_type: :pypi) }, inverse_of: :pypi_metadatum validates :package, presence: true + validates :required_python, length: { maximum: 255 }, allow_blank: true validate :pypi_package_type |