diff options
Diffstat (limited to 'app/services/packages')
3 files changed, 29 insertions, 16 deletions
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 50a008843ad..505f45a7b21 100644 --- a/app/services/packages/maven/find_or_create_package_service.rb +++ b/app/services/packages/maven/find_or_create_package_service.rb @@ -3,21 +3,33 @@ module Packages module Maven class FindOrCreatePackageService < BaseService MAVEN_METADATA_FILE = 'maven-metadata.xml'.freeze + SNAPSHOT_TERM = '-SNAPSHOT'.freeze def execute - package = ::Packages::Maven::PackageFinder - .new(params[:path], current_user, project: project).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. + # 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. When uploading such file, we create + # a package with a version set to `nil`. The xml file with a version + # is only created and uploaded for snapshot versions. + # + # Gradle has a different upload order: + # - my-company/my-app/1.0-SNAPSHOT/maven-metadata.xml + # - my-company/my-app/1.0-SNAPSHOT/my-app.jar + # - my-company/my-app/1.0-SNAPSHOT/my-app.pom + # - my-company/my-app/maven-metadata.xml + # + # The first upload has to create the proper package (the one with the version set). + if params[:file_name] == MAVEN_METADATA_FILE && !params[:path]&.ends_with?(SNAPSHOT_TERM) package_name, version = params[:path], nil else package_name, _, version = params[:path].rpartition('/') @@ -30,8 +42,9 @@ module Packages build: params[:build] } - package = ::Packages::Maven::CreatePackageService - .new(project, current_user, package_params).execute + package = + ::Packages::Maven::CreatePackageService.new(project, current_user, package_params) + .execute end package diff --git a/app/services/packages/nuget/metadata_extraction_service.rb b/app/services/packages/nuget/metadata_extraction_service.rb index 6fec398fab0..59125669f7d 100644 --- a/app/services/packages/nuget/metadata_extraction_service.rb +++ b/app/services/packages/nuget/metadata_extraction_service.rb @@ -42,7 +42,7 @@ module Packages def valid_package_file? package_file && package_file.package&.nuget? && - package_file.file.size.positive? + package_file.file.size > 0 # rubocop:disable Style/ZeroLengthPredicate end def extract_metadata(file) diff --git a/app/services/packages/nuget/search_service.rb b/app/services/packages/nuget/search_service.rb index f7e09e11819..b95aa30bec1 100644 --- a/app/services/packages/nuget/search_service.rb +++ b/app/services/packages/nuget/search_service.rb @@ -21,8 +21,8 @@ module Packages @search_term = search_term @options = DEFAULT_OPTIONS.merge(options) - raise ArgumentError, 'negative per_page' if per_page.negative? - raise ArgumentError, 'negative padding' if padding.negative? + raise ArgumentError, 'negative per_page' if per_page < 0 + raise ArgumentError, 'negative padding' if padding < 0 end def execute |