2015-11-21 17:08:45 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class CreateReleaseService < BaseService
|
|
|
|
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
|
2015-11-21 21:24:34 +00:00
|
|
|
release = project.releases.find_by(tag: tag_name)
|
2015-11-21 17:08:45 +00:00
|
|
|
|
2015-11-21 21:34:53 +00:00
|
|
|
if release
|
2015-11-21 21:24:34 +00:00
|
|
|
error('Release already exists', 409)
|
|
|
|
else
|
|
|
|
release = project.releases.new({ tag: tag_name, description: release_description })
|
|
|
|
release.save
|
|
|
|
|
|
|
|
success(release)
|
|
|
|
end
|
2015-11-21 17:08:45 +00:00
|
|
|
else
|
2015-11-21 21:24:34 +00:00
|
|
|
error('Tag does not exist', 404)
|
2015-11-21 17:08:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def success(release)
|
|
|
|
out = super()
|
|
|
|
out[:release] = release
|
|
|
|
out
|
|
|
|
end
|
|
|
|
end
|