deliver/lib/deliver/upload_metadata.rb in fastlane_hotfix-2.165.1 vs deliver/lib/deliver/upload_metadata.rb in fastlane_hotfix-2.187.0

- old
+ new

@@ -1,7 +1,9 @@ +require 'fastlane_core' +require 'spaceship' + require_relative 'module' -require_relative 'queue_worker' module Deliver # upload description, rating, etc. # rubocop:disable Metrics/ClassLength class UploadMetadata @@ -78,11 +80,11 @@ # Make sure to call `load_from_filesystem` before calling upload def upload(options) return if options[:skip_metadata] - app = options[:app] + app = Deliver.cache[:app] platform = Spaceship::ConnectAPI::Platform.map(options[:platform]) enabled_languages = detect_languages(options) @@ -93,11 +95,11 @@ # not all values are editable when using live_version version = app.get_live_app_store_version(platform: platform) localised_options = LOCALISED_LIVE_VALUES non_localised_options = NON_LOCALISED_LIVE_VALUES - if v.nil? + if version.nil? UI.message("Couldn't find live version, editing the current version on App Store Connect instead") version = fetch_edit_app_store_version(app, platform) # we don't want to update the localised_options and non_localised_options # as we also check for `options[:edit_live]` at other areas in the code # by not touching those 2 variables, deliver is more consistent with what the option says @@ -196,22 +198,22 @@ sleep(2) version.update(attributes: non_localized_version_attributes) sleep(1) # Update app store version localizations - store_version_worker = Deliver::QueueWorker.new do |app_store_version_localization| + store_version_worker = FastlaneCore::QueueWorker.new do |app_store_version_localization| attributes = localized_version_attributes_by_locale[app_store_version_localization.locale] if attributes UI.message("Uploading metadata to App Store Connect for localized version '#{app_store_version_localization.locale}'") app_store_version_localization.update(attributes: attributes) end end store_version_worker.batch_enqueue(app_store_version_localizations) store_version_worker.start # Update app info localizations - app_info_worker = Deliver::QueueWorker.new do |app_info_localization| + app_info_worker = FastlaneCore::QueueWorker.new do |app_info_localization| attributes = localized_info_attributes_by_locale[app_info_localization.locale] if attributes UI.message("Uploading metadata to App Store Connect for localized info '#{app_info_localization.locale}'") app_info_localization.update(attributes: attributes) end @@ -338,11 +340,11 @@ end end set_review_information(version, options) set_review_attachment_file(version, options) - set_app_rating(version, options) + set_app_rating(app_info, options) end # rubocop:enable Metrics/PerceivedComplexity def convert_ms_to_iso8601(time_in_ms) @@ -373,13 +375,11 @@ end # Check folder list (an empty folder signifies a language is required) ignore_validation = options[:ignore_language_directory_validation] Loader.language_folders(options[:metadata_path], ignore_validation).each do |lang_folder| - next unless File.directory?(lang_folder) # We don't want to read txt as they are non localised - language = File.basename(lang_folder) - enabled_languages << language unless enabled_languages.include?(language) + enabled_languages << lang_folder.basename unless enabled_languages.include?(lang_folder.basename) end return unless enabled_languages.include?("default") UI.message("Detected languages: " + enabled_languages.to_s) @@ -414,14 +414,11 @@ end # Check folder list (an empty folder signifies a language is required) ignore_validation = options[:ignore_language_directory_validation] Loader.language_folders(options[:metadata_path], ignore_validation).each do |lang_folder| - next unless File.directory?(lang_folder) # We don't want to read txt as they are non localised - - language = File.basename(lang_folder) - enabled_languages << language unless enabled_languages.include?(language) + enabled_languages << lang_folder.basename unless enabled_languages.include?(lang_folder.basename) end # Mapping to strings because :default symbol can be passed in enabled_languages .map(&:to_s) @@ -528,18 +525,17 @@ return if options[:skip_metadata] # Load localised data ignore_validation = options[:ignore_language_directory_validation] Loader.language_folders(options[:metadata_path], ignore_validation).each do |lang_folder| - language = File.basename(lang_folder) (LOCALISED_VERSION_VALUES.keys + LOCALISED_APP_VALUES.keys).each do |key| - path = File.join(lang_folder, "#{key}.txt") + path = File.join(lang_folder.path, "#{key}.txt") next unless File.exist?(path) UI.message("Loading '#{path}'...") options[key] ||= {} - options[key][language] ||= File.read(path) + options[key][lang_folder.basename] ||= File.read(path) end end # Load non localised data (NON_LOCALISED_VERSION_VALUES.keys + NON_LOCALISED_APP_VALUES.keys).each do |key| @@ -594,13 +590,14 @@ options end def set_review_information(version, options) - return unless options[:app_review_information] info = options[:app_review_information] - info = info.collect { |k, v| [k.to_sym, v] }.to_h + return if info.nil? || info.empty? + + info = info.transform_keys(&:to_sym) UI.user_error!("`app_review_information` must be a hash", show_github_issues: true) unless info.kind_of?(Hash) attributes = {} REVIEW_INFORMATION_VALUES.each do |key, attribute_name| strip_value = info[key].to_s.strip @@ -643,11 +640,11 @@ app_store_review_attachments.each(&:delete!) UI.message("Removing review attachment file to App Store Connect") unless app_store_review_attachments.empty? end end - def set_app_rating(version, options) + def set_app_rating(app_info, options) return unless options[:app_rating_config_path] require 'json' begin json = JSON.parse(File.read(options[:app_rating_config_path])) @@ -676,12 +673,26 @@ next if k.nil? || v.nil? next if k == v has_mapped_values = true UI.deprecated("Age rating '#{k}' from iTunesConnect has been deprecated. Please replace with '#{v}'") end - UI.deprecated("You can find more info at https://docs.fastlane.tools/actions/deliver/#reference") if has_mapped_values - age_rating_declaration = version.fetch_age_rating_declaration + # Handle App Store Connect deprecation/migrations of keys/values if possible + attributes, deprecation_messages, errors = Spaceship::ConnectAPI::AgeRatingDeclaration.map_deprecation_if_possible(attributes) + deprecation_messages.each do |message| + UI.deprecated(message) + end + + unless errors.empty? + errors.each do |error| + UI.error(error) + end + UI.user_error!("There are Age Rating deprecation errors that cannot be solved automatically... Please apply any fixes and try again") + end + + UI.deprecated("You can find more info at https://docs.fastlane.tools/actions/deliver/#reference") if has_mapped_values || !deprecation_messages.empty? + + age_rating_declaration = app_info.fetch_age_rating_declaration age_rating_declaration.update(attributes: attributes) end end # rubocop:enable Metrics/ClassLength end