2020-10-06 15:08:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Releases
|
|
|
|
class BaseService
|
|
|
|
include BaseServiceUtility
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-07-05 09:07:37 +00:00
|
|
|
ReleaseProtectedTagAccessError = Class.new(StandardError)
|
|
|
|
|
2020-10-06 15:08:33 +00:00
|
|
|
attr_accessor :project, :current_user, :params
|
|
|
|
|
|
|
|
def initialize(project, user = nil, params = {})
|
2021-04-19 21:09:27 +00:00
|
|
|
@project = project
|
|
|
|
@current_user = user
|
|
|
|
@params = params.dup
|
2020-10-06 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_name
|
|
|
|
params[:tag]
|
|
|
|
end
|
|
|
|
|
2022-05-19 06:08:48 +00:00
|
|
|
def tag_message
|
|
|
|
params[:tag_message]
|
|
|
|
end
|
|
|
|
|
2020-10-06 15:08:33 +00:00
|
|
|
def ref
|
|
|
|
params[:ref]
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
params[:name] || tag_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
params[:description]
|
|
|
|
end
|
|
|
|
|
|
|
|
def released_at
|
|
|
|
params[:released_at]
|
|
|
|
end
|
|
|
|
|
|
|
|
def release
|
|
|
|
strong_memoize(:release) do
|
|
|
|
project.releases.find_by_tag(tag_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository
|
|
|
|
strong_memoize(:repository) do
|
|
|
|
project.repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-18 21:09:32 +00:00
|
|
|
def existing_tag
|
|
|
|
strong_memoize(:existing_tag) do
|
|
|
|
repository.find_tag(tag_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-06 15:08:33 +00:00
|
|
|
def milestones
|
|
|
|
return [] unless param_for_milestone_titles_provided?
|
|
|
|
|
|
|
|
strong_memoize(:milestones) do
|
|
|
|
MilestonesFinder.new(
|
|
|
|
project: project,
|
|
|
|
current_user: current_user,
|
|
|
|
project_ids: Array(project.id),
|
2020-10-19 00:08:50 +00:00
|
|
|
group_ids: Array(project_group_id),
|
2020-10-06 15:08:33 +00:00
|
|
|
state: 'all',
|
|
|
|
title: params[:milestones]
|
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inexistent_milestones
|
|
|
|
return [] unless param_for_milestone_titles_provided?
|
|
|
|
|
|
|
|
existing_milestone_titles = milestones.map(&:title)
|
|
|
|
Array(params[:milestones]) - existing_milestone_titles
|
|
|
|
end
|
|
|
|
|
|
|
|
def param_for_milestone_titles_provided?
|
2020-11-18 09:09:02 +00:00
|
|
|
!!params[:milestones]
|
2020-10-06 15:08:33 +00:00
|
|
|
end
|
2020-10-19 00:08:50 +00:00
|
|
|
|
2020-11-07 00:08:58 +00:00
|
|
|
def execute_hooks(release, action = 'create')
|
|
|
|
release.execute_hooks(action)
|
|
|
|
end
|
|
|
|
|
2020-10-19 00:08:50 +00:00
|
|
|
# overridden in EE
|
|
|
|
def project_group_id; end
|
2020-10-06 15:08:33 +00:00
|
|
|
end
|
|
|
|
end
|
2020-10-19 00:08:50 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Releases::BaseService.prepend_mod_with('Releases::BaseService')
|