summaryrefslogtreecommitdiff
path: root/Hutch/Models
diff options
context:
space:
mode:
Diffstat (limited to 'Hutch/Models')
-rw-r--r--Hutch/Models/Builds.swift27
-rw-r--r--Hutch/Models/Git.swift19
2 files changed, 36 insertions, 10 deletions
diff --git a/Hutch/Models/Builds.swift b/Hutch/Models/Builds.swift
index 6694c35..b0c0e8d 100644
--- a/Hutch/Models/Builds.swift
+++ b/Hutch/Models/Builds.swift
@@ -34,10 +34,33 @@ enum TaskStatus: String, Codable, Sendable {
/// A single task within a build job.
struct BuildTask: Codable, Sendable, Identifiable {
- var id: String { name }
+ private(set) var ordinal: Int?
let name: String
let status: TaskStatus
let log: BuildLog?
+
+ var id: String {
+ if let ordinal {
+ return "\(ordinal):\(name)"
+ }
+ return [name, log?.fullURL, status.rawValue]
+ .compactMap { $0 }
+ .joined(separator: "::")
+ }
+
+ var logCacheKey: String {
+ id
+ }
+
+ func withOrdinal(_ ordinal: Int) -> BuildTask {
+ var task = self
+ task.ordinal = ordinal
+ return task
+ }
+
+ private enum CodingKeys: String, CodingKey {
+ case name, status, log
+ }
}
// MARK: - Job Summary (for list view)
@@ -90,7 +113,7 @@ struct JobDetail: Codable, Sendable {
let visibility: Visibility?
let image: String?
let manifest: String?
- let tasks: [BuildTask]
+ var tasks: [BuildTask]
let log: BuildLog?
let owner: Entity
}
diff --git a/Hutch/Models/Git.swift b/Hutch/Models/Git.swift
index 19ec31b..905822e 100644
--- a/Hutch/Models/Git.swift
+++ b/Hutch/Models/Git.swift
@@ -113,7 +113,7 @@ struct GitTree: Codable, Sendable {
struct GitTextBlob: Codable, Sendable {
let id: String?
let shortId: String?
- let text: String
+ let text: String?
let size: Int?
}
@@ -134,14 +134,16 @@ struct GitTreeEntryPage: Codable, Sendable {
extension GitObject: Codable {
private enum CodingKeys: String, CodingKey {
case type, id, shortId, entries, text, size, content
+ case typename = "__typename"
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decodeIfPresent(String.self, forKey: .type)
+ let typename = try container.decodeIfPresent(String.self, forKey: .typename)
- switch type {
- case "TREE":
+ switch type ?? typename {
+ case "TREE", "Tree":
let tree = GitTree(
id: try container.decodeIfPresent(String.self, forKey: .id),
shortId: try container.decodeIfPresent(String.self, forKey: .shortId),
@@ -149,13 +151,12 @@ extension GitObject: Codable {
)
self = .tree(tree)
- case "BLOB":
- // TextBlob has a "text" key; BinaryBlob does not
- if container.contains(.text) {
+ case "BLOB", "TextBlob", "BinaryBlob":
+ if typename == "TextBlob" || container.contains(.text) {
let blob = GitTextBlob(
id: try container.decodeIfPresent(String.self, forKey: .id),
shortId: try container.decodeIfPresent(String.self, forKey: .shortId),
- text: try container.decode(String.self, forKey: .text),
+ text: try container.decodeIfPresent(String.self, forKey: .text),
size: try container.decodeIfPresent(Int.self, forKey: .size)
)
self = .textBlob(blob)
@@ -184,12 +185,14 @@ extension GitObject: Codable {
try container.encodeIfPresent(tree.entries, forKey: .entries)
case .textBlob(let blob):
try container.encode("BLOB", forKey: .type)
+ try container.encode("TextBlob", forKey: .typename)
try container.encodeIfPresent(blob.id, forKey: .id)
try container.encodeIfPresent(blob.shortId, forKey: .shortId)
- try container.encode(blob.text, forKey: .text)
+ try container.encodeIfPresent(blob.text, forKey: .text)
try container.encodeIfPresent(blob.size, forKey: .size)
case .binaryBlob(let blob):
try container.encode("BLOB", forKey: .type)
+ try container.encode("BinaryBlob", forKey: .typename)
try container.encodeIfPresent(blob.id, forKey: .id)
try container.encodeIfPresent(blob.shortId, forKey: .shortId)
try container.encodeIfPresent(blob.size, forKey: .size)