debian-mirror-gitlab/app/services/packages/pypi/create_package_service.rb

44 lines
1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Pypi
2020-11-24 15:15:51 +05:30
class CreatePackageService < ::Packages::CreatePackageService
2020-07-28 23:09:34 +05:30
include ::Gitlab::Utils::StrongMemoize
def execute
::Packages::Package.transaction do
2020-11-24 15:15:51 +05:30
meta = Packages::Pypi::Metadatum.new(
package: created_package,
2020-07-28 23:09:34 +05:30
required_python: params[:requires_python]
)
2020-11-24 15:15:51 +05:30
unless meta.valid?
raise ActiveRecord::RecordInvalid.new(meta)
end
Packages::Pypi::Metadatum.upsert(meta.attributes)
2020-07-28 23:09:34 +05:30
::Packages::CreatePackageFileService.new(created_package, file_params).execute
end
end
private
def created_package
strong_memoize(:created_package) do
2020-11-24 15:15:51 +05:30
find_or_create_package!(:pypi)
2020-07-28 23:09:34 +05:30
end
end
def file_params
{
file: params[:content],
file_name: params[:content].original_filename,
file_md5: params[:md5_digest],
file_sha256: params[:sha256_digest]
}
end
end
end
end