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?
|
2021-06-08 01:23:25 +05:30
|
|
|
raise ActiveRecord::RecordInvalid, meta
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
Packages::Pypi::Metadatum.upsert(meta.attributes)
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
::Packages::CreatePackageFileService.new(created_package, file_params).execute
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
created_package
|
2020-07-28 23:09:34 +05:30
|
|
|
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
|
|
|
|
{
|
2021-02-22 17:27:13 +05:30
|
|
|
build: params[:build],
|
2020-07-28 23:09:34 +05:30
|
|
|
file: params[:content],
|
|
|
|
file_name: params[:content].original_filename,
|
|
|
|
file_md5: params[:md5_digest],
|
|
|
|
file_sha256: params[:sha256_digest]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|