debian-mirror-gitlab/app/services/packages/composer/create_package_service.rb
2021-04-17 20:07:23 +05:30

58 lines
1.3 KiB
Ruby

# frozen_string_literal: true
module Packages
module Composer
class CreatePackageService < ::Packages::CreatePackageService
include ::Gitlab::Utils::StrongMemoize
def execute
# fetches json outside of transaction
composer_json
::Packages::Package.transaction do
::Packages::Composer::Metadatum.upsert({
package_id: created_package.id,
target_sha: target,
composer_json: composer_json
})
end
::Packages::Composer::CacheUpdateWorker.perform_async(created_package.project_id, created_package.name, nil)
created_package
end
private
def created_package
find_or_create_package!(:composer, name: package_name, version: package_version)
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