gitbay/Issues/IssueModels.swift
56 lines · 1587 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 createdAt: Date
35 let comments: [Comment]?
36
37 enum CodingKeys: String, CodingKey {
38 case number, title, state, author, milestone, labels, assignees, body, comments
39 case createdAt = "created_at"
40 }
41
42 var isOpen: Bool { state == "open" }
43
44 nonisolated struct Comment: Decodable, Sendable, Hashable, Identifiable {
45 let author: String
46 let body: String
47 let createdAt: Date
48
49 enum CodingKeys: String, CodingKey {
50 case author, body
51 case createdAt = "created_at"
52 }
53
54 var id: String { author + createdAt.timeIntervalSince1970.description + body }
55 }
56}