2020-07-10 11:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Composer
|
2020-09-03 08:08:47 -04:00
|
|
|
class CreatePackageService < ::Packages::CreatePackageService
|
2020-07-10 11:09:07 -04:00
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def execute
|
|
|
|
# fetches json outside of transaction
|
|
|
|
composer_json
|
|
|
|
|
|
|
|
::Packages::Package.transaction do
|
2020-11-17 16:09:19 -05:00
|
|
|
::Packages::Composer::Metadatum.upsert({
|
2020-07-10 11:09:07 -04:00
|
|
|
package_id: created_package.id,
|
|
|
|
target_sha: target,
|
|
|
|
composer_json: composer_json
|
2020-11-17 16:09:19 -05:00
|
|
|
})
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
2020-12-03 19:09:55 -05:00
|
|
|
|
2021-03-11 04:09:36 -05:00
|
|
|
::Packages::Composer::CacheUpdateWorker.perform_async(created_package.project_id, created_package.name, nil)
|
|
|
|
|
2020-12-03 19:09:55 -05:00
|
|
|
created_package
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def created_package
|
2020-09-03 08:08:47 -04:00
|
|
|
find_or_create_package!(:composer, name: package_name, version: package_version)
|
2020-07-10 11:09:07 -04:00
|
|
|
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
|