2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Releases
|
|
|
|
class BaseService
|
|
|
|
include BaseServiceUtility
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
ReleaseProtectedTagAccessError = Class.new(StandardError)
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
attr_accessor :project, :current_user, :params
|
|
|
|
|
|
|
|
def initialize(project, user = nil, params = {})
|
2021-04-29 21:17:54 +05:30
|
|
|
@project = project
|
|
|
|
@current_user = user
|
|
|
|
@params = params.dup
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def tag_name
|
|
|
|
params[:tag]
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
def tag_message
|
|
|
|
params[:tag_message]
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def existing_tag
|
|
|
|
strong_memoize(:existing_tag) do
|
|
|
|
repository.find_tag(tag_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def milestones
|
2023-04-23 21:23:45 +05:30
|
|
|
return [] unless param_for_milestones_exists?
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
strong_memoize(:milestones) do
|
|
|
|
MilestonesFinder.new(
|
|
|
|
project: project,
|
|
|
|
current_user: current_user,
|
|
|
|
project_ids: Array(project.id),
|
|
|
|
group_ids: Array(project_group_id),
|
|
|
|
state: 'all',
|
2023-04-23 21:23:45 +05:30
|
|
|
title: params[:milestones],
|
|
|
|
ids: params[:milestone_ids]
|
2021-01-03 14:25:43 +05:30
|
|
|
).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def inexistent_milestone_titles
|
2021-01-03 14:25:43 +05:30
|
|
|
return [] unless param_for_milestone_titles_provided?
|
|
|
|
|
|
|
|
existing_milestone_titles = milestones.map(&:title)
|
2023-04-23 21:23:45 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
Array(params[:milestones]) - existing_milestone_titles
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def inexistent_milestone_ids
|
|
|
|
return [] unless param_for_milestone_ids_provided?
|
|
|
|
|
|
|
|
existing_milestone_ids = milestones.map(&:id)
|
|
|
|
|
|
|
|
Array(params[:milestone_ids]) - existing_milestone_ids
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def param_for_milestone_titles_provided?
|
2021-02-22 17:27:13 +05:30
|
|
|
!!params[:milestones]
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def param_for_milestone_ids_provided?
|
|
|
|
!!params[:milestone_ids]
|
|
|
|
end
|
|
|
|
|
|
|
|
def param_for_milestones_provided?
|
|
|
|
param_for_milestone_titles_provided? || param_for_milestone_ids_provided?
|
|
|
|
end
|
|
|
|
|
|
|
|
def param_for_milestones_exists?
|
|
|
|
params[:milestones].present? || params[:milestone_ids].present?
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def execute_hooks(release, action = 'create')
|
|
|
|
release.execute_hooks(action)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
# overridden in EE
|
|
|
|
def project_group_id; end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Releases::BaseService.prepend_mod_with('Releases::BaseService')
|