gitbay/Issues/Milestone.swift

v1.14.1
gitbay-ios/gitbay/Issues/Milestone.swift history · blame · raw

33 lines · 1227 bytes

 1import Foundation
 2
 3/// One row of `milestone list`, with progress counts.
 4nonisolated struct Milestone: Decodable, Sendable, Hashable, Identifiable {
 5    let title: String
 6    let description: String?
 7    let due: String?
 8    let state: String
 9    /// True for a milestone the repository sees through its org
10    /// (v1.19.0). The repository cannot close or reopen it; `org
11    /// milestone` does. Absent on the wire for a repository row and on
12    /// older servers.
13    let org: Bool
14    let open: Int
15    let closed: Int
16
17    var id: String { title }
18
19    private enum CodingKeys: String, CodingKey {
20        case title, description, due, state, org, open, closed
21    }
22
23    init(from decoder: Decoder) throws {
24        let c = try decoder.container(keyedBy: CodingKeys.self)
25        title = try c.decode(String.self, forKey: .title)
26        description = try c.decodeIfPresent(String.self, forKey: .description)
27        due = try c.decodeIfPresent(String.self, forKey: .due)
28        state = try c.decode(String.self, forKey: .state)
29        org = try c.decodeIfPresent(Bool.self, forKey: .org) ?? false
30        open = try c.decode(Int.self, forKey: .open)
31        closed = try c.decode(Int.self, forKey: .closed)
32    }
33}