Welcome to mirror list, hosted at ThFree Co, Russian Federation.

find_or_create_package_service.rb « debian « packages « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9481504d2b60ec2225825f32ef600695632162b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Packages
  module Debian
    class FindOrCreatePackageService < ::Packages::CreatePackageService
      include Gitlab::Utils::StrongMemoize

      def execute
        packages = project.packages
                          .existing_debian_packages_with(name: params[:name], version: params[:version])

        package = packages.with_debian_codename_or_suite(params[:distribution_name]).first

        unless package
          package_in_other_distribution = packages.first

          if package_in_other_distribution
            raise ArgumentError, "Debian package #{params[:name]} #{params[:version]} exists " \
                                 "in distribution #{package_in_other_distribution.debian_distribution.codename}"
          end
        end

        package ||= create_package!(
          :debian,
          debian_publication_attributes: { distribution_id: distribution.id }
        )

        ServiceResponse.success(payload: { package: package })
      end

      private

      def distribution
        Packages::Debian::DistributionsFinder.new(
          project,
          codename_or_suite: params[:distribution_name]
        ).execute.last!
      end
      strong_memoize_attr :distribution
    end
  end
end