// CxLLM Studio — macOS Application // Services/GitService.swift — Gitea integration service import Foundation import CxGit import CxCode @Observable final class GitService { private(set) var isConnected = false private(set) var healthStatus: GitHealthStatus? private(set) var repositories: [GitRepository] = [] private(set) var pullRequests: [GitPullRequest] = [] private(set) var issues: [GitIssue] = [] private(set) var branches: [GitBranch] = [] private(set) var actionRuns: [GitActionRun] = [] private(set) var currentUser: GitUser? private(set) var error: String? let client: CxGitClient init(config: CxGitConfig = CxGitConfig()) { self.client = CxGitClient(config: config) } func checkHealth() async { let health = await client.healthCheck() healthStatus = health isConnected = health.isHealthy } func loadRepositories(org: String? = nil) async { do { repositories = try await client.listOrgRepos(org) error = nil } catch { self.error = error.localizedDescription } } func loadPullRequests(owner: String, repo: String) async { do { pullRequests = try await client.listPulls(owner, repo) error = nil } catch { self.error = error.localizedDescription } } func loadIssues(owner: String, repo: String) async { do { issues = try await client.listIssues(owner, repo) error = nil } catch { self.error = error.localizedDescription } } func loadBranches(owner: String, repo: String) async { do { branches = try await client.listBranches(owner, repo) error = nil } catch { self.error = error.localizedDescription } } func loadActionRuns(owner: String, repo: String) async { do { actionRuns = try await client.listActionRuns(owner, repo) error = nil } catch { self.error = error.localizedDescription } } func loadCurrentUser() async { do { currentUser = try await client.authenticatedUser() } catch { // Not critical — user may not be authenticated } } func refreshAll() async { await checkHealth() await loadRepositories() await loadCurrentUser() } func createPullRequest(owner: String, repo: String, title: String, head: String, base: String = "main", body: String = "") async throws -> GitPullRequest { try await client.createPull(owner, repo, title: title, head: head, base: base, body: body) } func createIssue(owner: String, repo: String, title: String, body: String = "") async throws -> GitIssue { try await client.createIssue(owner, repo, title: title, body: body) } func createBranch(owner: String, repo: String, name: String, from: String = "main") async throws -> GitBranch { try await client.createBranch(owner, repo, name: name, from: from) } }