diff --git a/lib/spaceship/tunes/build.rb b/lib/spaceship/tunes/build.rb index de552c9..42e23e4 100644 --- a/lib/spaceship/tunes/build.rb +++ b/lib/spaceship/tunes/build.rb @@ -149,13 +149,11 @@ def update_build_information!(whats_new: nil, # encryption: false # } def submit_for_beta_review!(metadata) - # First, enable beta testing for this train (per iTC requirement) - self.build_train.update_testing_status!(true, 'external') - parameters = { app_id: self.build_train.application.apple_id, train: self.build_train.version_string, build_number: self.build_version, + platform: self.platform, # Required Metadata: changelog: "No changelog provided", @@ -177,6 +175,9 @@ def submit_for_beta_review!(metadata) client.submit_testflight_build_for_review!(parameters) + # Last, enable beta testing for this train (per iTC requirement). This will fail until the app has been approved for beta testing + self.build_train.update_testing_status!(true, 'external', self) + return parameters end @@ -200,7 +201,8 @@ def testing_status def cancel_beta_review! client.remove_testflight_build_from_review!(app_id: self.build_train.application.apple_id, train: self.build_train.version_string, - build_number: self.build_version) + build_number: self.build_version, + platform: self.platform) end end end diff --git a/lib/spaceship/tunes/build_train.rb b/lib/spaceship/tunes/build_train.rb index 8eba1cc..c71cf48 100644 --- a/lib/spaceship/tunes/build_train.rb +++ b/lib/spaceship/tunes/build_train.rb @@ -87,18 +87,31 @@ def update_testing_status!(new_value, testing_type, build = nil) data = client.build_trains(self.application.apple_id, testing_type) build ||= latest_build if testing_type == 'external' - - data['trains'].each do |train| - train["#{testing_type}Testing"]['value'] = false - train["#{testing_type}Testing"]['value'] = new_value if train['versionString'] == version_string - - # find correct build - train['builds'].select! { |b| !b["#{testing_type}Testing"].nil? && !build.nil? && b['buildVersion'] == build.build_version } - - # also update the build if it was found - train['builds'].each do |b| - b["#{testing_type}Testing"]['value'] = false - b["#{testing_type}Testing"]['value'] = new_value if b['trainVersion'] == version_string + testing_key = "#{testing_type}Testing" + + # Delete the irrelevant trains and update the relevant one to enable testing + data['trains'].delete_if do |train| + if train['versionString'] != version_string + true + else + train[testing_key]['value'] = new_value + + # also update the builds + train['builds'].delete_if do |b| + return true if b[testing_key].nil? + + if build && b["buildVersion"] == build.build_version + b[testing_key]['value'] = new_value + false + elsif b[testing_key]['value'] == true + b[testing_key]['value'] = false + false + else + true + end + end + + false end end diff --git a/lib/spaceship/tunes/tunes_client.rb b/lib/spaceship/tunes/tunes_client.rb index c191d9e..0dd05e0 100644 --- a/lib/spaceship/tunes/tunes_client.rb +++ b/lib/spaceship/tunes/tunes_client.rb @@ -281,9 +281,9 @@ def create_application!(name: nil, primary_language: nil, version: nil, sku: nil handle_itc_response(data) end - def create_version!(app_id, version_number) + def create_version!(app_id, version_number, platform = 'ios') r = request(:post) do |req| - req.url "ra/apps/#{app_id}/platforms/ios/versions/create/" + req.url "ra/apps/#{app_id}/platforms/#{platform}/versions/create/" req.body = { version: { value: version_number.to_s @@ -526,9 +526,9 @@ def update_build_trains!(app_id, testing_type, data) handle_itc_response(r.body) end - def remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil) + def remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil, platform: 'ios') r = request(:post) do |req| - req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/reject" + req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/reject" req.body = {}.to_json req.headers['Content-Type'] = 'application/json' end @@ -567,7 +567,7 @@ def update_build_information!(app_id: nil, handle_itc_response(r.body) end - def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil, + def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil, platform: 'ios', # Required Metadata: changelog: nil, description: nil, @@ -585,29 +585,29 @@ def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: n review_password: nil, encryption: false) - build_info = get_build_info_for_review(app_id: app_id, train: train, build_number: build_number) + build_info = get_build_info_for_review(app_id: app_id, train: train, build_number: build_number, platform: platform) # Now fill in the values provided by the user # First the localised values: build_info['testInfo']['details'].each do |current| - current['whatsNew']['value'] = changelog - current['description']['value'] = description - current['feedbackEmail']['value'] = feedback_email - current['marketingUrl']['value'] = marketing_url - current['privacyPolicyUrl']['value'] = privacy_policy_url + current['whatsNew']['value'] = changelog if changelog + current['description']['value'] = description if description + current['feedbackEmail']['value'] = feedback_email if feedback_email + current['marketingUrl']['value'] = marketing_url if marketing_url + current['privacyPolicyUrl']['value'] = privacy_policy_url if privacy_policy_url current['pageLanguageValue'] = current['language'] # There is no valid reason why we need this, only iTC being iTC end build_info['significantChange'] ||= {} build_info['significantChange']['value'] = significant_change - build_info['testInfo']['reviewFirstName']['value'] = first_name - build_info['testInfo']['reviewLastName']['value'] = last_name - build_info['testInfo']['reviewPhone']['value'] = phone_number - build_info['testInfo']['reviewEmail']['value'] = review_email - build_info['testInfo']['reviewUserName']['value'] = review_user_name - build_info['testInfo']['reviewPassword']['value'] = review_password + build_info['testInfo']['reviewFirstName']['value'] = first_name if first_name + build_info['testInfo']['reviewLastName']['value'] = last_name if last_name + build_info['testInfo']['reviewPhone']['value'] = phone_number if phone_number + build_info['testInfo']['reviewEmail']['value'] = review_email if review_email + build_info['testInfo']['reviewUserName']['value'] = review_user_name if review_user_name + build_info['testInfo']['reviewPassword']['value'] = review_password if review_password r = request(:post) do |req| # same URL, but a POST request - req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/start" + req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/start" req.body = build_info.to_json req.headers['Content-Type'] = 'application/json' @@ -618,13 +618,14 @@ def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: n update_encryption_compliance(app_id: app_id, train: train, build_number: build_number, + platform: platform, encryption_info: encryption_info, encryption: encryption) end - def get_build_info_for_review(app_id: nil, train: nil, build_number: nil) + def get_build_info_for_review(app_id: nil, train: nil, build_number: nil, platform: 'ios') r = request(:get) do |req| - req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/start" + req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/start" req.headers['Content-Type'] = 'application/json' end handle_itc_response(r.body) @@ -632,16 +633,19 @@ def get_build_info_for_review(app_id: nil, train: nil, build_number: nil) r.body['data'] end - def update_encryption_compliance(app_id: nil, train: nil, build_number: nil, encryption_info: nil, encryption: nil) + def update_encryption_compliance(app_id: nil, train: nil, build_number: nil, platform: 'ios', encryption_info: nil, encryption: nil, is_exempt: true, proprietary: false, third_party: false) return unless encryption_info['exportComplianceRequired'] # only sometimes this is required encryption_info['usesEncryption']['value'] = encryption encryption_info['encryptionUpdated'] ||= {} encryption_info['encryptionUpdated']['value'] = encryption + encryption_info['isExempt']['value'] = is_exempt + encryption_info['containsProprietaryCryptography']['value'] = proprietary + encryption_info['containsThirdPartyCryptography']['value'] = third_party r = request(:post) do |req| - req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/complete" + req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/complete" req.body = encryption_info.to_json req.headers['Content-Type'] = 'application/json' end diff --git a/lib/spaceship/version.rb b/lib/spaceship/version.rb index ba24a15..d62ba38 100644 --- a/lib/spaceship/version.rb +++ b/lib/spaceship/version.rb @@ -1,3 +1,3 @@ module Spaceship - VERSION = "0.19.4" + VERSION = "0.20.0" end diff --git a/spec/tunes/build_spec.rb b/spec/tunes/build_spec.rb index fda79e6..c122d16 100644 --- a/spec/tunes/build_spec.rb +++ b/spec/tunes/build_spec.rb @@ -75,6 +75,7 @@ app_id: "898536088", train: "1.0", build_number: "10", + platform: "ios", changelog: "Custom Changelog", description: "No app description provided", feedback_email: "contact@company.com",