Skip to content

Commit

Permalink
add normalization to pypi package keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Nov 1, 2024
1 parent 9a4a9ea commit 9a7590c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/release_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class ReleasePackage < ApplicationRecord

accepts_nested_attributes_for :engine

# see: https://peps.python.org/pep-0503/#normalized-names
before_save -> { self.key = key.gsub(/[-_.]+/, '-') },
if: -> { pypi? && key_changed? }

validates :product,
scope: { by: :account_id }

Expand Down Expand Up @@ -103,6 +107,10 @@ class ReleasePackage < ApplicationRecord
scope :raw, -> { for_engine_key('raw') }
scope :rubygems, -> { for_engine_key('rubygems') }

delegate :pypi?, :tauri?, :raw?, :rubygems?,
to: :engine,
allow_nil: true

def engine_id? = release_engine_id?
def engine_id = release_engine_id
def engine_id=(id)
Expand Down
12 changes: 12 additions & 0 deletions spec/models/release_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@
end
end
end

it 'should normalize key for pypi package' do
package = create(:package, :pypi, key: 'a_test.key', product:, account:)

expect(package.key).to eq 'a-test-key'
end

it 'should not normalize key for package' do
package = create(:package, key: 'a_test.key', product:, account:)

expect(package.key).to eq 'a_test.key'
end
end

0 comments on commit 9a7590c

Please sign in to comment.