2017-02-14 15:33:50 +00:00
|
|
|
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")
|
2017-08-22 12:18:09 +00:00
|
|
|
rescue Gitlab::Git::HooksService::PreReceiveError => ex
|
2017-02-14 15:33:50 +00:00
|
|
|
return error(ex.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
if new_tag
|
|
|
|
if release_description
|
2017-06-21 13:48:12 +00:00
|
|
|
CreateReleaseService.new(@project, @current_user)
|
|
|
|
.execute(tag_name, release_description)
|
2017-02-14 15:33:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
success.merge(tag: new_tag)
|
|
|
|
else
|
|
|
|
error("Target #{target} is invalid")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|