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

find_or_create_package_service.rb « maven « packages « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 50a008843ad3dffb1c5bbdf40022e7279f0201cc (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
# frozen_string_literal: true
module Packages
  module Maven
    class FindOrCreatePackageService < BaseService
      MAVEN_METADATA_FILE = 'maven-metadata.xml'.freeze

      def execute
        package = ::Packages::Maven::PackageFinder
          .new(params[:path], current_user, project: project).execute

        unless package
          if params[:file_name] == MAVEN_METADATA_FILE
            # Maven uploads several files during `mvn deploy` in next order:
            #   - my-company/my-app/1.0-SNAPSHOT/my-app.jar
            #   - my-company/my-app/1.0-SNAPSHOT/my-app.pom
            #   - my-company/my-app/1.0-SNAPSHOT/maven-metadata.xml
            #   - my-company/my-app/maven-metadata.xml
            #
            # The last xml file does not have VERSION in URL because it contains
            # information about all versions.
            package_name, version = params[:path], nil
          else
            package_name, _, version = params[:path].rpartition('/')
          end

          package_params = {
            name: package_name,
            path: params[:path],
            version: version,
            build: params[:build]
          }

          package = ::Packages::Maven::CreatePackageService
            .new(project, current_user, package_params).execute
        end

        package
      end
    end
  end
end