summaryrefslogtreecommitdiff
path: root/app/services/packages
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /app/services/packages
parent4b1de649d0168371549608993deac953eb692019 (diff)
downloadgitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/services/packages')
-rw-r--r--app/services/packages/composer/create_package_service.rb2
-rw-r--r--app/services/packages/conan/create_package_file_service.rb9
-rw-r--r--app/services/packages/create_event_service.rb10
-rw-r--r--app/services/packages/create_package_service.rb16
-rw-r--r--app/services/packages/generic/create_package_file_service.rb5
-rw-r--r--app/services/packages/generic/find_or_create_package_service.rb6
-rw-r--r--app/services/packages/maven/find_or_create_package_service.rb2
-rw-r--r--app/services/packages/npm/create_package_service.rb8
-rw-r--r--app/services/packages/pypi/create_package_service.rb3
9 files changed, 40 insertions, 21 deletions
diff --git a/app/services/packages/composer/create_package_service.rb b/app/services/packages/composer/create_package_service.rb
index 2d2f1568187..0f5429f667e 100644
--- a/app/services/packages/composer/create_package_service.rb
+++ b/app/services/packages/composer/create_package_service.rb
@@ -16,6 +16,8 @@ module Packages
composer_json: composer_json
})
end
+
+ created_package
end
private
diff --git a/app/services/packages/conan/create_package_file_service.rb b/app/services/packages/conan/create_package_file_service.rb
index 2db5c4e507b..1bde9606492 100644
--- a/app/services/packages/conan/create_package_file_service.rb
+++ b/app/services/packages/conan/create_package_file_service.rb
@@ -12,7 +12,7 @@ module Packages
end
def execute
- package.package_files.create!(
+ package_file = package.package_files.build(
file: file,
size: params['file.size'],
file_name: params[:file_name],
@@ -25,6 +25,13 @@ module Packages
conan_file_type: params[:conan_file_type]
}
)
+
+ if params[:build].present?
+ package_file.package_file_build_infos << package_file.package_file_build_infos.build(pipeline: params[:build].pipeline)
+ end
+
+ package_file.save!
+ package_file
end
end
end
diff --git a/app/services/packages/create_event_service.rb b/app/services/packages/create_event_service.rb
index c4492389da9..f0328ceb08a 100644
--- a/app/services/packages/create_event_service.rb
+++ b/app/services/packages/create_event_service.rb
@@ -4,7 +4,11 @@ module Packages
class CreateEventService < BaseService
def execute
if Feature.enabled?(:collect_package_events_redis) && redis_event_name
- ::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(current_user.id, redis_event_name)
+ if guest?
+ ::Gitlab::UsageDataCounters::GuestPackageEventCounter.count(redis_event_name)
+ else
+ ::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(current_user.id, redis_event_name)
+ end
end
if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write?
@@ -45,5 +49,9 @@ module Packages
:guest
end
end
+
+ def guest?
+ originator_type == :guest
+ end
end
end
diff --git a/app/services/packages/create_package_service.rb b/app/services/packages/create_package_service.rb
index e3b0ad218e2..fcf252cf971 100644
--- a/app/services/packages/create_package_service.rb
+++ b/app/services/packages/create_package_service.rb
@@ -8,9 +8,9 @@ module Packages
project
.packages
.with_package_type(package_type)
- .safe_find_or_create_by!(name: name, version: version) do |pkg|
- pkg.creator = package_creator
- yield pkg if block_given?
+ .safe_find_or_create_by!(name: name, version: version) do |package|
+ package.creator = package_creator
+ add_build_info(package)
end
end
@@ -18,7 +18,9 @@ module Packages
project
.packages
.with_package_type(package_type)
- .create!(package_attrs(attrs))
+ .create!(package_attrs(attrs)) do |package|
+ add_build_info(package)
+ end
end
private
@@ -34,5 +36,11 @@ module Packages
def package_creator
current_user if current_user.is_a?(User)
end
+
+ def add_build_info(package)
+ if params[:build].present?
+ package.build_infos.new(pipeline: params[:build].pipeline)
+ end
+ end
end
end
diff --git a/app/services/packages/generic/create_package_file_service.rb b/app/services/packages/generic/create_package_file_service.rb
index f25e8b0ae56..b14b1c193ec 100644
--- a/app/services/packages/generic/create_package_file_service.rb
+++ b/app/services/packages/generic/create_package_file_service.rb
@@ -18,9 +18,12 @@ module Packages
build: params[:build]
}
- ::Packages::Generic::FindOrCreatePackageService
+ package = ::Packages::Generic::FindOrCreatePackageService
.new(project, current_user, package_params)
.execute
+
+ package.build_infos.safe_find_or_create_by!(pipeline: params[:build].pipeline) if params[:build].present?
+ package
end
def create_package_file(package)
diff --git a/app/services/packages/generic/find_or_create_package_service.rb b/app/services/packages/generic/find_or_create_package_service.rb
index 97f774a836b..0a6099e4d35 100644
--- a/app/services/packages/generic/find_or_create_package_service.rb
+++ b/app/services/packages/generic/find_or_create_package_service.rb
@@ -4,11 +4,7 @@ module Packages
module Generic
class FindOrCreatePackageService < ::Packages::CreatePackageService
def execute
- find_or_create_package!(::Packages::Package.package_types['generic']) do |package|
- if params[:build].present?
- package.build_infos.new(pipeline: params[:build].pipeline)
- end
- end
+ find_or_create_package!(::Packages::Package.package_types['generic'])
end
end
end
diff --git a/app/services/packages/maven/find_or_create_package_service.rb b/app/services/packages/maven/find_or_create_package_service.rb
index a2a61ff8d93..f598b5e7cd4 100644
--- a/app/services/packages/maven/find_or_create_package_service.rb
+++ b/app/services/packages/maven/find_or_create_package_service.rb
@@ -46,7 +46,7 @@ module Packages
.execute
end
- package.build_infos.create!(pipeline: params[:build].pipeline) if params[:build].present?
+ package.build_infos.safe_find_or_create_by!(pipeline: params[:build].pipeline) if params[:build].present?
package
end
diff --git a/app/services/packages/npm/create_package_service.rb b/app/services/packages/npm/create_package_service.rb
index c4b75348bba..22396eb7687 100644
--- a/app/services/packages/npm/create_package_service.rb
+++ b/app/services/packages/npm/create_package_service.rb
@@ -17,10 +17,6 @@ module Packages
def create_npm_package!
package = create_package!(:npm, name: name, version: version)
- if build.present?
- package.build_infos.create!(pipeline: build.pipeline)
- end
-
::Packages::CreatePackageFileService.new(package, file_params).execute
::Packages::CreateDependencyService.new(package, package_dependencies).execute
::Packages::Npm::CreateTagService.new(package, dist_tag).execute
@@ -50,10 +46,6 @@ module Packages
params[:versions][version]
end
- def build
- params[:build]
- end
-
def dist_tag
params['dist-tags'].each_key.first
end
diff --git a/app/services/packages/pypi/create_package_service.rb b/app/services/packages/pypi/create_package_service.rb
index c49efca0fc5..cb8d9559dc9 100644
--- a/app/services/packages/pypi/create_package_service.rb
+++ b/app/services/packages/pypi/create_package_service.rb
@@ -19,6 +19,8 @@ module Packages
Packages::Pypi::Metadatum.upsert(meta.attributes)
::Packages::CreatePackageFileService.new(created_package, file_params).execute
+
+ created_package
end
end
@@ -32,6 +34,7 @@ module Packages
def file_params
{
+ build: params[:build],
file: params[:content],
file_name: params[:content].original_filename,
file_md5: params[:md5_digest],