summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/environments/canary_ingress/update_service.rb4
-rw-r--r--app/services/merge_requests/refresh_service.rb10
-rw-r--r--app/services/packages/helm/process_file_service.rb97
-rw-r--r--app/services/projects/update_remote_mirror_service.rb8
-rw-r--r--app/services/users/update_service.rb1
5 files changed, 109 insertions, 11 deletions
diff --git a/app/services/environments/canary_ingress/update_service.rb b/app/services/environments/canary_ingress/update_service.rb
index 2b510280873..f9813e5e86d 100644
--- a/app/services/environments/canary_ingress/update_service.rb
+++ b/app/services/environments/canary_ingress/update_service.rb
@@ -34,10 +34,6 @@ module Environments
private
def validate(environment)
- unless Feature.enabled?(:canary_ingress_weight_control, environment.project, default_enabled: true)
- return error(_("Feature flag is not enabled on the environment's project."))
- end
-
unless can?(current_user, :update_environment, environment)
return error(_('You do not have permission to update the environment.'))
end
diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb
index 3a4e3ba38fd..f7a0f90b95f 100644
--- a/app/services/merge_requests/refresh_service.rb
+++ b/app/services/merge_requests/refresh_service.rb
@@ -294,14 +294,14 @@ module MergeRequests
@source_merge_requests ||= merge_requests_for(@push.branch_name)
end
- # rubocop: disable CodeReuse/ActiveRecord
def merge_requests_for_forks
@merge_requests_for_forks ||=
- MergeRequest.opened
- .where(source_branch: @push.branch_name, source_project: @project)
- .where.not(target_project: @project)
+ MergeRequest
+ .opened
+ .from_project(project)
+ .from_source_branches(@push.branch_name)
+ .from_fork
end
- # rubocop: enable CodeReuse/ActiveRecord
end
end
diff --git a/app/services/packages/helm/process_file_service.rb b/app/services/packages/helm/process_file_service.rb
new file mode 100644
index 00000000000..31b357c1616
--- /dev/null
+++ b/app/services/packages/helm/process_file_service.rb
@@ -0,0 +1,97 @@
+# frozen_string_literal: true
+
+module Packages
+ module Helm
+ class ProcessFileService
+ include Gitlab::Utils::StrongMemoize
+ include ExclusiveLeaseGuard
+
+ ExtractionError = Class.new(StandardError)
+ DEFAULT_LEASE_TIMEOUT = 1.hour.to_i
+
+ def initialize(channel, package_file)
+ @channel = channel
+ @package_file = package_file
+ end
+
+ def execute
+ raise ExtractionError, 'Helm chart was not processed - package_file is not set' unless package_file
+
+ try_obtain_lease do
+ temp_package.transaction do
+ rename_package_and_set_version
+ rename_package_file_and_set_metadata
+ cleanup_temp_package
+ end
+ end
+ end
+
+ private
+
+ attr_reader :channel, :package_file
+
+ def rename_package_and_set_version
+ package.update!(
+ name: metadata['name'],
+ version: metadata['version'],
+ status: :default
+ )
+ end
+
+ def rename_package_file_and_set_metadata
+ # Updating file_name updates the path where the file is stored.
+ # We must pass the file again so that CarrierWave can handle the update
+ package_file.update!(
+ file_name: file_name,
+ file: package_file.file,
+ package_id: package.id,
+ helm_file_metadatum_attributes: {
+ channel: channel,
+ metadata: metadata
+ }
+ )
+ end
+
+ def cleanup_temp_package
+ temp_package.destroy if package.id != temp_package.id
+ end
+
+ def temp_package
+ strong_memoize(:temp_package) do
+ package_file.package
+ end
+ end
+
+ def package
+ strong_memoize(:package) do
+ project_packages = package_file.package.project.packages
+ package = project_packages.with_package_type(:helm)
+ .with_name(metadata['name'])
+ .with_version(metadata['version'])
+ .last
+ package || temp_package
+ end
+ end
+
+ def metadata
+ strong_memoize(:metadata) do
+ ::Packages::Helm::ExtractFileMetadataService.new(package_file).execute
+ end
+ end
+
+ def file_name
+ "#{metadata['name']}-#{metadata['version']}.tgz"
+ end
+
+ # used by ExclusiveLeaseGuard
+ def lease_key
+ "packages:helm:process_file_service:package_file:#{package_file.id}"
+ end
+
+ # used by ExclusiveLeaseGuard
+ def lease_timeout
+ DEFAULT_LEASE_TIMEOUT
+ end
+ end
+ end
+end
diff --git a/app/services/projects/update_remote_mirror_service.rb b/app/services/projects/update_remote_mirror_service.rb
index 9f4f6133d92..eac84337967 100644
--- a/app/services/projects/update_remote_mirror_service.rb
+++ b/app/services/projects/update_remote_mirror_service.rb
@@ -39,12 +39,16 @@ module Projects
def update_mirror(remote_mirror)
remote_mirror.update_start!
- remote_mirror.ensure_remote!
# LFS objects must be sent first, or the push has dangling pointers
send_lfs_objects!(remote_mirror)
- response = remote_mirror.update_repository
+ response = if Feature.enabled?(:update_remote_mirror_inmemory, project, default_enabled: :yaml)
+ remote_mirror.update_repository(inmemory_remote: true)
+ else
+ remote_mirror.ensure_remote!
+ remote_mirror.update_repository(inmemory_remote: false)
+ end
if response.divergent_refs.any?
message = "Some refs have diverged and have not been updated on the remote:"
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index ff08c806319..23c67231a29 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -17,6 +17,7 @@ module Users
yield(@user) if block_given?
user_exists = @user.persisted?
+ @user.user_detail # prevent assignment
discard_read_only_attributes
assign_attributes