diff --git a/src/server/actors/repo/config.rs b/src/server/actors/repo/config.rs index febf6eba..74a52ce3 100644 --- a/src/server/actors/repo/config.rs +++ b/src/server/actors/repo/config.rs @@ -10,16 +10,23 @@ use crate::server::{ use super::{LoadedConfig, RepoActor}; pub async fn load(details: RepoDetails, addr: Addr, net: Network) { - let config = match details.forge.forge_type { - #[cfg(feature = "forgejo")] - ForgeType::ForgeJo => forge::forgejo::config::load(&details, &net).await, - #[cfg(test)] - ForgeType::MockForge => forge::mock::config::load(&details, &net).await, - }; - match config { - Ok(config) => addr.do_send(LoadedConfig(config)), - Err(err) => { - error!(?err, "Failed to load config"); + let config = match details.config { + Some(config) => config, + None => { + let config = match details.forge.forge_type { + #[cfg(feature = "forgejo")] + ForgeType::ForgeJo => forge::forgejo::config::load(&details, &net).await, + #[cfg(test)] + ForgeType::MockForge => forge::mock::config::load(&details, &net).await, + }; + match config { + Ok(config) => config, + Err(err) => { + error!(?err, "Failed to load config"); + return; + } + } } - } + }; + addr.do_send(LoadedConfig(config)); } diff --git a/src/server/config.rs b/src/server/config.rs index 4d731442..d390578b 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -124,6 +124,9 @@ impl Display for Forge { pub struct Repo { repo: String, branch: String, + main: Option, + next: Option, + dev: Option, } impl Repo { #[allow(dead_code)] @@ -135,6 +138,19 @@ impl Repo { pub fn branch(&self) -> BranchName { BranchName(self.branch.clone()) } + /// 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(), + }, + }), + _ => None, + } + } } #[cfg(test)] impl AsRef for Repo { @@ -252,12 +268,14 @@ pub struct RepoDetails { pub repo: RepoPath, pub branch: BranchName, pub forge: ForgeDetails, + pub config: Option, } impl RepoDetails { pub fn new(name: &RepoName, repo: &Repo, forge_name: &ForgeName, forge: &Forge) -> Self { Self { name: name.clone(), repo: RepoPath(repo.repo.clone()), + config: repo.repo_config(), branch: BranchName(repo.branch.clone()), forge: ForgeDetails { name: forge_name.clone(), @@ -326,7 +344,14 @@ mod tests { [forge.default.repos] hello = { repo = "user/hello", branch = "main" } - world = { repo = "user/world", branch = "master" } + world = { repo = "user/world", branch = "master", main = "main", next = "next", dev = "dev" } + + [forge.default.repos.sam] + repo = "user/sam" + branch = "main" + main = "master" + next = "upcoming" + dev = "sam-dev" "#, ) .map_err(OneOf::new)?; @@ -345,6 +370,9 @@ mod tests { Repo { repo: "user/hello".to_string(), branch: "main".to_string(), + main: None, + next: None, + dev: None, }, ), ( @@ -352,13 +380,40 @@ mod tests { Repo { repo: "user/world".to_string(), branch: "master".to_string(), + main: Some("main".to_string()), + next: Some("next".to_string()), + dev: Some("dev".to_string()), + }, + ), + ( + "sam".to_string(), + Repo { + repo: "user/sam".to_string(), + branch: "main".to_string(), + main: Some("master".to_string()), + next: Some("upcoming".to_string()), + dev: Some("sam-dev".to_string()), }, ), ]), }, )]), }; - assert_eq!(config, expected); + assert_eq!(config, expected, "ServerConfig"); + + if let Some(forge) = config.forge.get("world") { + if let Some(repo) = forge.repos.get("sam") { + let repo_config = repo.repo_config(); + let expected = Some(RepoConfig { + branches: RepoBranches { + main: "master".to_string(), + next: "upcoming".to_string(), + dev: "sam-dev".to_string(), + }, + }); + assert_eq!(repo_config, expected, "RepoConfig"); + } + } Ok(()) }