Skip to content

Commit

Permalink
Revert "[deliver] fetch live app info if no edit info is present, fix…
Browse files Browse the repository at this point in the history
…ing scenario of having both macOS and iOS apps present (fastlane#21472)"

This reverts commit c4ed1a4.
  • Loading branch information
github-actions (on behalf of ignacio-calderon) committed Oct 5, 2023
1 parent d3d5f14 commit 1843443
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 145 deletions.
67 changes: 13 additions & 54 deletions deliver/lib/deliver/upload_metadata.rb
Expand Up @@ -89,8 +89,7 @@ def upload(options)
enabled_languages = detect_languages(options)

app_store_version_localizations = verify_available_version_languages!(options, app, enabled_languages) unless options[:edit_live]
app_info = fetch_edit_app_info(app)
app_info_localizations = verify_available_info_languages!(options, app, app_info, enabled_languages) unless options[:edit_live] || !updating_localized_app_info?(options, app, app_info)
app_info_localizations = verify_available_info_languages!(options, app, enabled_languages) unless options[:edit_live]

if options[:edit_live]
# not all values are editable when using live_version
Expand Down Expand Up @@ -212,19 +211,18 @@ def upload(options)
store_version_worker.start

# Update app info localizations
if app_info_localizations
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
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
app_info_worker.batch_enqueue(app_info_localizations)
app_info_worker.start
end
app_info_worker.batch_enqueue(app_info_localizations)
app_info_worker.start

# Update categories
app_info = fetch_edit_app_info(app)
if app_info
category_id_map = {}

Expand Down Expand Up @@ -439,12 +437,6 @@ def fetch_edit_app_info(app, wait_time: 10)
end
end

def fetch_live_app_info(app, wait_time: 10)
retry_if_nil("Cannot find live app info", wait_time: wait_time) do
app.fetch_live_app_info
end
end

def retry_if_nil(message, tries: 5, wait_time: 10)
loop do
tries -= 1
Expand All @@ -459,45 +451,12 @@ def retry_if_nil(message, tries: 5, wait_time: 10)
end
end

# Checking if the metadata to update includes localised App Info
def updating_localized_app_info?(options, app, app_info)
app_info ||= fetch_live_app_info(app)
unless app_info
UI.important("Can't find edit or live App info. Skipping upload.")
return false
end
localizations = app_info.get_app_info_localizations

LOCALISED_APP_VALUES.keys.each do |key|
current = options[key]
next unless current

unless current.kind_of?(Hash)
UI.error("Error with provided '#{key}'. Must be a hash, the key being the language.")
next
end

current.each do |language, value|
strip_value = value.to_s.strip
next if strip_value.empty?

app_info_locale = localizations.find { |l| l.locale == language }
next if app_info_locale.nil?

current_value = app_info_locale.public_send(key.to_sym)

return true if current_value != strip_value
end
end

UI.message('No changes to localized App Info detected. Skipping upload.')
return false
end

# Finding languages to enable
def verify_available_info_languages!(options, app, app_info, languages)
def verify_available_info_languages!(options, app, languages)
app_info = fetch_edit_app_info(app)

unless app_info
UI.user_error!("Cannot update languages - could not find an editable 'App Info'. Verify that your app is in one of the editable states in App Store Connect")
UI.user_error!("Cannot update languages - could not find an editable info")
return
end

Expand Down
95 changes: 4 additions & 91 deletions deliver/spec/upload_metadata_spec.rb
Expand Up @@ -162,7 +162,6 @@ def create_metadata(path, text)
locale: 'en-US')
end
let(:app_info) { double('app_info') }
let(:live_app_info) { nil }
let(:app_info_localization_en) do
double('app_info_localization_en',
locale: 'en-US')
Expand Down Expand Up @@ -238,18 +237,15 @@ def create_metadata(path, text)
# Verify available languages
expect(app).to receive(:id).and_return(id)
expect(app).to receive(:get_edit_app_store_version).and_return(version)
expect(uploader).to receive(:fetch_edit_app_info).and_return(app_info)
expect(app).to receive(:fetch_edit_app_info).and_return(app_info)

# Get versions
expect(app).to receive(:get_edit_app_store_version).and_return(version)
expect(version).to receive(:get_app_store_version_localizations).and_return([version_localization_en])

# Get app infos
if app_info
expect(app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])
else
expect(live_app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])
end
expect(app).to receive(:fetch_edit_app_info).and_return(app_info)
expect(app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])
end

context "normal metadata" do
Expand All @@ -261,17 +257,11 @@ def create_metadata(path, text)
description: { "en-US" => "App description" }
}

# Get number of versions (used for if whats_new should be sent)
# Get number of verions (used for if whats_new should be sent)
expect(Spaceship::ConnectAPI).to receive(:get_app_store_versions).and_return(app_store_versions)

expect(version).to receive(:update).with(attributes: {})

# Get app info
expect(app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])

# Get app info localization English (Used to compare with data to upload)
expect(app_info_localization_en).to receive(:name).and_return('App Name')

# Update version localization
expect(version_localization_en).to receive(:update).with(attributes: {
"description" => options[:description]["en-US"]
Expand Down Expand Up @@ -422,83 +412,6 @@ def create_metadata(path, text)
uploader.upload(options)
end
end

context "with no editable app info" do
let(:live_app_info) { double('app_info') }
let(:app_info) { nil }
it 'no new app info provided by user' do
options = {
platform: "ios",
metadata_path: metadata_path,
}

# Get live app info
expect(app).to receive(:fetch_live_app_info).and_return(live_app_info)

# Get number of versions (used for if whats_new should be sent)
expect(Spaceship::ConnectAPI).to receive(:get_app_store_versions).and_return(app_store_versions)
expect(version).to receive(:update).with(attributes: {})

uploader.upload(options)
end

it 'same app info as live version' do
options = {
platform: "ios",
metadata_path: metadata_path,
name: { "en-US" => "App name" }
}

# Get live app info
expect(app).to receive(:fetch_live_app_info).and_return(live_app_info)

# Get number of versions (used for if whats_new should be sent)
expect(Spaceship::ConnectAPI).to receive(:get_app_store_versions).and_return(app_store_versions)

expect(version).to receive(:update).with(attributes: {})

# Get app info localization in English (used to compare with data to upload)
expect(app_info_localization_en).to receive(:name).and_return('App name')

uploader.upload(options)
end
end
end

context "fail when not allowed to update" do
let(:live_app_info) { double('app_info') }
let(:app_info) { nil }
it 'different app info than live version' do
options = {
platform: "ios",
metadata_path: metadata_path,
name: { "en-US" => "New app name" }
}

allow(Deliver).to receive(:cache).and_return({ app: app })

allow(uploader).to receive(:set_review_information)
allow(uploader).to receive(:set_review_attachment_file)
allow(uploader).to receive(:set_app_rating)

# Get app info
expect(uploader).to receive(:fetch_edit_app_info).and_return(app_info)
expect(app).to receive(:fetch_live_app_info).and_return(live_app_info)
expect(live_app_info).to receive(:get_app_info_localizations).and_return([app_info_localization_en])

# Get versions
expect(app).to receive(:get_edit_app_store_version).and_return(version)
expect(version).to receive(:get_app_store_version_localizations).and_return([version_localization_en])

# Get app info localization in English (used to compare with data to upload)
expect(app_info_localization_en).to receive(:name).and_return('App name')

# Fail because app info can't be updated
expect(FastlaneCore::UI).to receive(:user_error!).with("Cannot update languages - could not find an editable 'App Info'. Verify that your app is in one of the editable states in App Store Connect").and_call_original

# Get app info localization in English (used to compare with data to upload)
expect { uploader.upload(options) }.to raise_error(FastlaneCore::Interface::FastlaneError)
end
end
end

Expand Down

0 comments on commit 1843443

Please sign in to comment.