2014-09-21 08:29:52 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateTagService < BaseService
|
2015-11-09 14:30:50 +00:00
|
|
|
def execute(tag_name, ref, message, release_description = nil)
|
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
|
|
|
|
|
2015-04-10 16:30:02 +00:00
|
|
|
message.strip! if message
|
2014-06-24 01:35:36 +00:00
|
|
|
|
|
|
|
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-11-09 14:30:50 +00:00
|
|
|
push_data = create_push_data(project, current_user, new_tag)
|
2015-03-13 13:55:17 +00:00
|
|
|
EventCreateService.new.push(project, current_user, push_data)
|
2015-02-24 13:31:08 +00:00
|
|
|
project.execute_hooks(push_data.dup, :tag_push_hooks)
|
|
|
|
project.execute_services(push_data.dup, :tag_push_hooks)
|
2016-01-11 11:34:58 +00:00
|
|
|
CreateCommitBuildsService.new.execute(project, current_user, push_data)
|
2015-02-24 13:31:08 +00:00
|
|
|
|
2015-11-21 17:08:45 +00:00
|
|
|
if release_description
|
|
|
|
CreateReleaseService.new(@project, @current_user).
|
|
|
|
execute(tag_name, release_description)
|
|
|
|
end
|
|
|
|
|
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)
|
2015-04-21 13:13:40 +00:00
|
|
|
commits = [project.commit(tag.target)].compact
|
2015-03-13 13:51:48 +00:00
|
|
|
Gitlab::PushDataBuilder.
|
2014-12-05 21:56:43 +00:00
|
|
|
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message)
|
2015-01-12 07:51:31 +00:00
|
|
|
end
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|