Class: DeleteTagService

Inherits:
BaseService show all
Defined in:
app/services/delete_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

#build_push_data(tag) ⇒ Object


40
41
42
43
# File 'app/services/delete_tag_service.rb', line 40

def build_push_data(tag)
  Gitlab::PushDataBuilder
    .build(project, current_user, tag.target, Gitlab::Git::BLANK_SHA, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", [])
end

#error(message, return_code = 400) ⇒ Object


28
29
30
31
32
# File 'app/services/delete_tag_service.rb', line 28

def error(message, return_code = 400)
  out = super(message)
  out[:return_code] = return_code
  out
end

#execute(tag_name) ⇒ Object


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

def execute(tag_name)
  repository = project.repository
  tag = repository.find_tag(tag_name)

  # No such tag
  unless tag
    return error('No such tag', 404)
  end

  if repository.rm_tag(tag_name)
    release = project.releases.find_by(tag: tag_name)
    release.destroy if release

    push_data = build_push_data(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('Tag was removed')
  else
    error('Failed to remove tag')
  end
end

#success(message) ⇒ Object


34
35
36
37
38
# File 'app/services/delete_tag_service.rb', line 34

def success(message)
  out = super()
  out[:message] = message
  out
end