2015-04-26 12:48:37 +05:30
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateTagService < BaseService
|
2016-06-02 11:05:42 +05:30
|
|
|
def execute(tag_name, target, message, release_description = nil)
|
2015-04-26 12:48:37 +05:30
|
|
|
valid_tag = Gitlab::GitRefValidator.validate(tag_name)
|
2016-06-02 11:05:42 +05:30
|
|
|
return error('Tag name invalid') unless valid_tag
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
repository = project.repository
|
2015-04-26 12:48:37 +05:30
|
|
|
message.strip! if message
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
new_tag = nil
|
|
|
|
begin
|
|
|
|
new_tag = repository.add_tag(current_user, tag_name, target, message)
|
|
|
|
rescue Rugged::TagError
|
|
|
|
return error("Tag #{tag_name} already exists")
|
|
|
|
rescue GitHooksService::PreReceiveError
|
|
|
|
return error('Tag creation was rejected by Git hook')
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
if new_tag
|
2015-11-26 14:37:03 +05:30
|
|
|
if release_description
|
|
|
|
CreateReleaseService.new(@project, @current_user).
|
|
|
|
execute(tag_name, release_description)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
success.merge(tag: new_tag)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
2016-06-02 11:05:42 +05:30
|
|
|
error("Target #{target} is invalid")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|