import Foundation import SwiftUI /// One row of `build list`. nonisolated struct Build: Decodable, Sendable, Hashable, Identifiable { let number: Int64 let job: String let status: String let sha: String let ref: String let createdAt: Date let finishedAt: Date? enum CodingKeys: String, CodingKey { case number, job, status, sha, ref case createdAt = "created_at" case finishedAt = "finished_at" } var id: Int64 { number } var shortSHA: String { String(sha.prefix(10)) } } /// `build jobs` — what a trigger can name. A repo with no CI config has /// none, which is an empty state rather than an error. nonisolated struct CIJob: Decodable, Sendable, Hashable, Identifiable { let name: String let schedule: String? let tags: String? var id: String { name } /// Why this job runs, in the words the server uses. var trigger: String { if let schedule, !schedule.isEmpty { return "schedule \(schedule)" } if let tags, !tags.isEmpty { return "tags \(tags)" } return "on push" } } extension Build { /// The list row and the detail header must agree on what a status /// looks like; the strings come from the registry. var statusIcon: String { switch status { case "success": "checkmark.circle.fill" case "failure", "error": "xmark.circle.fill" case "running": "circle.dotted" case "queued", "pending": "clock" default: "questionmark.circle" } } var statusColor: Color { switch status { case "success": .gbOK case "failure", "error": .gbBad case "running", "queued", "pending": .gbWarn default: .secondary } } }