Skip to content

Instantly share code, notes, and snippets.

@rnystrom
Last active August 13, 2020 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnystrom/cf2b8e1b9f005860a5327825d4a43b34 to your computer and use it in GitHub Desktop.
Save rnystrom/cf2b8e1b9f005860a5327825d4a43b34 to your computer and use it in GitHub Desktop.
Purge inactive testflight users with fastlane

Purging inactive users from TestFlight

Pretty hacky flow, but this will remove anyone that was invited but not accepted their TestFlight invitation.

Start the Ruby REPL

$ irb

Setup your environment and select the your team

require "spaceship"
Spaceship::Tunes.login("felix@krausefx.com", "password")
Spaceship::Tunes.select_team

Set variables you'll need

app = Spaceship::ConnectAPI::App.find("COM.YOUR.APP.ID")

Then get all the users

testers = app.get_beta_testers(includes: "betaTesterMetrics,betaGroups", limit: 200)

Go to App Store Connect. Keep scrolling and loading builds at the bottom of the page until there are no more builds. This will show the last-unexpired build.

The last build should say something like "Expires in 4 days".

In irb, set the last-unexpired build.

last_build = 1

Filter testers that should be removed:

  • Users in the Beta group and last-status is over 2 weeks (avoid removing anyone just-invited)
  • Users on an expired build.
    • Note that to_i will be 0 for users that have not accepted an invitation. This will also then automatically remove people who have not accepted an invite in over 2 weeks.
> remove_testers = testers.select{ |t| \
  t.beta_groups.first.name == "YOUR_BETA_GROUP_NAME" \
  && ((Time.now - Time.parse(t.beta_tester_metrics.first.last_modified_date)) / 60.0 / 60.0 / 24.0) > 14 \
  && t.beta_tester_metrics.first.installed_cf_bundle_version.to_i < last_build \
}

To check how many users you will remove

remove_testers.length()

Then remove them from TestFlight

remove_testers.each{|t| t.delete_from_apps(apps: [app]) }

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment