mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-26 14:18:32 -05:00
Adds code coverage reports to pull requests. Enabling code coverage gathering appears to be about a 25% increase in build time, unfortunately, so just enabling it for the App/Shared targets and doing it in a separate scheme so it doesn't impact local build times.
55 lines
1.6 KiB
Swift
55 lines
1.6 KiB
Swift
import Foundation
|
|
import ObjectMapper
|
|
|
|
struct WebhookPersisted: Codable {
|
|
var request: WebhookRequest
|
|
var identifier: WebhookResponseIdentifier
|
|
|
|
enum CodingKeys: CodingKey {
|
|
case request
|
|
case identifier
|
|
}
|
|
|
|
enum CodingError: Error {
|
|
case requestFailure
|
|
}
|
|
|
|
init(request: WebhookRequest, identifier: WebhookResponseIdentifier) {
|
|
self.request = request
|
|
self.identifier = identifier
|
|
}
|
|
|
|
func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
|
|
try container.encode(
|
|
Mapper<WebhookRequest>(context: WebhookRequestContext.local).toJSON(request),
|
|
forKey: .request
|
|
)
|
|
try container.encode(identifier, forKey: .identifier)
|
|
}
|
|
|
|
init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
let json = try container.decode([String: Any].self, forKey: .request)
|
|
self.request = try Mapper<WebhookRequest>(context: WebhookRequestContext.local).map(JSON: json)
|
|
self.identifier = try container.decode(WebhookResponseIdentifier.self, forKey: .identifier)
|
|
}
|
|
}
|
|
|
|
extension URLSessionTask {
|
|
var webhookPersisted: WebhookPersisted? {
|
|
get {
|
|
if let data = taskDescription.flatMap({ Data(base64Encoded: $0) }) {
|
|
return try? JSONDecoder().decode(WebhookPersisted.self, from: data)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
set {
|
|
taskDescription = try? JSONEncoder().encode(newValue).base64EncodedString()
|
|
}
|
|
}
|
|
}
|