2015-03-13 13:56:53 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class DeleteTagService < BaseService
|
|
|
|
def execute(tag_name)
|
|
|
|
repository = project.repository
|
|
|
|
tag = repository.find_tag(tag_name)
|
|
|
|
|
|
|
|
unless tag
|
|
|
|
return error('No such tag', 404)
|
|
|
|
end
|
|
|
|
|
|
|
|
if repository.rm_tag(tag_name)
|
2015-11-09 14:30:50 +00:00
|
|
|
release = project.releases.find_by(tag: tag_name)
|
|
|
|
release.destroy if release
|
|
|
|
|
2015-03-13 13:56:53 +00:00
|
|
|
push_data = build_push_data(tag)
|
|
|
|
EventCreateService.new.push(project, current_user, push_data)
|
|
|
|
project.execute_hooks(push_data.dup, :tag_push_hooks)
|
|
|
|
project.execute_services(push_data.dup, :tag_push_hooks)
|
|
|
|
|
|
|
|
success('Tag was removed')
|
|
|
|
else
|
|
|
|
error('Failed to remove tag')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def error(message, return_code = 400)
|
2016-07-06 13:26:59 +00:00
|
|
|
super(message).merge(return_code: return_code)
|
2015-03-13 13:56:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def success(message)
|
2016-07-06 13:26:59 +00:00
|
|
|
super().merge(message: message)
|
2015-03-13 13:56:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def build_push_data(tag)
|
2016-08-04 15:44:27 +00:00
|
|
|
Gitlab::DataBuilder::PushDataBuilder
|
2016-07-27 15:26:29 +00:00
|
|
|
.build(project, current_user, tag.target.sha, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", [])
|
2015-03-13 13:56:53 +00:00
|
|
|
end
|
|
|
|
end
|