gitbay/Issues/IssueModels.swift
60 lines · 1731 bytes
1import Foundation
2
3/// One issue; `issue list` rows and the header of `issue show`.
4nonisolated struct Issue: Decodable, Sendable, Hashable, Identifiable {
5 let number: Int64
6 let title: String
7 let state: String
8 let author: String
9 let milestone: String?
10 let labels: [String]?
11 let assignees: [String]?
12 let body: String?
13 let createdAt: Date
14
15 enum CodingKeys: String, CodingKey {
16 case number, title, state, author, milestone, labels, assignees, body
17 case createdAt = "created_at"
18 }
19
20 var id: Int64 { number }
21 var isOpen: Bool { state == "open" }
22}
23
24/// `issue show <owner/name> <n>` — the issue plus its comments.
25nonisolated struct IssueDetail: Decodable, Sendable, Hashable {
26 let number: Int64
27 let title: String
28 let state: String
29 let author: String
30 let milestone: String?
31 let labels: [String]?
32 let assignees: [String]?
33 let body: String?
34 let bodyFormat: String?
35 let createdAt: Date
36 let comments: [Comment]?
37
38 enum CodingKeys: String, CodingKey {
39 case number, title, state, author, milestone, labels, assignees, body, comments
40 case bodyFormat = "body_format"
41 case createdAt = "created_at"
42 }
43
44 var isOpen: Bool { state == "open" }
45
46 nonisolated struct Comment: Decodable, Sendable, Hashable, Identifiable {
47 let author: String
48 let body: String
49 let bodyFormat: String?
50 let createdAt: Date
51
52 enum CodingKeys: String, CodingKey {
53 case author, body
54 case bodyFormat = "body_format"
55 case createdAt = "created_at"
56 }
57
58 var id: String { author + createdAt.timeIntervalSince1970.description + body }
59 }
60}