Class: Releases::CreateService

Inherits:
BaseService show all
Defined in:
app/services/releases/create_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
# File 'app/services/releases/create_service.rb', line 5

def execute
  return error(_('Access Denied'), 403) unless allowed?
  return error(_('You are not allowed to create this tag as it is protected.'), 403) unless can_create_tag?
  return error(_('Release already exists'), 409) if release
  return error(format(_("Milestone(s) not found: %{milestones}"), milestones: inexistent_milestone_titles.join(', ')), 400) if inexistent_milestone_titles.any? # rubocop:disable Layout/LineLength
  return error(format(_("Milestone id(s) not found: %{milestones}"), milestones: inexistent_milestone_ids.join(', ')), 400) if inexistent_milestone_ids.any? # rubocop:disable Layout/LineLength

  # should be found before the creation of new tag
  # because tag creation can spawn new pipeline
  # which won't have any data for evidence yet
  evidence_pipeline = Releases::EvidencePipelineFinder.new(project, params).execute

  tag = ensure_tag

  return tag unless tag.is_a?(Gitlab::Git::Tag)

  if project.catalog_resource
    response = Ci::Catalog::ValidateResourceService.new(project, ref).execute

    return error(response.message) if response.error?
  end

  create_release(tag, evidence_pipeline)
end