Add delete method in Release API
Introduce DELETE endpoint in Release API
This commit is contained in:
parent
6a2decf545
commit
dc8a8c7d99
4 changed files with 98 additions and 0 deletions
41
app/services/delete_release_service.rb
Normal file
41
app/services/delete_release_service.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DeleteReleaseService < BaseService
|
||||
include Gitlab::Utils::StrongMemoize
|
||||
|
||||
def execute
|
||||
return error('Tag does not exist', 404) unless existing_tag
|
||||
return error('Release does not exist', 404) unless release
|
||||
return error('Access Denied', 403) unless allowed?
|
||||
|
||||
if release.destory
|
||||
success(release: release)
|
||||
else
|
||||
error(release.errors.messages || '400 Bad request', 400)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def allowed?
|
||||
Ability.allowed?(current_user, :admin_release, release)
|
||||
end
|
||||
|
||||
def release
|
||||
strong_memoize(:release) do
|
||||
project.releases.find_by_tag(@tag_name)
|
||||
end
|
||||
end
|
||||
|
||||
def existing_tag
|
||||
strong_memoize(:existing_tag) do
|
||||
repository.find_tag(@tag_name)
|
||||
end
|
||||
end
|
||||
|
||||
def repository
|
||||
strong_memoize(:repository) do
|
||||
project.repository
|
||||
end
|
||||
end
|
||||
end
|
|
@ -89,6 +89,27 @@ module API
|
|||
render_api_error!(result[:message], result[:http_status])
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Delete a release' do
|
||||
detail 'This feature was introduced in GitLab 11.7.'
|
||||
success Entities::Release
|
||||
end
|
||||
params do
|
||||
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
|
||||
end
|
||||
delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
|
||||
authorize_update_release!
|
||||
|
||||
attributes = declared(params)
|
||||
attributes.delete(:id)
|
||||
result = DeleteReleaseService.new(user_project, current_user, attributes).execute
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:release], with: Entities::Release
|
||||
else
|
||||
render_api_error!(result[:message], result[:http_status])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
35
spec/requests/api/releases_spec.rb
Normal file
35
spec/requests/api/releases_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe API::Releases do
|
||||
let(:user) { create(:user) }
|
||||
let(:guest) { create(:user).tap { |u| project.add_guest(u) } }
|
||||
let(:project) { create(:project, :repository, creator: user, path: 'my.project') }
|
||||
let(:tag_name) { project.repository.find_tag('v1.1.0').name }
|
||||
|
||||
let(:project_id) { project.id }
|
||||
let(:current_user) { nil }
|
||||
|
||||
before do
|
||||
project.add_maintainer(user)
|
||||
end
|
||||
|
||||
describe 'GET /projects/:id/releases' do
|
||||
# TODO:
|
||||
end
|
||||
|
||||
describe 'GET /projects/:id/releases/:tag_name' do
|
||||
# TODO:
|
||||
end
|
||||
|
||||
describe 'POST /projects/:id/releases' do
|
||||
# TODO:
|
||||
end
|
||||
|
||||
describe 'PUT /projects/:id/releases/:tag_name' do
|
||||
# TODO:
|
||||
end
|
||||
|
||||
describe 'DELETE /projects/:id/releases/:tag_name' do
|
||||
# TODO:
|
||||
end
|
||||
end
|
1
spec/services/delete_release_service_spec.rb
Normal file
1
spec/services/delete_release_service_spec.rb
Normal file
|
@ -0,0 +1 @@
|
|||
#TODO:
|
Loading…
Reference in a new issue