diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-14 03:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-14 03:08:43 +0300 |
commit | 30da0e79d286cdf137e958ab53ef992f86d8661d (patch) | |
tree | 038ebb1da587e33eb52e764c7a1f37119dd791d6 /app/models/packages | |
parent | 4ea2496094922fc17d9f7f84c2a44d691c483190 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/packages')
-rw-r--r-- | app/models/packages/package.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index 7744e578df5..90a1bb4bc69 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -103,7 +103,15 @@ class Packages::Package < ApplicationRecord 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) } + + scope :with_normalized_pypi_name, ->(name) do + where( + "LOWER(regexp_replace(name, ?, '-', 'g')) = ?", + Gitlab::Regex::Packages::PYPI_NORMALIZED_NAME_REGEX_STRING, + name.downcase + ) + end + scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) } scope :with_version, ->(version) { where(version: version) } scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) } @@ -315,6 +323,13 @@ class Packages::Package < ApplicationRecord ::Packages::MarkPackageFilesForDestructionWorker.perform_async(id) end + # As defined in PEP 503 https://peps.python.org/pep-0503/#normalized-names + def normalized_pypi_name + return name unless pypi? + + name.gsub(/#{Gitlab::Regex::Packages::PYPI_NORMALIZED_NAME_REGEX_STRING}/, '-').downcase + end + private def composer_tag_version? |