2015-04-26 12:48:37 +05:30
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateTagService < BaseService
|
|
|
|
def execute(tag_name, ref, message)
|
|
|
|
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
|
|
|
if valid_tag == false
|
|
|
|
return error('Tag name invalid')
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
repository = project.repository
|
2015-04-26 12:48:37 +05:30
|
|
|
existing_tag = repository.find_tag(tag_name)
|
|
|
|
if existing_tag
|
|
|
|
return error('Tag already exists')
|
|
|
|
end
|
|
|
|
|
|
|
|
message.strip! if message
|
|
|
|
|
|
|
|
repository.add_tag(tag_name, ref, message)
|
2014-09-02 18:07:02 +05:30
|
|
|
new_tag = repository.find_tag(tag_name)
|
|
|
|
|
|
|
|
if new_tag
|
2015-04-26 12:48:37 +05:30
|
|
|
push_data = create_push_data(project, current_user, new_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(new_tag)
|
|
|
|
else
|
|
|
|
error('Invalid reference name')
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def success(branch)
|
|
|
|
out = super()
|
|
|
|
out[:tag] = branch
|
|
|
|
out
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def create_push_data(project, user, tag)
|
|
|
|
commits = [project.repository.commit(tag.target)].compact
|
|
|
|
Gitlab::PushDataBuilder.
|
|
|
|
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|