git-next/crates/config/src/server_repo_config.rs
Paul Campbell df352443b7
All checks were successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Successful in 1m21s
feat: GitDir tracks when repo is cloned by git-next
2024-07-06 15:08:13 +01:00

54 lines
1.5 KiB
Rust

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,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Deserialize,
derive_more::Display,
derive_more::Constructor,
)]
#[display("{}@{}", repo, branch)]
pub struct ServerRepoConfig {
repo: String,
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()
// Provenance is external as the gitdir is only used to specify non-internal paths
.map(|dir| GitDir::new(dir, crate::git_dir::StoragePathType::External))
}
/// 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,
}
}
}