Commit 28e9e22e authored by David Fernandez's avatar David Fernandez Committed by Jan Provaznik

Update the maven sync worker

It will now treat the 'non existing versionless package' situation as a
normal one and will not raise a sync error.
parent febad03e
...@@ -13,16 +13,20 @@ module Packages ...@@ -13,16 +13,20 @@ module Packages
def execute def execute
return error('Blank package name') unless package_name return error('Blank package name') unless package_name
return error('Not allowed') unless Ability.allowed?(current_user, :destroy_package, project) return error('Not allowed') unless Ability.allowed?(current_user, :destroy_package, project)
return error('Non existing versionless package') unless versionless_package_for_versions
return error('Non existing metadata file for versions') unless metadata_package_file_for_versions
result = success('Non existing versionless package(s). Nothing to do.')
# update versionless package for plugins if it exists
if metadata_package_file_for_plugins if metadata_package_file_for_plugins
result = update_plugins_xml result = update_plugins_xml
return result if result.error? return result if result.error?
end end
update_versions_xml # update versionless_package for versions if it exists
return update_versions_xml if metadata_package_file_for_versions
result
end end
private private
...@@ -79,6 +83,9 @@ module Packages ...@@ -79,6 +83,9 @@ module Packages
def metadata_package_file_for_plugins def metadata_package_file_for_plugins
strong_memoize(:metadata_package_file_for_plugins) do strong_memoize(:metadata_package_file_for_plugins) do
pkg_name = package_name_for_plugins
next unless pkg_name
metadata_package_file_for(versionless_package_named(package_name_for_plugins)) metadata_package_file_for(versionless_package_named(package_name_for_plugins))
end end
end end
...@@ -106,6 +113,8 @@ module Packages ...@@ -106,6 +113,8 @@ module Packages
end end
def package_name_for_plugins def package_name_for_plugins
return unless versionless_package_for_versions
group = versionless_package_for_versions.maven_metadatum.app_group group = versionless_package_for_versions.maven_metadatum.app_group
group.tr('.', '/') group.tr('.', '/')
end end
......
---
title: Fix the Maven sync worker to not fail if the versionless package is not found
merge_request: 56514
author:
type: fixed
...@@ -131,7 +131,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do ...@@ -131,7 +131,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do
expect(::Packages::Maven::Metadata::CreateVersionsXmlService).not_to receive(:new) expect(::Packages::Maven::Metadata::CreateVersionsXmlService).not_to receive(:new)
end end
it_behaves_like 'returning an error service response', message: 'Non existing versionless package' it_behaves_like 'returning a success service response', message: 'Non existing versionless package(s). Nothing to do.'
end end
context 'without a metadata package file for versions' do context 'without a metadata package file for versions' do
...@@ -141,7 +141,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do ...@@ -141,7 +141,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do
expect(::Packages::Maven::Metadata::CreateVersionsXmlService).not_to receive(:new) expect(::Packages::Maven::Metadata::CreateVersionsXmlService).not_to receive(:new)
end end
it_behaves_like 'returning an error service response', message: 'Non existing metadata file for versions' it_behaves_like 'returning a success service response', message: 'Non existing versionless package(s). Nothing to do.'
end end
context 'without a project' do context 'without a project' do
...@@ -205,7 +205,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do ...@@ -205,7 +205,7 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do
it_behaves_like 'returning a success service response', message: 'Versionless package for versions destroyed' it_behaves_like 'returning a success service response', message: 'Versionless package for versions destroyed'
end end
context 'with a too big maven metadata file for versions' do context 'with a too big maven metadata file for plugins' do
before do before do
metadata_file_for_plugins.update!(size: 100.megabytes) metadata_file_for_plugins.update!(size: 100.megabytes)
end end
...@@ -244,6 +244,15 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do ...@@ -244,6 +244,15 @@ RSpec.describe ::Packages::Maven::Metadata::SyncService do
it_behaves_like 'returning a success service response', message: 'New metadata package files created' it_behaves_like 'returning a success service response', message: 'New metadata package files created'
end end
context 'without a versionless package for versions' do
before do
versionless_package_for_versions.package_files.update_all(file_name: 'test.txt')
expect(::Packages::Maven::Metadata::CreateVersionsXmlService).not_to receive(:new)
end
it_behaves_like 'returning a success service response', message: 'No changes for plugins xml'
end
context 'without a metadata package file for plugins' do context 'without a metadata package file for plugins' do
before do before do
versionless_package_for_plugins.package_files.update_all(file_name: 'test.txt') versionless_package_for_plugins.package_files.update_all(file_name: 'test.txt')
......
...@@ -61,9 +61,10 @@ RSpec.describe Packages::Maven::Metadata::SyncWorker, type: :worker do ...@@ -61,9 +61,10 @@ RSpec.describe Packages::Maven::Metadata::SyncWorker, type: :worker do
let(:project) { create(:project) } let(:project) { create(:project) }
it 'does not create the updated metadata files' do it 'does not create the updated metadata files' do
expect(worker).to receive(:log_extra_metadata_on_done).with(:message, 'Non existing versionless package(s). Nothing to do.')
expect { subject } expect { subject }
.to change { ::Packages::PackageFile.count }.by(0) .to change { ::Packages::PackageFile.count }.by(0)
.and raise_error(described_class::SyncError, 'Non existing versionless package')
end end
end end
...@@ -146,9 +147,10 @@ RSpec.describe Packages::Maven::Metadata::SyncWorker, type: :worker do ...@@ -146,9 +147,10 @@ RSpec.describe Packages::Maven::Metadata::SyncWorker, type: :worker do
let(:project) { create(:project) } let(:project) { create(:project) }
it 'does not create the updated metadata files' do it 'does not create the updated metadata files' do
expect(worker).to receive(:log_extra_metadata_on_done).with(:message, 'Non existing versionless package(s). Nothing to do.')
expect { subject } expect { subject }
.to change { ::Packages::PackageFile.count }.by(0) .to change { ::Packages::PackageFile.count }.by(0)
.and raise_error(described_class::SyncError, 'Non existing versionless package')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment