diff options
Diffstat (limited to 'app/services/packages/create_package_service.rb')
-rw-r--r-- | app/services/packages/create_package_service.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/services/packages/create_package_service.rb b/app/services/packages/create_package_service.rb new file mode 100644 index 00000000000..05b0b8e9fa6 --- /dev/null +++ b/app/services/packages/create_package_service.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Packages + class CreatePackageService < BaseService + protected + + def find_or_create_package!(package_type, name: params[:name], version: params[:version]) + project + .packages + .with_package_type(package_type) + .safe_find_or_create_by!(name: name, version: version) + end + + def create_package!(package_type, attrs = {}) + project + .packages + .with_package_type(package_type) + .create!(package_attrs(attrs)) + end + + private + + def package_attrs(attrs) + { + name: params[:name], + version: params[:version] + }.merge(attrs) + end + end +end |