diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-15 18:13:41 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-15 18:13:41 +0000 |
commit | 87f4767e604a556291c531f8889b654d824245aa (patch) | |
tree | 41ea0a4cd610404102fb82e58c1a25d8117c5147 /app/services | |
parent | 5a13470a7935c2a31acdb4e85193721eb453a8a9 (diff) | |
parent | 613856face7f2ea58c229682a3acbba3e64be01b (diff) | |
download | gitlab-ce-87f4767e604a556291c531f8889b654d824245aa.tar.gz |
Merge branch 'move_tags_service_to_namespace' into 'master'
Move tag services to `Tags` namespace
See merge request !9231
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 |