-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathTestFlightPushCommand.swift
More file actions
62 lines (50 loc) · 2.05 KB
/
TestFlightPushCommand.swift
File metadata and controls
62 lines (50 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2020 Itty Bitty Apps Pty Ltd
import ArgumentParser
import Foundation
import FileSystem
import Model
struct TestFlightPushCommand: CommonParsableCommand {
static var configuration = CommandConfiguration(
commandName: "push",
abstract: "Push local TestFlight configuration to the remote API."
)
@OptionGroup()
var common: CommonOptions
@Option(
default: "./config/apps",
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()
let local = try FileSystem.readTestFlightConfiguration(from: inputPath)
let remote = try service.getTestFlightProgram()
let difference = TestFlightProgramDifference(local: local, remote: remote)
if dryRun {
difference.changes.forEach { print($0.description) }
} else {
try difference.changes.forEach {
try performChange(change: $0, with: service)
}
}
}
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")
}
}
}