Skip to content

Commit

Permalink
[deliver] fetch live app info if no edit info is present, fixing scen…
Browse files Browse the repository at this point in the history
…ario of having both macOS and iOS apps present (#21472)

* Fetch live app info if no edit info is present

* Add comments to explain the fallback

* Check App Info localization only when new metadata contains App Info

* Fix lint issues

* Only fail upload when trying to update localised app info in no edit mode.

* Update tests

* Make rubocop happy

* Update deliver/lib/deliver/upload_metadata.rb

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>

* Update deliver/lib/deliver/upload_metadata.rb

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>

* Update deliver/lib/deliver/upload_metadata.rb

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>

* Update message severity

* Minimize api call to fetch app infos

* Add tests

* Fix simple typos.

* Refactor to more Ruby-like syntax

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>

* Update tests

* Update spelling for consistency

Co-authored-by: Olivier Halligon <olivier@halligon.net>

* Update spelling for consistency

Co-authored-by: Olivier Halligon <olivier@halligon.net>

* Address feedback

* Update user-facing message.

* Fix syntax of string quotes.

---------

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>
Co-authored-by: Olivier Halligon <olivier@halligon.net>
  • Loading branch information
3 people committed Sep 29, 2023
1 parent 4257191 commit c4ed1a4
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 17 deletions.
67 changes: 54 additions & 13 deletions deliver/lib/deliver/upload_metadata.rb
Expand Up @@ -89,7 +89,8 @@ 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_localizations = verify_available_info_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)

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

# Update 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)
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
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 @@ -437,6 +439,12 @@ 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 @@ -451,12 +459,45 @@ def retry_if_nil(message, tries: 5, wait_time: 10)
end
end

# Finding languages to enable
def verify_available_info_languages!(options, app, languages)
app_info = fetch_edit_app_info(app)
# 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)
unless app_info
UI.user_error!("Cannot update languages - could not find an editable 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")
return
end

Expand Down
95 changes: 91 additions & 4 deletions deliver/spec/upload_metadata_spec.rb
Expand Up @@ -162,6 +162,7 @@ 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 @@ -237,15 +238,18 @@ 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(app).to receive(:fetch_edit_app_info).and_return(app_info)
expect(uploader).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
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])
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
end

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

# Get number of verions (used for if whats_new should be sent)
# 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
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 @@ -412,6 +422,83 @@ 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 c4ed1a4

Please sign in to comment.