Class: Releases::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/releases/update_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::ReleaseProtectedTagAccessError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#description, #execute_hooks, #existing_tag, #inexistent_milestone_ids, #inexistent_milestone_titles, #initialize, #milestones, #name, #param_for_milestone_ids_provided?, #param_for_milestone_titles_provided?, #param_for_milestones_exists?, #param_for_milestones_provided?, #project_group_id, #ref, #release, #released_at, #repository, #tag_message, #tag_name

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 Releases::BaseService

Instance Method Details

#executeObject



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/releases/update_service.rb', line 5

def execute
  if error = validate
    return error
  end

  if param_for_milestones_provided?
    previous_milestones = release.milestones.map(&:id)
    params[:milestones] = milestones
  end

  # transaction needed as Rails applies `save!` to milestone_releases
  # when it does assign_attributes instead of actual saving
  # this leads to the validation error being raised
  # see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43385
  ApplicationRecord.transaction do
    if release.update(params)
      execute_hooks(release, 'update')
      success(tag: existing_tag, release: release, milestones_updated: milestones_updated?(previous_milestones))
    else
      error(release.errors.messages || '400 Bad request', 400)
    end
  rescue ActiveRecord::RecordInvalid => e
    error(e.message || '400 Bad request', 400)
  end
end