|
| 1 | +import Foundation |
| 2 | + |
| 3 | +// MARK: - autopilot Repo DTO |
| 4 | + |
| 5 | +/// Repository payload returned by `GET /api/v1/repos` on autopilot |
| 6 | +/// (deployed at https://autopilot.rxlab.app). The macOS app no longer talks |
| 7 | +/// to api.github.com directly — autopilot fans out across the signed-in |
| 8 | +/// user's GitHub App installations and hands back a deduped list. |
| 9 | +public struct AutopilotRepo: Identifiable, Codable, Sendable, Hashable { |
| 10 | + public let id: Int |
| 11 | + public let fullName: String |
| 12 | + public let name: String |
| 13 | + public let owner: String |
| 14 | + public let isPrivate: Bool |
| 15 | + public let defaultBranch: String? |
| 16 | + public let htmlUrl: String |
| 17 | + public let cloneUrl: String |
| 18 | + public let sshUrl: String |
| 19 | + public let updatedAt: String? |
| 20 | + public let description: String? |
| 21 | + |
| 22 | + public init( |
| 23 | + id: Int, |
| 24 | + fullName: String, |
| 25 | + name: String, |
| 26 | + owner: String, |
| 27 | + isPrivate: Bool, |
| 28 | + defaultBranch: String?, |
| 29 | + htmlUrl: String, |
| 30 | + cloneUrl: String, |
| 31 | + sshUrl: String, |
| 32 | + updatedAt: String?, |
| 33 | + description: String? |
| 34 | + ) { |
| 35 | + self.id = id |
| 36 | + self.fullName = fullName |
| 37 | + self.name = name |
| 38 | + self.owner = owner |
| 39 | + self.isPrivate = isPrivate |
| 40 | + self.defaultBranch = defaultBranch |
| 41 | + self.htmlUrl = htmlUrl |
| 42 | + self.cloneUrl = cloneUrl |
| 43 | + self.sshUrl = sshUrl |
| 44 | + self.updatedAt = updatedAt |
| 45 | + self.description = description |
| 46 | + } |
| 47 | + |
| 48 | + private enum CodingKeys: String, CodingKey { |
| 49 | + case id |
| 50 | + case fullName |
| 51 | + case name |
| 52 | + case owner |
| 53 | + case isPrivate = "private" |
| 54 | + case defaultBranch |
| 55 | + case htmlUrl |
| 56 | + case cloneUrl |
| 57 | + case sshUrl |
| 58 | + case updatedAt |
| 59 | + case description |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +public struct AutopilotRepoListResponse: Codable, Sendable { |
| 64 | + public let items: [AutopilotRepo] |
| 65 | + public let pagination: Pagination? |
| 66 | + |
| 67 | + public struct Pagination: Codable, Sendable { |
| 68 | + public let nextCursor: String? |
| 69 | + public let hasMore: Bool |
| 70 | + |
| 71 | + public init(nextCursor: String?, hasMore: Bool) { |
| 72 | + self.nextCursor = nextCursor |
| 73 | + self.hasMore = hasMore |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + public init(items: [AutopilotRepo], pagination: Pagination?) { |
| 78 | + self.items = items |
| 79 | + self.pagination = pagination |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +// MARK: - GitHub App Installation DTOs |
| 84 | + |
| 85 | +/// A GitHub App installation owned by the signed-in user, as recorded by |
| 86 | +/// autopilot. The macOS app uses this to decide whether to surface the |
| 87 | +/// "Install GitHub App" CTA in the import-repo sheet. |
| 88 | +public struct AutopilotInstallation: Identifiable, Codable, Sendable, Hashable { |
| 89 | + public let id: String |
| 90 | + public let installationId: Int |
| 91 | + public let accountLogin: String |
| 92 | + public let accountType: String |
| 93 | + public let accountAvatarUrl: String? |
| 94 | + public let repositorySelection: String |
| 95 | + |
| 96 | + public init( |
| 97 | + id: String, |
| 98 | + installationId: Int, |
| 99 | + accountLogin: String, |
| 100 | + accountType: String, |
| 101 | + accountAvatarUrl: String?, |
| 102 | + repositorySelection: String |
| 103 | + ) { |
| 104 | + self.id = id |
| 105 | + self.installationId = installationId |
| 106 | + self.accountLogin = accountLogin |
| 107 | + self.accountType = accountType |
| 108 | + self.accountAvatarUrl = accountAvatarUrl |
| 109 | + self.repositorySelection = repositorySelection |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +/// Cheap "do you have any installations?" probe returned by |
| 114 | +/// `GET /api/v1/installations/precheck`. |
| 115 | +public struct AutopilotPrecheckResponse: Codable, Sendable { |
| 116 | + public let hasInstallation: Bool |
| 117 | + public let count: Int |
| 118 | + |
| 119 | + public init(hasInstallation: Bool, count: Int) { |
| 120 | + self.hasInstallation = hasInstallation |
| 121 | + self.count = count |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +/// Reply from `GET /api/v1/installations/install-url`. The URL embeds a |
| 126 | +/// signed `state` JWT tying the GitHub callback back to the requesting |
| 127 | +/// rxauth user, so the install completes correctly even if the browser |
| 128 | +/// is not signed in to autopilot.rxlab.app. |
| 129 | +public struct AutopilotInstallUrlResponse: Codable, Sendable { |
| 130 | + public let url: String |
| 131 | + public let state: String |
| 132 | + public let expiresAt: String |
| 133 | + |
| 134 | + public init(url: String, state: String, expiresAt: String) { |
| 135 | + self.url = url |
| 136 | + self.state = state |
| 137 | + self.expiresAt = expiresAt |
| 138 | + } |
| 139 | +} |
| 140 | + |
0 commit comments