use std::path::PathBuf; use crate::{BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, RepoPath}; /// Defines a Repo within a ForgeConfig to be monitored by the server /// Maps from `git-next-server.toml` at `forge.{forge}.repos.{name}` #[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)] pub struct ServerRepoConfig { pub repo: String, pub branch: String, pub gitdir: Option, pub main: Option, pub next: Option, pub dev: Option, } impl ServerRepoConfig { pub fn repo(&self) -> RepoPath { RepoPath(self.repo.clone()) } #[allow(dead_code)] pub fn branch(&self) -> BranchName { BranchName(self.branch.clone()) } pub fn gitdir(&self) -> Option { self.gitdir.clone().map(GitDir::from) } /// Returns a RepoConfig from the server configuration if ALL THREE branches were provided pub fn repo_config(&self) -> Option { match (&self.main, &self.next, &self.dev) { (Some(main), Some(next), Some(dev)) => Some(RepoConfig { branches: RepoBranches { main: main.to_string(), next: next.to_string(), dev: dev.to_string(), }, source: RepoConfigSource::Server, }), _ => None, } } } #[cfg(test)] impl AsRef for ServerRepoConfig { fn as_ref(&self) -> &Self { self } } impl std::fmt::Display for ServerRepoConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}@{}", self.repo, self.branch) } }