2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Composer
|
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
|
|
|
|
# fetches json outside of transaction
|
|
|
|
composer_json
|
|
|
|
|
|
|
|
::Packages::Package.transaction do
|
2021-01-29 00:20:46 +05:30
|
|
|
::Packages::Composer::Metadatum.upsert({
|
2020-07-28 23:09:34 +05:30
|
|
|
package_id: created_package.id,
|
|
|
|
target_sha: target,
|
|
|
|
composer_json: composer_json
|
2021-01-29 00:20:46 +05:30
|
|
|
})
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
::Packages::Composer::CacheUpdateWorker.perform_async(created_package.project_id, created_package.name, nil)
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
created_package
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def created_package
|
2020-11-24 15:15:51 +05:30
|
|
|
find_or_create_package!(:composer, name: package_name, version: package_version)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def composer_json
|
|
|
|
strong_memoize(:composer_json) do
|
|
|
|
::Packages::Composer::ComposerJsonService.new(project, target).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_name
|
|
|
|
composer_json['name']
|
|
|
|
end
|
|
|
|
|
|
|
|
def target
|
|
|
|
(branch || tag).target
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch
|
|
|
|
params[:branch]
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag
|
|
|
|
params[:tag]
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_version
|
|
|
|
::Packages::Composer::VersionParserService.new(tag_name: tag&.name, branch_name: branch&.name).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|