2014-09-21 08:29:52 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateTagService < BaseService
|
2016-04-25 14:31:45 +00:00
|
|
|
def execute(tag_name, target, message, release_description = nil)
|
2014-07-27 17:56:33 +00:00
|
|
|
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
2016-04-25 14:31:45 +00:00
|
|
|
return error('Tag name invalid') unless valid_tag
|
2014-07-27 17:56:33 +00:00
|
|
|
|
2014-05-22 01:46:01 +00:00
|
|
|
repository = project.repository
|
2015-04-10 16:30:02 +00:00
|
|
|
message.strip! if message
|
2016-04-25 14:31:45 +00:00
|
|
|
|
|
|
|
new_tag = nil
|
2016-04-15 10:15:52 +00:00
|
|
|
begin
|
2016-04-25 14:31:45 +00:00
|
|
|
new_tag = repository.add_tag(current_user, tag_name, target, message)
|
2016-04-15 10:15:52 +00:00
|
|
|
rescue Rugged::TagError
|
|
|
|
return error("Tag #{tag_name} already exists")
|
2016-07-04 12:30:22 +00:00
|
|
|
rescue GitHooksService::PreReceiveError => ex
|
|
|
|
return error(ex.message)
|
2016-04-15 10:15:52 +00:00
|
|
|
end
|
2014-06-24 01:35:36 +00:00
|
|
|
|
2016-04-25 14:31:45 +00:00
|
|
|
if new_tag
|
|
|
|
if release_description
|
|
|
|
CreateReleaseService.new(@project, @current_user).
|
|
|
|
execute(tag_name, release_description)
|
|
|
|
end
|
|
|
|
success.merge(tag: new_tag)
|
|
|
|
else
|
|
|
|
error("Target #{target} is invalid")
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|
2015-01-12 07:51:31 +00:00
|
|
|
end
|
2014-05-22 01:46:01 +00:00
|
|
|
end
|