2018-07-18 16:03:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-14 15:33:50 +00:00
|
|
|
module Tags
|
|
|
|
class DestroyService < 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(current_user, tag_name)
|
2018-12-25 09:48:26 +00:00
|
|
|
##
|
|
|
|
# When a tag in a repository is destroyed,
|
|
|
|
# release assets will be destroyed too.
|
|
|
|
Releases::DestroyService
|
|
|
|
.new(project, current_user, tag: tag_name)
|
|
|
|
.execute
|
2017-02-14 15:33:50 +00:00
|
|
|
|
2020-07-14 12:09:14 +00:00
|
|
|
unlock_artifacts(tag_name)
|
|
|
|
|
2017-02-14 15:33:50 +00:00
|
|
|
success('Tag was removed')
|
|
|
|
else
|
|
|
|
error('Failed to remove tag')
|
|
|
|
end
|
2018-06-11 10:42:09 +00:00
|
|
|
rescue Gitlab::Git::PreReceiveError => ex
|
2017-03-13 17:12:32 +00:00
|
|
|
error(ex.message)
|
2017-02-14 15:33:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def error(message, return_code = 400)
|
|
|
|
super(message).merge(return_code: return_code)
|
|
|
|
end
|
|
|
|
|
|
|
|
def success(message)
|
|
|
|
super().merge(message: message)
|
|
|
|
end
|
2020-07-14 12:09:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def unlock_artifacts(tag_name)
|
|
|
|
Ci::RefDeleteUnlockArtifactsWorker.perform_async(project.id, current_user.id, "#{::Gitlab::Git::TAG_REF_PREFIX}#{tag_name}")
|
|
|
|
end
|
2017-02-14 15:33:50 +00:00
|
|
|
end
|
|
|
|
end
|