diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-20 21:10:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-20 21:10:05 +0300 |
commit | cc4e1c884cd6b8782fb6a247d840a2d1c7f4603e (patch) | |
tree | 8a54c659b82873efafe04887708140785caea153 /app/services | |
parent | 709948b7a69597b1efe24df9b0f388cc0b493dd9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/ci/runners/register_runner_service.rb | 4 | ||||
-rw-r--r-- | app/services/packages/debian/process_package_file_service.rb | 116 |
2 files changed, 85 insertions, 35 deletions
diff --git a/app/services/ci/runners/register_runner_service.rb b/app/services/ci/runners/register_runner_service.rb index abd32610cec..db16b86d5e6 100644 --- a/app/services/ci/runners/register_runner_service.rb +++ b/app/services/ci/runners/register_runner_service.rb @@ -46,10 +46,10 @@ module Ci # Create shared runner. Requires admin access { runner_type: :instance_type } elsif runner_registrar_valid?('project') && project = ::Project.find_by_runners_token(registration_token) - # Create a specific runner for the project + # Create a project runner { runner_type: :project_type, scope: project } elsif runner_registrar_valid?('group') && group = ::Group.find_by_runners_token(registration_token) - # Create a specific runner for the group + # Create a group runner { runner_type: :group_type, scope: group } end end diff --git a/app/services/packages/debian/process_package_file_service.rb b/app/services/packages/debian/process_package_file_service.rb index 59e8ac3425b..2568085d303 100644 --- a/app/services/packages/debian/process_package_file_service.rb +++ b/app/services/packages/debian/process_package_file_service.rb @@ -10,19 +10,23 @@ module Packages # used by ExclusiveLeaseGuard DEFAULT_LEASE_TIMEOUT = 1.hour.to_i.freeze - def initialize(package_file, creator, distribution_name, component_name) + def initialize(package_file, distribution_name, component_name) @package_file = package_file - @creator = creator @distribution_name = distribution_name @component_name = component_name end def execute + return if @package_file.package.pending_destruction? + try_obtain_lease do validate! - @package_file.transaction do + package.transaction do + rename_package_and_set_version + update_package update_file_metadata + cleanup_temp_package end ::Packages::Debian::GenerateDistributionWorker.perform_async(:project, package.debian_distribution.id) @@ -40,6 +44,80 @@ module Packages raise ArgumentError, "invalid package file type: #{file_metadata[:file_type]}" end + def file_metadata + ::Packages::Debian::ExtractMetadataService.new(@package_file).execute + end + strong_memoize_attr :file_metadata + + def package + package = temp_package.project + .packages + .debian + .with_name(package_name) + .with_version(package_version) + .with_debian_codename(@distribution_name) + .not_pending_destruction + .last + package || temp_package + end + strong_memoize_attr :package + + def temp_package + @package_file.package + end + strong_memoize_attr :temp_package + + def package_name + package_name_and_version[0] + end + + def package_version + package_name_and_version[1] + end + + def package_name_and_version + package_name = file_metadata[:fields]['Package'] + package_version = file_metadata[:fields]['Version'] + + if file_metadata[:fields]['Source'] + # "sample" or "sample (1.2.3~alpha2)" + source_field_parts = file_metadata[:fields]['Source'].split(SOURCE_FIELD_SPLIT_REGEX) + package_name = source_field_parts[0] + package_version = source_field_parts[2] || package_version + end + + [package_name, package_version] + end + strong_memoize_attr :package_name_and_version + + def rename_package_and_set_version + package.update!( + name: package_name, + version: package_version, + status: :default + ) + end + + def update_package + return unless using_temporary_package? + + package.update!( + debian_publication_attributes: { distribution_id: distribution.id } + ) + end + + def using_temporary_package? + package.id == temp_package.id + end + + def distribution + Packages::Debian::DistributionsFinder.new( + @package_file.package.project, + codename: @distribution_name + ).execute.last! + end + strong_memoize_attr :distribution + def update_file_metadata ::Packages::UpdatePackageFileService.new(@package_file, package_id: package.id) .execute @@ -55,36 +133,8 @@ module Packages ) end - def package - strong_memoize(:package) do - package_name = file_metadata[:fields]['Package'] - package_version = file_metadata[:fields]['Version'] - - if file_metadata[:fields]['Source'] - # "sample" or "sample (1.2.3~alpha2)" - source_field_parts = file_metadata[:fields]['Source'].split(SOURCE_FIELD_SPLIT_REGEX) - package_name = source_field_parts[0] - package_version = source_field_parts[2] || package_version - end - - params = { - 'name': package_name, - 'version': package_version, - 'distribution_name': @distribution_name - } - response = Packages::Debian::FindOrCreatePackageService.new(project, @creator, params).execute - response.payload[:package] - end - end - - def file_metadata - strong_memoize(:metadata) do - ::Packages::Debian::ExtractMetadataService.new(@package_file).execute - end - end - - def project - @package_file.package.project + def cleanup_temp_package + temp_package.destroy unless using_temporary_package? end # used by ExclusiveLeaseGuard |