2020-07-08 08:09:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Pypi
|
2020-09-03 08:08:47 -04:00
|
|
|
class CreatePackageService < ::Packages::CreatePackageService
|
2020-07-08 08:09:33 -04:00
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def execute
|
|
|
|
::Packages::Package.transaction do
|
2020-09-03 14:08:29 -04:00
|
|
|
meta = Packages::Pypi::Metadatum.new(
|
|
|
|
package: created_package,
|
2020-07-08 08:09:33 -04:00
|
|
|
required_python: params[:requires_python]
|
|
|
|
)
|
|
|
|
|
2020-09-03 14:08:29 -04:00
|
|
|
unless meta.valid?
|
2021-05-04 11:10:36 -04:00
|
|
|
raise ActiveRecord::RecordInvalid, meta
|
2020-09-03 14:08:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Packages::Pypi::Metadatum.upsert(meta.attributes)
|
|
|
|
|
2020-07-08 08:09:33 -04:00
|
|
|
::Packages::CreatePackageFileService.new(created_package, file_params).execute
|
2020-12-03 19:09:55 -05:00
|
|
|
|
|
|
|
created_package
|
2020-07-08 08:09:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def created_package
|
|
|
|
strong_memoize(:created_package) do
|
2020-09-03 08:08:47 -04:00
|
|
|
find_or_create_package!(:pypi)
|
2020-07-08 08:09:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_params
|
|
|
|
{
|
2020-12-03 19:09:55 -05:00
|
|
|
build: params[:build],
|
2020-07-08 08:09:33 -04:00
|
|
|
file: params[:content],
|
|
|
|
file_name: params[:content].original_filename,
|
|
|
|
file_md5: params[:md5_digest],
|
|
|
|
file_sha256: params[:sha256_digest]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|