import Foundation import Observation /// `mr range-diff --from --to ` — git's /// range-diff between two heads the merge request has had, as text. @Observable @MainActor final class RangeDiffViewModel { private(set) var state: LoadState = .loading private let client: GitbayClient let repoPath: String let number: Int64 let from: String let to: String init(client: GitbayClient, repoPath: String, number: Int64, from: String, to: String) { self.client = client self.repoPath = repoPath self.number = number self.from = from self.to = to } func load() async { state = .loading do { let text = try await client.readText( ["mr", "range-diff", repoPath, String(number), "--from", from, "--to", to]) state = text.isEmpty ? .empty("The two revisions carry the same commits.") : .loaded(text) } catch { state = .from(error) } } }