summaryrefslogtreecommitdiff
path: root/app/services/update_release_service.rb
blob: e2228ca026c717439f455bd8e8b2c4b54c5a633f (plain)
1
2
3
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
# frozen_string_literal: true

class UpdateReleaseService < BaseService
  # rubocop: disable CodeReuse/ActiveRecord
  def execute(tag_name, release_description)
    repository = project.repository
    existing_tag = repository.find_tag(tag_name)

    if existing_tag
      release = project.releases.find_by(tag: tag_name)

      if release
        release.update(description: release_description)

        success(release)
      else
        error('Release does not exist', 404)
      end
    else
      error('Tag does not exist', 404)
    end
  end
  # rubocop: enable CodeReuse/ActiveRecord

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