pilot/lib/pilot/tester_manager.rb in fastlane-2.65.0 vs pilot/lib/pilot/tester_manager.rb in fastlane-2.66.0
- old
+ new
@@ -7,30 +7,25 @@
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
+ groups_param = config[:groups]
+ UI.user_error!("You must provide 1 or more groups (with the `:groups` option)") unless groups_param
+
tester = find_app_tester(email: config[:email], app: app)
tester ||= create_tester(
email: config[:email],
first_name: config[:first_name],
last_name: config[:last_name],
app: app
)
begin
+ # Groups are now required
groups = Spaceship::TestFlight::Group.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
- # tester was added to the group(s) in the above add_tester_to_groups() call, now we need to let the user know which group(s)
- if config[:groups]
- group_names = groups.map(&:name).join(", ")
- UI.success("Successfully added tester to group(s): #{group_names} in app: #{app.name}")
- else
- UI.success("Successfully added tester to the default tester group in app: #{app.name}")
- end
- end
+ group_names = groups.map(&:name).join(", ")
+ UI.success("Successfully added tester to group(s): #{group_names} in app: #{app.name}")
rescue => ex
UI.error("Could not add #{tester.email} to app: #{app.name}")
raise ex
end
end
@@ -64,11 +59,11 @@
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)
+ if config[:groups].nil?
test_flight_testers = Spaceship::TestFlight::Tester.search(app_id: app.apple_id, text: tester.email, is_email_exact_match: true)
if test_flight_testers.length > 1
UI.user_error!("Could not remove #{tester.email} from app: #{app.name}, reason: too many matches: #{test_flight_testers}")
elsif test_flight_testers.length == 0
@@ -93,11 +88,11 @@
app_filter = (config[:apple_id] || config[:app_identifier])
if app_filter
list_testers_by_app(app_filter)
else
- list_testers_global
+ UI.user_error!("You must include an `app_identifier` to `list_testers`")
end
end
private
@@ -110,20 +105,19 @@
nil
end
def find_app_tester(email: nil, app: nil)
current_user = find_current_user
+ app_apple_id = app.nil? ? nil : app.apple_id
if current_user.admin?
- tester = Spaceship::Tunes::Tester::Internal.find(email)
- tester ||= Spaceship::Tunes::Tester::External.find(email)
+ tester = Spaceship::TestFlight::Tester.find(app_id: app_apple_id, email: email)
elsif current_user.app_manager?
- unless app
+ unless app_apple_id
UI.user_error!("Account #{current_user.email_address} is only an 'App Manager' and therefore you must also define what app this tester (#{email}) should be added to")
end
- tester = Spaceship::Tunes::Tester::Internal.find_by_app(app.apple_id, email)
- tester ||= Spaceship::Tunes::Tester::External.find_by_app(app.apple_id, email)
+ tester = Spaceship::TestFlight::Tester.find(app_id: app_apple_id, email: email)
else
UI.user_error!("Account #{current_user.email_address} doesn't have a role that is allowed to administer app testers, current roles: #{current_user.roles}")
tester = nil
end
@@ -145,83 +139,44 @@
return current_user
end
def create_tester(email: nil, first_name: nil, last_name: nil, app: nil)
current_user = find_current_user
- if current_user.admin?
- tester = Spaceship::Tunes::Tester::External.create!(email: email,
- first_name: first_name,
- last_name: last_name)
- UI.success("Successfully added tester: #{email} to your account")
- elsif current_user.app_manager?
-
+ if current_user.admin? || current_user.app_manager?
Spaceship::TestFlight::Tester.create_app_level_tester(app_id: app.apple_id,
- first_name: first_name,
- last_name: last_name,
+ first_name: first_name || '',
+ last_name: last_name || '',
email: email)
- tester = Spaceship::Tunes::Tester::External.find_by_app(app.apple_id, email)
+
UI.success("Successfully added tester: #{email} to app: #{app.name}")
+ return Spaceship::TestFlight::Tester.find(app_id: app.apple_id, email: email)
else
UI.user_error!("Current account doesn't have permission to create a tester")
end
-
- return tester
rescue => ex
UI.error("Could not create tester #{email}")
raise ex
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
-
- int_testers = Spaceship::Tunes::Tester::Internal.all_by_app(app.apple_id)
- ext_testers = Spaceship::Tunes::Tester::External.all_by_app(app.apple_id)
-
- list_by_app(int_testers, "Internal Testers")
- puts ""
- list_by_app(ext_testers, "External Testers")
+ testers = Spaceship::TestFlight::Tester.all(app_id: app.apple_id)
+ list_by_app(testers, "All Testers")
end
- def list_testers_global
- begin
- int_testers = Spaceship::Tunes::Tester::Internal.all
- ext_testers = Spaceship::Tunes::Tester::External.all
- rescue Spaceship::Client::InsufficientPermissions
- UI.user_error!("You don't have the permission to list the testers of your whole team. Please provide an app identifier to list all testers of a specific application.")
- end
-
- list_global(int_testers, "Internal Testers")
- puts ""
- list_global(ext_testers, "External Testers")
- end
-
- def list_global(all_testers, title)
- headers = ["First", "Last", "Email", "Groups", "Devices", "Latest Version", "Latest Install Date"]
- list(all_testers, "#{title} (#{all_testers.count})", headers) do |tester|
- [
- tester.first_name,
- tester.last_name,
- tester.email,
- tester.groups_list,
- tester.devices.count,
- tester.latest_build,
- tester.pretty_install_date
- ]
- end
- end
-
def list_by_app(all_testers, title)
headers = ["First", "Last", "Email", "Groups"]
list(all_testers, "#{title} (#{all_testers.count})", headers) do |tester|
+ tester_groups = tester.groups.nil? ? nil : tester.groups.join(";")
[
tester.first_name,
tester.last_name,
tester.email,
- tester.groups_list
+ tester_groups
# Testers returned by the query made in the context of an app do not contain
- # the devices, version, or install date information
+ # the version, or install date information
]
end
end
# Requires a block that accepts a tester and returns an array of tester column values
@@ -243,30 +198,15 @@
rows << ["First name", tester.first_name]
rows << ["Last name", tester.last_name]
rows << ["Email", tester.email]
if tester.groups.to_s.length > 0
- rows << ["Groups", tester.groups_list]
+ rows << ["Groups", tester.groups.join(";")]
end
if tester.latest_install_date
rows << ["Latest Version", tester.latest_build]
rows << ["Latest Install Date", tester.pretty_install_date]
- end
-
- if tester.devices.to_s.length == 0
- rows << ["Devices", "No devices"]
- else
- rows << ["#{tester.devices.count} Devices", ""]
- tester.devices.each do |device|
- current = "\u2022 #{device['model']}, iOS #{device['osVersion']}"
-
- if rows.last[1].length == 0
- rows.last[1] = current
- else
- rows << ["", current]
- end
- end
end
puts Terminal::Table.new(
title: tester.email.green,
rows: FastlaneCore::PrintTable.transform_output(rows)