Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API calls for removing testers and group in sync push command #242

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ struct TestFlightPushCommand: CommonParsableCommand {
help: "Path to read in the TestFlight configuration."
) var inputPath: String

@Flag(help: "Perform a dry run.")
var dryRun: Bool

func run() throws {
let service = try makeService()

Expand All @@ -28,11 +31,32 @@ struct TestFlightPushCommand: CommonParsableCommand {

let difference = TestFlightProgramDifference(local: local, remote: remote)

difference.changes.forEach { print($0.description) }

// TODO: Push the testflight program to the API
if dryRun {
difference.changes.forEach { print($0.description) }
} else {
try difference.changes.forEach {
try performChange(change: $0, with: service)
}
}
}

throw CommandError.unimplemented
func performChange(change: TestFlightProgramDifference.Change, with service: AppStoreConnectService) throws {
switch change {
case .removeBetaGroup(let betagroup):
guard let groupId = betagroup.id else { return }
try service.deleteBetaGroup(id: groupId)
print("βœ… \(change.description)")
case .removeBetaTesterFromApps(let tester, let apps):
guard let email = tester.email else { return }
try service.removeTesterFromApps(email: email, appIds: apps.map(\.id))
print("βœ… \(change.description)")
case .removeBetaTesterFromGroups(let tester, let groups):
guard let email = tester.email else { return }
try service.removeTesterFromGroups(email: email, groupNames: groups.compactMap(\.groupName))
print("βœ… \(change.description)")
default:
print("❌ \(change.description): this operation has not been implemented")
}
}

}
24 changes: 24 additions & 0 deletions Sources/AppStoreConnectCLI/Services/AppStoreConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,24 @@ class AppStoreConnectService {
try operation.execute(with: requestor).await()
}

func removeTesterFromApps(email: String, appIds: [String]) throws {
let testerId = try GetBetaTesterOperation(
options: .init(identifier: .email(email))
)
.execute(with: requestor)
.await()
.betaTester
.id

let operation = RemoveTesterOperation(
options: .init(
removeStrategy: .removeTesterFromApps(testerId: testerId, appIds: appIds)
)
)

try operation.execute(with: requestor).await()
}

func readBetaGroup(bundleId: String, groupName: String) throws -> Model.BetaGroup {
let app = try ReadAppOperation(options: .init(identifier: .bundleId(bundleId)))
.execute(with: requestor)
Expand Down Expand Up @@ -472,6 +490,12 @@ class AppStoreConnectService {
.await()
}

func deleteBetaGroup(id: String) throws {
try DeleteBetaGroupOperation(options: .init(betaGroupId: id))
.execute(with: requestor)
.await()
}

func listBetaGroups(
filterIdentifiers: [AppLookupIdentifier] = [],
names: [String] = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct RemoveTesterOperation: APIOperation {
enum RemoveStrategy {
case removeTestersFromGroup(testerIds: [String], groupId: String)
case removeTesterFromGroups(testerId: String, groupIds: [String])
case removeTesterFromApps(testerId: String, appIds: [String])
}

let removeStrategy: RemoveStrategy
Expand All @@ -23,6 +24,8 @@ struct RemoveTesterOperation: APIOperation {
return APIEndpoint.remove(betaTesterWithId: testerId, fromBetaGroupsWithIds: groupIds)
case .removeTestersFromGroup(let testerIds, let groupId):
return APIEndpoint.remove(betaTestersWithIds: testerIds, fromBetaGroupWithId: groupId)
case .removeTesterFromApps(let testerId, let appIds):
return APIEndpoint.remove(accessOfBetaTesterWithId: testerId, toAppsWithIds: appIds)
}
}

Expand Down