diff options
author | dixpac <dino.onex@gmail.com> | 2017-02-14 18:33:50 +0300 |
---|---|---|
committer | dixpac <dino.onex@gmail.com> | 2017-02-14 18:43:35 +0300 |
commit | 613856face7f2ea58c229682a3acbba3e64be01b (patch) | |
tree | 8e40292c26331480e998fa5155ac0ba6eecee347 /app/services | |
parent | f802ad370e625e7aa2f3023f73c24a8b6f009821 (diff) |
Move tag services to `Tags` namespace
CreateTagService and DeleteTagService where in root namespace, by
following service code organization I moved them in Tags::CreateService
and Tags::DestroyService
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/create_tag_service.rb | 30 | ||||
-rw-r--r-- | app/services/delete_tag_service.rb | 42 | ||||
-rw-r--r-- | app/services/tags/create_service.rb | 32 | ||||
-rw-r--r-- | app/services/tags/destroy_service.rb | 44 |
4 files changed, 76 insertions, 72 deletions
diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb deleted file mode 100644 index 6c75d1f04ff..00000000000 --- a/app/services/create_tag_service.rb +++ /dev/null @@ -1,30 +0,0 @@ -class CreateTagService < BaseService - def execute(tag_name, target, message, release_description = nil) - valid_tag = Gitlab::GitRefValidator.validate(tag_name) - return error('Tag name invalid') unless valid_tag - - repository = project.repository - message&.strip! - - new_tag = nil - - begin - new_tag = repository.add_tag(current_user, tag_name, target, message) - rescue Rugged::TagError - return error("Tag #{tag_name} already exists") - rescue GitHooksService::PreReceiveError => ex - return error(ex.message) - end - - if new_tag - if release_description - CreateReleaseService.new(@project, @current_user). - execute(tag_name, release_description) - end - - success.merge(tag: new_tag) - else - error("Target #{target} is invalid") - end - end -end diff --git a/app/services/delete_tag_service.rb b/app/services/delete_tag_service.rb deleted file mode 100644 index eb726cb04b1..00000000000 --- a/app/services/delete_tag_service.rb +++ /dev/null @@ -1,42 +0,0 @@ -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(current_user, tag_name) - release = project.releases.find_by(tag: tag_name) - release&.destroy - - 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) - super(message).merge(return_code: return_code) - end - - def success(message) - super().merge(message: message) - end - - def build_push_data(tag) - Gitlab::DataBuilder::Push.build( - project, - current_user, - tag.dereferenced_target.sha, - Gitlab::Git::BLANK_SHA, - "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", - []) - end -end diff --git a/app/services/tags/create_service.rb b/app/services/tags/create_service.rb new file mode 100644 index 00000000000..1756da9e519 --- /dev/null +++ b/app/services/tags/create_service.rb @@ -0,0 +1,32 @@ +module Tags + class CreateService < BaseService + def execute(tag_name, target, message, release_description = nil) + valid_tag = Gitlab::GitRefValidator.validate(tag_name) + return error('Tag name invalid') unless valid_tag + + repository = project.repository + message&.strip! + + new_tag = nil + + begin + new_tag = repository.add_tag(current_user, tag_name, target, message) + rescue Rugged::TagError + return error("Tag #{tag_name} already exists") + rescue GitHooksService::PreReceiveError => ex + return error(ex.message) + end + + if new_tag + if release_description + CreateReleaseService.new(@project, @current_user). + execute(tag_name, release_description) + end + + success.merge(tag: new_tag) + else + error("Target #{target} is invalid") + end + end + end +end diff --git a/app/services/tags/destroy_service.rb b/app/services/tags/destroy_service.rb new file mode 100644 index 00000000000..910b4f5e361 --- /dev/null +++ b/app/services/tags/destroy_service.rb @@ -0,0 +1,44 @@ +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) + release = project.releases.find_by(tag: tag_name) + release&.destroy + + 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) + super(message).merge(return_code: return_code) + end + + def success(message) + super().merge(message: message) + end + + def build_push_data(tag) + Gitlab::DataBuilder::Push.build( + project, + current_user, + tag.dereferenced_target.sha, + Gitlab::Git::BLANK_SHA, + "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", + []) + end + end +end |