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: 46e06c9f584a186c426ce07c52ee9e924b484f13 (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
# frozen_string_literal: true

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

      def execute
        package = project.packages
                         .debian
                         .with_name(params[:name])
                         .with_version(params[:version])
                         .with_debian_codename(params[:distribution_name])
                         .first

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

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

      private

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