gitbay/Repos/LogViewModel.swift

5411753023a5e2958f17b523903abce380941107
gitbay-ios/gitbay/Repos/LogViewModel.swift history · blame · raw

27 lines · 693 bytes

 1import Foundation
 2import Observation
 3
 4/// `repo log`: the default branch's history, signature verdict per commit.
 5@Observable
 6@MainActor
 7final class LogViewModel {
 8
 9    private(set) var state: LoadState<[Commit]> = .loading
10
11    private let client: GitbayClient
12    let repoPath: String
13
14    init(client: GitbayClient, repoPath: String) {
15        self.client = client
16        self.repoPath = repoPath
17    }
18
19    func load() async {
20        do {
21            let commits = try await client.readList(["repo", "log", repoPath], of: Commit.self)
22            state = commits.isEmpty ? .empty("No commits yet.") : .loaded(commits)
23        } catch {
24            state = .from(error)
25        }
26    }
27}