Class: Tags::DestroyService

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

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#error(message, return_code = 400) ⇒ Object



31
32
33
# File 'app/services/tags/destroy_service.rb', line 31

def error(message, return_code = 400)
  super(message).merge(return_code: return_code)
end

#execute(tag_name) ⇒ Object



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/tags/destroy_service.rb', line 5

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

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

  if repository.rm_tag(current_user, tag_name)
    ##
    # When a tag in a repository is destroyed,
    # release assets will be destroyed too.
    Releases::DestroyService
      .new(project, current_user, tag: tag_name)
      .execute

    unlock_artifacts(tag_name)

    success('Tag was removed')
  else
    error('Failed to remove tag')
  end
rescue Gitlab::Git::PreReceiveError => ex
  error(ex.message)
end

#success(message) ⇒ Object



35
36
37
# File 'app/services/tags/destroy_service.rb', line 35

def success(message)
  super().merge(message: message)
end