Commit aae463a9 authored by David Fernandez's avatar David Fernandez

Merge branch 'debian_api_upload' into 'master'

Add Debian package upload to API

See merge request gitlab-org/gitlab!62028
parents 50022004 671d53f6
......@@ -37,6 +37,21 @@ module API
track_package_event('push_package', :debian)
file_params = {
file: params['file'],
file_name: params['file_name'],
file_sha1: params['file.sha1'],
file_md5: params['file.md5']
}
package = ::Packages::Debian::FindOrCreateIncomingService.new(authorized_user_project, current_user).execute
package_file = ::Packages::Debian::CreatePackageFileService.new(package, file_params).execute
if params['file_name'].end_with? '.changes'
::Packages::Debian::ProcessChangesWorker.perform_async(package_file.id, current_user.id) # rubocop:disable CodeReuse/Worker
end
created!
rescue ObjectStorage::RemoteStoreError => e
Gitlab::ErrorTracking.track_exception(e, extra: { file_name: params[:file_name], project_id: authorized_user_project.id })
......
......@@ -40,10 +40,21 @@ RSpec.describe API::DebianProjectPackages do
let(:method) { :put }
let(:url) { "/projects/#{container.id}/packages/debian/#{file_name}" }
it_behaves_like 'Debian repository write endpoint', 'upload request', :created
context 'with a deb' do
let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' }
it_behaves_like 'Debian repository write endpoint', 'upload request', :created
end
context 'with a changes file' do
let(:file_name) { 'sample_1.2.3~alpha2_amd64.changes' }
it_behaves_like 'Debian repository write endpoint', 'upload request', :created
end
end
describe 'PUT projects/:id/packages/debian/:file_name/authorize' do
let(:file_name) { 'libsample0_1.2.3~alpha2_amd64.deb' }
let(:method) { :put }
let(:url) { "/projects/#{container.id}/packages/debian/#{file_name}/authorize" }
......
......@@ -107,10 +107,19 @@ RSpec.shared_examples 'Debian repository upload request' do |status, body = nil|
if status == :created
it 'creates package files', :aggregate_failures do
pending "Debian package creation not implemented"
expect(::Packages::Debian::FindOrCreateIncomingService).to receive(:new).with(container, user).and_call_original
expect(::Packages::Debian::CreatePackageFileService).to receive(:new).with(be_a(Packages::Package), be_an(Hash)).and_call_original
if file_name.end_with? '.changes'
expect(::Packages::Debian::ProcessChangesWorker).to receive(:perform_async)
else
expect(::Packages::Debian::ProcessChangesWorker).not_to receive(:perform_async)
end
expect { subject }
.to change { container.packages.debian.count }.by(1)
.and change { container.packages.debian.where(name: 'incoming').count }.by(1)
.and change { container.package_files.count }.by(1)
expect(response).to have_gitlab_http_status(status)
expect(response.media_type).to eq('text/plain')
......
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