Class: CreateReleaseService

Inherits:
BaseService show all
Defined in:
app/services/create_release_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, release_description) ⇒ Object


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

def execute(tag_name, release_description)

  repository = project.repository
  existing_tag = repository.find_tag(tag_name)

  # Only create a release if the tag exists
  if existing_tag
    release = project.releases.find_by(tag: tag_name)

    if release
      error('Release already exists', 409)
    else
      release = project.releases.new({ tag: tag_name, description: release_description })
      release.save

      success(release)
    end
  else
    error('Tag does not exist', 404)
  end
end

#success(release) ⇒ Object


26
27
28
29
30
# File 'app/services/create_release_service.rb', line 26

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