pilot/lib/pilot/tester_manager.rb in fastlane-2.29.0.beta.20170426010043 vs pilot/lib/pilot/tester_manager.rb in fastlane-2.29.0.beta.20170427010043
- old
+ new
@@ -5,43 +5,27 @@
module Pilot
class TesterManager < Manager
def add_tester(options)
start(options)
+ app = find_app(app_filter: config[:apple_id] || config[:app_identifier])
+ UI.user_error!("You must provide either a Apple ID for the app (with the `:apple_id` option) or app identifier (with the `:app_identifier` option)") unless app
+
+ tester = find_or_create_tester(email: config[:email], first_name: config[:first_name], last_name: config[:last_name])
+
begin
- tester = Spaceship::Tunes::Tester::External.find(config[:email])
- if tester
- UI.success("Existing tester #{tester.email}")
+ groups = add_tester_to_groups!(tester: tester, app: app, groups: config[:groups])
+ if tester.kind_of?(Spaceship::Tunes::Tester::Internal)
+ UI.success("Successfully added tester to app #{app.name}")
else
- # make sure the user isn't already an internal tester, because we don't support those
- internal_tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
- UI.user_error!("#{internal_tester.email} is an internal tester; pilot does not support internal testers") unless internal_tester.nil?
-
- tester = Spaceship::Tunes::Tester::External.create!(email: config[:email],
- first_name: config[:first_name],
- last_name: config[:last_name])
- UI.success("Successfully added tester: #{tester.email} to your account")
+ group_names = groups.map(&:name).join(", ")
+ UI.success("Successfully added tester to app #{app.name} in group(s) #{group_names}")
end
rescue => ex
- UI.error("Could not create tester #{config[:email]}")
+ UI.error("Could not add #{tester.email} to app: #{app.name}")
raise ex
end
-
- app_filter = (config[:apple_id] || config[:app_identifier])
- if app_filter
- begin
- app = Spaceship::Application.find(app_filter)
- UI.user_error!("Couldn't find app with '#{app_filter}'") unless app
-
- groups = add_tester_to_groups!(tester: tester, app: app, groups: config[:groups])
- group_names = groups.map(&:name).join(", ")
- UI.success("Successfully added tester to app #{app_filter} in group(s) #{group_names}")
- rescue => ex
- UI.error("Could not add #{tester.email} to app: #{app.name}")
- raise ex
- end
- end
end
def find_tester(options)
start(options)
@@ -56,42 +40,34 @@
def remove_tester(options)
start(options)
tester = Spaceship::Tunes::Tester::External.find(config[:email])
+ tester ||= Spaceship::Tunes::Tester::Internal.find(config[:email])
+ UI.user_error!("Tester not found: #{config[:email]}") if tester.nil?
- if tester
- app_filter = (config[:apple_id] || config[:app_identifier])
- if app_filter
- begin
- app = Spaceship::Application.find(app_filter)
- UI.user_error!("Couldn't find app with '#{app_filter}'") unless app
+ app = find_app(app_filter: config[:apple_id] || config[:app_identifier])
+ unless app
+ tester.delete!
+ UI.success("Successfully removed tester #{tester.email}")
+ end
- # If no groups are passed to options, remove the tester from the app-level,
- # otherwise remove the tester from the groups specified.
- if config[:groups].nil?
- test_flight_tester = Spaceship::TestFlight::Tester.find(app_id: app.apple_id, email: tester.email)
- test_flight_tester.remove_from_app!(app_id: app.apple_id)
- UI.success("Successfully removed tester, #{test_flight_tester.email}, from app: #{app_filter}")
- else
- groups = remove_tester_from_groups!(tester: tester, app: app, groups: config[:groups])
- group_names = groups.map(&:name).join(", ")
- UI.success("Successfully removed tester #{tester.email} from app #{app_filter} in group(s) #{group_names}")
- end
- rescue => ex
- UI.error("Could not remove #{tester.email} from app: #{ex}")
- raise ex
- end
+ begin
+ # If no groups are passed to options, remove the tester from the app-level,
+ # otherwise remove the tester from the groups specified.
+ if config[:groups].nil? && tester.kind_of?(Spaceship::Tunes::Tester::External)
+ test_flight_tester = Spaceship::TestFlight::Tester.find(app_id: app.apple_id, email: tester.email)
+ test_flight_tester.remove_from_app!(app_id: app.apple_id)
+ UI.success("Successfully removed tester, #{test_flight_tester.email}, from app: #{app.name}")
else
- tester.delete!
- UI.success("Successfully removed tester #{tester.email}")
+ groups = remove_tester_from_groups!(tester: tester, app: app, groups: config[:groups])
+ group_names = groups.map(&:name).join(", ")
+ UI.success("Successfully removed tester #{tester.email} from app #{app.name} in group(s) #{group_names}")
end
- else
- internal_tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
- UI.user_error!("#{internal_tester.email} is an internal tester; pilot does not support internal testers") unless internal_tester.nil?
-
- UI.user_error!("Tester not found: #{config[:email]}")
+ rescue => ex
+ UI.error("Could not remove #{tester.email} from app: #{ex}")
+ raise ex
end
end
def list_testers(options)
start(options)
@@ -104,10 +80,37 @@
end
end
private
+ def find_app(app_filter: nil)
+ if app_filter
+ app = Spaceship::Application.find(app_filter)
+ UI.user_error!("Could not find an app by #{app_filter}") unless app
+ return app
+ end
+ nil
+ end
+
+ def find_or_create_tester(email: nil, first_name: nil, last_name: nil)
+ tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
+ tester ||= Spaceship::Tunes::Tester::External.find(config[:email])
+
+ if tester
+ UI.success("Existing tester #{tester.email}")
+ else
+ tester = Spaceship::Tunes::Tester::External.create!(email: config[:email],
+ first_name: config[:first_name],
+ last_name: config[:last_name])
+ UI.success("Successfully added tester: #{tester.email} to your account")
+ end
+ return tester
+ rescue => ex
+ UI.error("Could not create tester #{config[:email]}")
+ raise ex
+ end
+
def perform_for_groups_in_app(app: nil, groups: nil, &block)
if groups.nil?
default_external_group = app.default_external_group
if default_external_group.nil?
UI.user_error!("The app #{app.name} does not have a default external group. Please make sure to pass group names to the `:groups` option.")
@@ -123,14 +126,22 @@
test_flight_groups.each(&block)
end
def add_tester_to_groups!(tester: nil, app: nil, groups: nil)
- perform_for_groups_in_app(app: app, groups: groups) { |group| group.add_tester!(tester) }
+ if tester.kind_of?(Spaceship::Tunes::Tester::Internal)
+ Spaceship::TestFlight::Group.internal_group(app_id: app.apple_id).add_tester!(tester)
+ else
+ perform_for_groups_in_app(app: app, groups: groups) { |group| group.add_tester!(tester) }
+ end
end
def remove_tester_from_groups!(tester: nil, app: nil, groups: nil)
- perform_for_groups_in_app(app: app, groups: groups) { |group| group.remove_tester!(tester) }
+ if tester.kind_of?(Spaceship::Tunes::Tester::Internal)
+ Spaceship::TestFlight::Group.internal_group(app_id: app.apple_id).remove_tester!(tester)
+ else
+ perform_for_groups_in_app(app: app, groups: groups) { |group| group.remove_tester!(tester) }
+ end
end
def list_testers_by_app(app_filter)
app = Spaceship::Application.find(app_filter)
UI.user_error!("Couldn't find app with '#{app_filter}'") unless app