Commit dc8a8c7d authored by Shinya Maeda's avatar Shinya Maeda

Add delete method in Release API

Introduce DELETE endpoint in Release API
parent 6a2decf5
# 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 ...@@ -89,6 +89,27 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
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 end
end end
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
#TODO:
\ No newline at end of file
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