diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-03-13 14:56:53 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-03-13 16:07:08 +0100 |
commit | 12b779e70b54692f4f00cb386440833bd1426a93 (patch) | |
tree | bd0c84265e53a936b52a91eb70f83434bc7ae18d /app | |
parent | 10421674afdc8a18cdab52288e736d06e3015096 (diff) | |
download | gitlab-ce-12b779e70b54692f4f00cb386440833bd1426a93.tar.gz |
Move tag deletion to service and execute hooks and services.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/tags_controller.rb | 11 | ||||
-rw-r--r-- | app/services/delete_tag_service.rb | 42 |
2 files changed, 47 insertions, 6 deletions
diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb index c4f27a6d989..83f4937bce3 100644 --- a/app/controllers/projects/tags_controller.rb +++ b/app/controllers/projects/tags_controller.rb @@ -24,14 +24,13 @@ class Projects::TagsController < Projects::ApplicationController end def destroy - tag = @repository.find_tag(params[:id]) - - if tag && @repository.rm_tag(tag.name) - EventCreateService.new.push_ref(@project, current_user, tag, 'rm', Gitlab::Git::TAG_REF_PREFIX) - end + DeleteTagService.new(project, current_user).execute(params[:id]) respond_to do |format| - format.html { redirect_to namespace_project_tags_path } + format.html do + redirect_to namespace_project_tags_path(@project.namespace, + @project) + end format.js end end diff --git a/app/services/delete_tag_service.rb b/app/services/delete_tag_service.rb new file mode 100644 index 00000000000..0c836401136 --- /dev/null +++ b/app/services/delete_tag_service.rb @@ -0,0 +1,42 @@ +require_relative 'base_service' + +class DeleteTagService < BaseService + def execute(tag_name) + repository = project.repository + tag = repository.find_tag(tag_name) + + # No such tag + unless tag + return error('No such tag', 404) + end + + if repository.rm_tag(tag_name) + 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) + out = super(message) + out[:return_code] = return_code + out + end + + def success(message) + out = super() + out[:message] = message + out + end + + def build_push_data(tag) + Gitlab::PushDataBuilder + .build(project, current_user, tag.target, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", []) + end +end |