gitbay/Dashboard/DashboardModels.swift
74 lines · 2745 bytes
1import Foundation
2
3/// The `dashboard` command: the same account aggregate as the web
4/// dashboard, in one read. Newer arrays default empty so an updated app
5/// can still talk to a server from before the dashboard parity contract.
6nonisolated struct DashboardData: Decodable, Sendable, Hashable {
7 let reviewQueue: [DashboardItem]
8 let assignedIssues: [DashboardItem]
9 let openMRs: [DashboardItem]
10 let openIssues: [DashboardItem]
11 /// Pinned repos share `repo list`'s row shape.
12 let pinned: [RepoSummary]
13 let recentActivity: [FeedEvent]
14 /// Retained by the CLI for compatibility; builds are not a web
15 /// dashboard section.
16 let builds: [DashboardBuild]
17
18 enum CodingKeys: String, CodingKey {
19 case pinned, builds
20 case reviewQueue = "review_queue"
21 case openMRs = "open_mrs"
22 case assignedIssues = "assigned_issues"
23 case openIssues = "open_issues"
24 case recentActivity = "recent_activity"
25 }
26
27 init(from decoder: any Decoder) throws {
28 let values = try decoder.container(keyedBy: CodingKeys.self)
29 reviewQueue = try values.decodeIfPresent([DashboardItem].self, forKey: .reviewQueue) ?? []
30 assignedIssues = try values.decodeIfPresent([DashboardItem].self, forKey: .assignedIssues) ?? []
31 openMRs = try values.decodeIfPresent([DashboardItem].self, forKey: .openMRs) ?? []
32 openIssues = try values.decodeIfPresent([DashboardItem].self, forKey: .openIssues) ?? []
33 pinned = try values.decodeIfPresent([RepoSummary].self, forKey: .pinned) ?? []
34 recentActivity = try values.decodeIfPresent([FeedEvent].self, forKey: .recentActivity) ?? []
35 builds = try values.decodeIfPresent([DashboardBuild].self, forKey: .builds) ?? []
36 }
37}
38
39/// One open issue or MR row, repo resolved server-side.
40nonisolated struct DashboardItem: Decodable, Sendable, Hashable, Identifiable {
41 let repo: String
42 let number: Int64
43 let title: String
44 let author: String
45 let state: String
46 let updatedAt: Date
47
48 enum CodingKeys: String, CodingKey {
49 case repo, number, title, author, state
50 case updatedAt = "updated_at"
51 }
52
53 var id: String { "\(repo)#\(number)" }
54}
55
56/// One build row with its repo attached.
57nonisolated struct DashboardBuild: Decodable, Sendable, Hashable, Identifiable {
58 let repo: String
59 let number: Int64
60 let job: String
61 let status: String
62 let sha: String
63 let ref: String
64 let createdAt: Date
65 let finishedAt: Date?
66
67 enum CodingKeys: String, CodingKey {
68 case repo, number, job, status, sha, ref
69 case createdAt = "created_at"
70 case finishedAt = "finished_at"
71 }
72
73 var id: String { "\(repo)#\(number)" }
74}