import Foundation import Observation /// `repo log`: the default branch's history, signature verdict per commit. @Observable @MainActor final class LogViewModel { private(set) var state: LoadState<[Commit]> = .loading private let client: GitbayClient let repoPath: String /// nil reads the default branch, as the command does. let ref: String? /// Set to follow one file's history, as the blob page does. let path: String? init(client: GitbayClient, repoPath: String, ref: String? = nil, path: String? = nil) { self.client = client self.repoPath = repoPath self.ref = ref self.path = path } func load() async { var argv = ["repo", "log", repoPath] if let ref { argv.append(contentsOf: ["--ref", ref]) } if let path { argv.append(contentsOf: ["--path", path]) } do { let commits = try await client.readList(argv, of: Commit.self) state = commits.isEmpty ? .empty("No commits yet.") : .loaded(commits) } catch { state = .from(error) } } }