diff options
Diffstat (limited to 'lib/api/npm_project_packages.rb')
-rw-r--r-- | lib/api/npm_project_packages.rb | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/api/npm_project_packages.rb b/lib/api/npm_project_packages.rb index 07cbb3bf582..171a061bf97 100644 --- a/lib/api/npm_project_packages.rb +++ b/lib/api/npm_project_packages.rb @@ -44,8 +44,8 @@ module API present_package_file!(package_file) end - desc 'Create NPM package' do - detail 'This feature was introduced in GitLab 11.8' + desc 'Create or deprecate NPM package' do + detail 'Create was introduced in GitLab 11.8 & deprecate suppport was added in 16.0' success code: 200 failure [ { code: 400, message: 'Bad Request' }, @@ -61,16 +61,22 @@ module API end route_setting :authentication, job_token_allowed: true, deploy_token_allowed: true put ':package_name', requirements: ::API::Helpers::Packages::Npm::NPM_ENDPOINT_REQUIREMENTS do - authorize_create_package!(project) - - created_package = ::Packages::Npm::CreatePackageService - .new(project, current_user, params.merge(build: current_authenticated_job)).execute + if headers['Npm-Command'] == 'deprecate' + authorize_destroy_package!(project) - if created_package[:status] == :error - render_api_error!(created_package[:message], created_package[:http_status]) + ::Packages::Npm::DeprecatePackageService.new(project, declared(params)).execute(async: true) else - track_package_event('push_package', :npm, category: 'API::NpmPackages', project: project, namespace: project.namespace) - created_package + authorize_create_package!(project) + + created_package = ::Packages::Npm::CreatePackageService + .new(project, current_user, params.merge(build: current_authenticated_job)).execute + + if created_package[:status] == :error + render_api_error!(created_package[:message], created_package[:http_status]) + else + track_package_event('push_package', :npm, category: 'API::NpmPackages', project: project, namespace: project.namespace) + created_package + end end end |