2024-05-11 19:46:20 +01:00
|
|
|
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}`
|
2024-05-15 07:55:05 +01:00
|
|
|
#[derive(
|
2024-06-19 07:03:08 +01:00
|
|
|
Clone,
|
|
|
|
Debug,
|
|
|
|
derive_more::From,
|
|
|
|
PartialEq,
|
|
|
|
Eq,
|
|
|
|
PartialOrd,
|
|
|
|
Ord,
|
|
|
|
serde::Deserialize,
|
|
|
|
derive_more::Display,
|
|
|
|
derive_more::Constructor,
|
2024-05-15 07:55:05 +01:00
|
|
|
)]
|
2024-05-12 22:27:20 +01:00
|
|
|
#[display("{}@{}", repo, branch)]
|
2024-05-11 19:46:20 +01:00
|
|
|
pub struct ServerRepoConfig {
|
2024-05-15 07:55:05 +01:00
|
|
|
repo: String,
|
|
|
|
branch: String,
|
|
|
|
gitdir: Option<PathBuf>,
|
|
|
|
main: Option<String>,
|
|
|
|
next: Option<String>,
|
|
|
|
dev: Option<String>,
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
impl ServerRepoConfig {
|
|
|
|
pub fn repo(&self) -> RepoPath {
|
2024-05-15 07:55:05 +01:00
|
|
|
RepoPath::new(self.repo.clone())
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn branch(&self) -> BranchName {
|
2024-05-12 22:27:20 +01:00
|
|
|
BranchName::new(&self.branch)
|
2024-05-11 19:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2024-05-15 07:55:05 +01:00
|
|
|
(Some(main), Some(next), Some(dev)) => Some(RepoConfig::new(
|
|
|
|
RepoBranches::new(main.to_string(), next.to_string(), dev.to_string()),
|
|
|
|
RepoConfigSource::Server,
|
|
|
|
)),
|
2024-05-11 19:46:20 +01:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|