git-next/crates/config/src/server_repo_config.rs

45 lines
1.3 KiB
Rust
Raw Normal View History

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, derive_more::Constructor, derive_more::Display,
)]
#[display("{}@{}", repo, branch)]
pub struct ServerRepoConfig {
2024-06-06 18:31:48 +01:00
/// repo path: owner/repo
repo: String,
2024-06-06 18:31:48 +01:00
/// branch name
branch: String,
gitdir: Option<PathBuf>,
main: Option<String>,
next: Option<String>,
dev: Option<String>,
}
impl ServerRepoConfig {
pub fn repo(&self) -> RepoPath {
RepoPath::new(self.repo.clone())
}
pub fn branch(&self) -> BranchName {
BranchName::new(&self.branch)
}
pub fn gitdir(&self) -> Option<GitDir> {
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<RepoConfig> {
match (&self.main, &self.next, &self.dev) {
(Some(main), Some(next), Some(dev)) => Some(RepoConfig::new(
RepoBranches::new(main.to_string(), next.to_string(), dev.to_string()),
RepoConfigSource::Server,
)),
_ => None,
}
}
}