Class: CreateTagService

Inherits:
BaseService show all
Defined in:
app/services/create_tag_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(tag_name, target, message, release_description = nil) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/create_tag_service.rb', line 4

def execute(tag_name, target, message, release_description = nil)
  valid_tag = Gitlab::GitRefValidator.validate(tag_name)
  return error('Tag name invalid') unless valid_tag

  repository = project.repository
  message.strip! if message

  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

  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")
  end
end