-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeployment.swift
32 lines (30 loc) · 1.21 KB
/
Deployment.swift
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
public extension Client {
func buildInfo() async throws(ClientError) -> BuildInfoResponse {
let res = try await request("/api/v2/buildinfo", method: .get)
guard res.resp.statusCode == 200 else {
throw responseAsError(res)
}
do {
return try Client.decoder.decode(BuildInfoResponse.self, from: res.data)
} catch {
throw .unexpectedResponse(res.data.prefix(1024))
}
}
}
public struct BuildInfoResponse: Encodable, Decodable, Equatable, Sendable {
public let external_url: String
public let version: String
public let dashboard_url: String
public let telemetry: Bool
public let workspace_proxy: Bool
public let agent_api_version: String
public let provisioner_api_version: String
public let upgrade_message: String
public let deployment_id: String
// `version` in the form `[0-9]+.[0-9]+.[0-9]+`
public var semver: String? {
return try? NSRegularExpression(pattern: #"v(\d+\.\d+\.\d+)"#)
.firstMatch(in: version, range: NSRange(version.startIndex ..< version.endIndex, in: version))
.flatMap { Range($0.range(at: 1), in: version).map { String(version[$0]) } }
}
}