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
|
2015-01-12 07:51:31 +00:00
|
|
|
if project.gitlab_ci?
|
|
|
|
push_data = create_push_data(project, current_user, new_tag)
|
|
|
|
project.gitlab_ci_service.async_execute(push_data)
|
|
|
|
end
|
|
|
|
|
2014-05-22 01:46:01 +00:00
|
|
|
Event.create_ref_event(project, current_user, new_tag, 'add', 'refs/tags')
|
2015-01-12 08:05:04 +00:00
|
|
|
success(new_tag)
|
2014-07-27 17:56:33 +00:00
|
|
|
else
|
2015-01-12 08:05:04 +00:00
|
|
|
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
|
2015-01-12 07:51:31 +00:00
|
|
|
|
|
|
|
def create_push_data(project, user, tag)
|
|
|
|
Gitlab::PushDataBuilder.
|
2015-01-12 08:05:04 +00:00
|
|
|
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, 'refs/tags/' + tag.name, [])
|
2015-01-12 07:51:31 +00:00
|
|
|
end
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|