gitbay/Builds/BuildFilter.swift

v1.10.0
gitbay-ios/gitbay/Builds/BuildFilter.swift history · blame · raw

32 lines · 964 bytes

 1import Foundation
 2
 3/// What `build list` is narrowed to: `--ref`, `--status` and `--job`.
 4/// There is no state flag, so the default sends the bare command.
 5nonisolated struct BuildFilter: Equatable, Sendable {
 6
 7    /// The vocabulary `--status` accepts; anything else is a usage error.
 8    enum Status: String, CaseIterable, Identifiable, Sendable {
 9        case pending, running, success, failure, cancelled
10
11        var id: String { rawValue }
12    }
13
14    var ref = ""
15    var status: Status?
16    var job: String?
17
18    func flags() -> [String] {
19        var flags = filterFlag("--ref", ref)
20        flags += filterFlag("--status", status?.rawValue)
21        flags += filterFlag("--job", job)
22        return flags
23    }
24
25    var isNarrowed: Bool { !flags().isEmpty }
26
27    var emptyMessage: String {
28        isNarrowed
29            ? "No builds match these filters."
30            : "No builds. Builds run when a push touches a repo with a .gitbay/ job file."
31    }
32}