debian-mirror-gitlab/app/services/packages/pypi/create_package_service.rb
2020-11-24 15:15:51 +05:30

43 lines
1 KiB
Ruby

# frozen_string_literal: true
module Packages
module Pypi
class CreatePackageService < ::Packages::CreatePackageService
include ::Gitlab::Utils::StrongMemoize
def execute
::Packages::Package.transaction do
meta = Packages::Pypi::Metadatum.new(
package: created_package,
required_python: params[:requires_python]
)
unless meta.valid?
raise ActiveRecord::RecordInvalid.new(meta)
end
Packages::Pypi::Metadatum.upsert(meta.attributes)
::Packages::CreatePackageFileService.new(created_package, file_params).execute
end
end
private
def created_package
strong_memoize(:created_package) do
find_or_create_package!(:pypi)
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