2014-09-21 08:29:52 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateTagService < BaseService
|
|
|
|
def execute(tag_name, ref, message)
|
2014-07-27 17:56:33 +00:00
|
|
|
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
|
|
|
if valid_tag == false
|
|
|
|
return error('Tag name invalid')
|
|
|
|
end
|
|
|
|
|
2014-05-22 01:46:01 +00:00
|
|
|
repository = project.repository
|
2014-07-27 17:56:33 +00:00
|
|
|
existing_tag = repository.find_tag(tag_name)
|
|
|
|
if existing_tag
|
|
|
|
return error('Tag already exists')
|
|
|
|
end
|
|
|
|
|
2014-06-24 01:35:36 +00:00
|
|
|
if message
|
|
|
|
message.gsub!(/^\s+|\s+$/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
repository.add_tag(tag_name, ref, message)
|
2014-05-22 01:46:01 +00:00
|
|
|
new_tag = repository.find_tag(tag_name)
|
|
|
|
|
|
|
|
if new_tag
|
|
|
|
Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags')
|
2014-07-27 17:56:33 +00:00
|
|
|
return success(new_tag)
|
|
|
|
else
|
|
|
|
return error('Invalid reference name')
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|
2014-07-27 17:56:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def success(branch)
|
2014-09-21 08:29:52 +00:00
|
|
|
out = super()
|
|
|
|
out[:tag] = branch
|
|
|
|
out
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|
|
|
|
end
|