diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-05 18:09:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-05 18:09:19 +0300 |
commit | 27d47e40e196e46f0f027f0a2e3e4debe293ba39 (patch) | |
tree | 2c249cdbe04d87cdd7d5983d370eb1920aff9da3 /app | |
parent | 164ac94bbd2eadc02ab54322a6fe12ed48ae8041 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 8 | ||||
-rw-r--r-- | app/models/concerns/chronic_duration_attribute.rb | 9 | ||||
-rw-r--r-- | app/models/concerns/integrations/enable_ssl_verification.rb | 17 | ||||
-rw-r--r-- | app/models/concerns/integrations/reset_secret_fields.rb | 4 | ||||
-rw-r--r-- | app/models/container_expiration_policy.rb | 6 | ||||
-rw-r--r-- | app/models/integration.rb | 5 | ||||
-rw-r--r-- | app/models/integrations/asana.rb | 3 | ||||
-rw-r--r-- | app/services/bulk_imports/file_download_service.rb | 6 | ||||
-rw-r--r-- | app/services/packages/nuget/odata_package_entry_service.rb | 70 | ||||
-rw-r--r-- | app/services/projects/container_repository/cleanup_tags_base_service.rb | 4 | ||||
-rw-r--r-- | app/validators/duration_validator.rb | 2 |
11 files changed, 112 insertions, 22 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 107f3c5987a..2b954e399ae 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -414,7 +414,9 @@ module Ci end def options_scheduled_at - ChronicDuration.parse(options[:start_in])&.seconds&.from_now + ChronicDuration.parse( + options[:start_in], use_complete_matcher: Feature.enabled?(:update_chronic_duration) + )&.seconds&.from_now end def action? @@ -745,7 +747,9 @@ module Ci def artifacts_expire_in=(value) self.artifacts_expire_at = if value - ChronicDuration.parse(value)&.seconds&.from_now + ChronicDuration.parse( + value, use_complete_matcher: Feature.enabled?(:update_chronic_duration) + )&.seconds&.from_now end end diff --git a/app/models/concerns/chronic_duration_attribute.rb b/app/models/concerns/chronic_duration_attribute.rb index af4905115b1..944ad252cc6 100644 --- a/app/models/concerns/chronic_duration_attribute.rb +++ b/app/models/concerns/chronic_duration_attribute.rb @@ -17,7 +17,14 @@ module ChronicDurationAttribute chronic_duration_attributes[virtual_attribute] = value.presence || parameters[:default].presence.to_s begin - new_value = value.present? ? ChronicDuration.parse(value).to_i : parameters[:default].presence + new_value = if value.present? + ChronicDuration.parse( + value, use_complete_matcher: Feature.enabled?(:update_chronic_duration) + ).to_i + else + parameters[:default].presence + end + assign_attributes(source_attribute => new_value) rescue ChronicDuration::DurationParseError # ignore error as it will be caught by validation diff --git a/app/models/concerns/integrations/enable_ssl_verification.rb b/app/models/concerns/integrations/enable_ssl_verification.rb index 11dc8a76a2b..9735a9bf5f6 100644 --- a/app/models/concerns/integrations/enable_ssl_verification.rb +++ b/app/models/concerns/integrations/enable_ssl_verification.rb @@ -19,13 +19,16 @@ module Integrations url_index = fields.index { |field| field[:name].ends_with?('_url') } insert_index = url_index ? url_index + 1 : -1 - fields.insert(insert_index, { - type: 'checkbox', - name: 'enable_ssl_verification', - title: s_('Integrations|SSL verification'), - checkbox_label: s_('Integrations|Enable SSL verification'), - help: s_('Integrations|Clear if using a self-signed certificate.') - }) + fields.insert(insert_index, + Field.new( + name: 'enable_ssl_verification', + integration_class: self, + type: :checkbox, + title: s_('Integrations|SSL verification'), + checkbox_label: s_('Integrations|Enable SSL verification'), + help: s_('Integrations|Clear if using a self-signed certificate.') + ) + ) end end end diff --git a/app/models/concerns/integrations/reset_secret_fields.rb b/app/models/concerns/integrations/reset_secret_fields.rb index f79c4392f19..24d716fe5dd 100644 --- a/app/models/concerns/integrations/reset_secret_fields.rb +++ b/app/models/concerns/integrations/reset_secret_fields.rb @@ -12,9 +12,7 @@ module Integrations end def exposing_secrets_fields - # TODO: Once all integrations use `Integrations::Field` we can remove the `.try` here. - # See: https://gitlab.com/groups/gitlab-org/-/epics/7652 - fields.select { _1.try(:exposes_secrets) }.pluck(:name) + fields.select(&:exposes_secrets).pluck(:name) end private diff --git a/app/models/container_expiration_policy.rb b/app/models/container_expiration_policy.rb index aecb47f7a03..857b7eccf70 100644 --- a/app/models/container_expiration_policy.rb +++ b/app/models/container_expiration_policy.rb @@ -80,7 +80,11 @@ class ContainerExpirationPolicy < ApplicationRecord end def set_next_run_at - self.next_run_at = Time.zone.now + ChronicDuration.parse(cadence).seconds + cadence_seconds = ChronicDuration.parse( + cadence, use_complete_matcher: Feature.enabled?(:update_chronic_duration) + ).seconds + + self.next_run_at = Time.zone.now + cadence_seconds end def disable! diff --git a/app/models/integration.rb b/app/models/integration.rb index 71eb54bc37a..d4c76f743a3 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -469,11 +469,8 @@ class Integration < ApplicationRecord [] end - # TODO: Once all integrations use `Integrations::Field` we can - # use `#secret?` here. - # See: https://gitlab.com/groups/gitlab-org/-/epics/7652 def secret_fields - fields.select { |f| f[:type] == :password }.pluck(:name) + fields.select(&:secret?).pluck(:name) end # Expose a list of fields in the JSON endpoint. diff --git a/app/models/integrations/asana.rb b/app/models/integrations/asana.rb index 7436c08aa38..3c3c12463ec 100644 --- a/app/models/integrations/asana.rb +++ b/app/models/integrations/asana.rb @@ -12,8 +12,7 @@ module Integrations help: -> { s_('AsanaService|User Personal Access Token. User must have access to the task. All comments are attributed to this user.') }, non_empty_password_title: -> { s_('ProjectService|Enter new API key') }, non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current API key.') }, - # Example Personal Access Token from Asana docs - placeholder: '0/68a9e79b868c6789e79a124c30b0', + placeholder: '0/68a9e79b868c6789e79a124c30b0', # Example Personal Access Token from Asana docs required: true field :restrict_to_branch, diff --git a/app/services/bulk_imports/file_download_service.rb b/app/services/bulk_imports/file_download_service.rb index 48adb90fb4c..b7e84508e98 100644 --- a/app/services/bulk_imports/file_download_service.rb +++ b/app/services/bulk_imports/file_download_service.rb @@ -83,6 +83,8 @@ module BulkImports end def raise_error(message) + logger.warn(message: message, response_headers: response_headers, importer: 'gitlab_migration') + raise ServiceError, message end @@ -109,6 +111,10 @@ module BulkImports @filename.presence || remote_filename end + def logger + @logger ||= Gitlab::Import::Logger.build + end + def validate_url ::Gitlab::UrlBlocker.validate!( http_client.resource_url(relative_url), diff --git a/app/services/packages/nuget/odata_package_entry_service.rb b/app/services/packages/nuget/odata_package_entry_service.rb new file mode 100644 index 00000000000..0cdcc38de16 --- /dev/null +++ b/app/services/packages/nuget/odata_package_entry_service.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +module Packages + module Nuget + class OdataPackageEntryService + include API::Helpers::RelatedResourcesHelpers + + SEMVER_LATEST_VERSION_PLACEHOLDER = '0.0.0-latest-version' + LATEST_VERSION_FOR_V2_DOWNLOAD_ENDPOINT = 'latest' + + def initialize(project, params) + @project = project + @params = params + end + + def execute + ServiceResponse.success(payload: package_entry) + end + + private + + attr_reader :project, :params + + def package_entry + <<-XML.squish + <entry xmlns='http://www.w3.org/2005/Atom' xmlns:d='http://schemas.microsoft.com/ado/2007/08/dataservices' xmlns:georss='http://www.georss.org/georss' xmlns:gml='http://www.opengis.net/gml' xmlns:m='http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' xml:base="#{xml_base}"> + <id>#{id_url}</id> + <category term='V2FeedPackage' scheme='http://schemas.microsoft.com/ado/2007/08/dataservices/scheme'/> + <title type='text'>#{params[:package_name]}</title> + <content type='application/zip' src="#{download_url}"/> + <m:properties> + <d:Version>#{package_version}</d:Version> + </m:properties> + </entry> + XML + end + + def package_version + params[:package_version] || SEMVER_LATEST_VERSION_PLACEHOLDER + end + + def id_url + expose_url "#{api_v4_projects_packages_nuget_v2_path(id: project.id)}" \ + "/Packages(Id='#{params[:package_name]}',Version='#{package_version}')" + end + + # TODO: use path helper when download endpoint is merged + def download_url + expose_url "#{api_v4_projects_packages_nuget_v2_path(id: project.id)}" \ + "/download/#{params[:package_name]}/#{download_url_package_version}" + end + + def download_url_package_version + if latest_version? + LATEST_VERSION_FOR_V2_DOWNLOAD_ENDPOINT + else + params[:package_version] + end + end + + def latest_version? + params[:package_version].nil? || params[:package_version] == SEMVER_LATEST_VERSION_PLACEHOLDER + end + + def xml_base + expose_url api_v4_projects_packages_nuget_v2_path(id: project.id) + end + end + end +end diff --git a/app/services/projects/container_repository/cleanup_tags_base_service.rb b/app/services/projects/container_repository/cleanup_tags_base_service.rb index 45557d03502..185895698af 100644 --- a/app/services/projects/container_repository/cleanup_tags_base_service.rb +++ b/app/services/projects/container_repository/cleanup_tags_base_service.rb @@ -100,7 +100,9 @@ module Projects def older_than_in_seconds strong_memoize(:older_than_in_seconds) do - ChronicDuration.parse(older_than).seconds + ChronicDuration.parse( + older_than, use_complete_matcher: Feature.enabled?(:update_chronic_duration) + ).seconds end end end diff --git a/app/validators/duration_validator.rb b/app/validators/duration_validator.rb index defd28d7d3b..5d7eba09122 100644 --- a/app/validators/duration_validator.rb +++ b/app/validators/duration_validator.rb @@ -12,7 +12,7 @@ # class DurationValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - ChronicDuration.parse(value) + ChronicDuration.parse(value, use_complete_matcher: Feature.enabled?(:update_chronic_duration)) rescue ChronicDuration::DurationParseError if options[:message] record.errors.add(:base, options[:message]) |