From 32d54cfc1c5aefd0378f60cfea7e2ba84824f811 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 21 Apr 2024 19:33:18 +0100 Subject: [PATCH] refactor: rename config variables,etc as repo_config --- src/server/actors/repo/config.rs | 7 ++++--- src/server/actors/repo/mod.rs | 12 ++++++------ src/server/actors/repo/webhook.rs | 4 ++-- src/server/config/mod.rs | 4 ++-- src/server/gitforge/tests/common.rs | 6 +++--- src/server/gitforge/tests/forgejo.rs | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/server/actors/repo/config.rs b/src/server/actors/repo/config.rs index f1eb98e..d90b731 100644 --- a/src/server/actors/repo/config.rs +++ b/src/server/actors/repo/config.rs @@ -5,13 +5,14 @@ use crate::server::{config::RepoDetails, gitforge}; use super::{LoadedConfig, RepoActor}; +/// Loads the [RepoConfig] from the `.git-next.toml` file in the repository pub async fn load(repo_details: RepoDetails, addr: Addr, forge: gitforge::Forge) { - let config = match crate::server::config::load::load(&repo_details, &forge).await { - Ok(config) => config, + let repo_config = match crate::server::config::load::load(&repo_details, &forge).await { + Ok(repo_config) => repo_config, Err(err) => { error!(?err, "Failed to load config"); return; } }; - addr.do_send(LoadedConfig(config)); + addr.do_send(LoadedConfig(repo_config)); } diff --git a/src/server/actors/repo/mod.rs b/src/server/actors/repo/mod.rs index ab6231a..94e942b 100644 --- a/src/server/actors/repo/mod.rs +++ b/src/server/actors/repo/mod.rs @@ -88,9 +88,9 @@ struct LoadedConfig(pub RepoConfig); impl Handler for RepoActor { type Result = (); fn handle(&mut self, msg: LoadedConfig, ctx: &mut Self::Context) -> Self::Result { - let config = msg.0; - info!(%self.details, %config, "Config loaded"); - self.details.config.replace(config); + let repo_config = msg.0; + info!(%self.details, %repo_config, "Config loaded"); + self.details.repo_config.replace(repo_config); if self.webhook_id.is_none() { webhook::register( self.details.clone(), @@ -111,7 +111,7 @@ pub struct ValidateRepo; impl Handler for RepoActor { type Result = (); fn handle(&mut self, _msg: ValidateRepo, ctx: &mut Self::Context) -> Self::Result { - if let Some(repo_config) = self.details.config.clone() { + if let Some(repo_config) = self.details.repo_config.clone() { let forge = self.forge.clone(); let addr = ctx.address(); async move { forge.branches_validate_positions(repo_config, addr).await } @@ -132,7 +132,7 @@ pub struct StartMonitoring { impl Handler for RepoActor { type Result = (); fn handle(&mut self, msg: StartMonitoring, ctx: &mut Self::Context) -> Self::Result { - let Some(repo_config) = self.details.config.clone() else { + let Some(repo_config) = self.details.repo_config.clone() else { warn!("No config loaded"); return; }; @@ -180,7 +180,7 @@ pub struct AdvanceMainTo(pub gitforge::Commit); impl Handler for RepoActor { type Result = (); fn handle(&mut self, msg: AdvanceMainTo, ctx: &mut Self::Context) -> Self::Result { - let Some(repo_config) = self.details.config.clone() else { + let Some(repo_config) = self.details.repo_config.clone() else { warn!("No config loaded"); return; }; diff --git a/src/server/actors/repo/webhook.rs b/src/server/actors/repo/webhook.rs index c9b6a2d..46b9cdf 100644 --- a/src/server/actors/repo/webhook.rs +++ b/src/server/actors/repo/webhook.rs @@ -92,7 +92,7 @@ pub async fn register( addr: actix::prelude::Addr, net: network::Network, ) { - let Some(repo_config) = repo_details.config.clone() else { + let Some(repo_config) = repo_details.repo_config.clone() else { return; }; @@ -214,7 +214,7 @@ impl Handler for RepoActor { match serde_json::from_str::(body) { Err(err) => debug!(?err, %body, "Not a 'push'"), Ok(push) => { - if let Some(config) = &self.details.config { + if let Some(config) = &self.details.repo_config { match push.branch(config.branches()) { None => warn!( ?push, diff --git a/src/server/config/mod.rs b/src/server/config/mod.rs index 0b96ffe..94151ee 100644 --- a/src/server/config/mod.rs +++ b/src/server/config/mod.rs @@ -326,7 +326,7 @@ pub struct RepoDetails { pub repo_path: RepoPath, pub branch: BranchName, pub forge: ForgeDetails, - pub config: Option, + pub repo_config: Option, pub gitdir: Option, } impl RepoDetails { @@ -339,7 +339,7 @@ impl RepoDetails { Self { name: name.clone(), repo_path: RepoPath(server_repo_config.repo.clone()), - config: server_repo_config.repo_config(), + repo_config: server_repo_config.repo_config(), branch: BranchName(server_repo_config.branch.clone()), gitdir: server_repo_config.gitdir(), forge: ForgeDetails { diff --git a/src/server/gitforge/tests/common.rs b/src/server/gitforge/tests/common.rs index e22dd3c..5e2fe5a 100644 --- a/src/server/gitforge/tests/common.rs +++ b/src/server/gitforge/tests/common.rs @@ -31,7 +31,7 @@ pub fn forge_name(n: u32) -> ForgeName { pub fn repo_details( n: u32, forge: ForgeDetails, - config: Option, + repo_config: Option, gitdir: Option, ) -> RepoDetails { RepoDetails { @@ -40,7 +40,7 @@ pub fn repo_details( gitdir, branch: branch_name(n), forge, - config, + repo_config, } } @@ -56,7 +56,7 @@ pub fn repo_alias(n: u32) -> RepoAlias { RepoAlias(format!("repo-alias-{}", n)) } -pub fn config(n: u32) -> RepoConfig { +pub fn repo_config(n: u32) -> RepoConfig { RepoConfig::new(RepoBranches::new( format!("main-{n}"), format!("next-{n}"), diff --git a/src/server/gitforge/tests/forgejo.rs b/src/server/gitforge/tests/forgejo.rs index 10fea2e..aec90a3 100644 --- a/src/server/gitforge/tests/forgejo.rs +++ b/src/server/gitforge/tests/forgejo.rs @@ -12,7 +12,7 @@ fn test_name() { let repo_details = common::repo_details( 1, common::forge_details(1, ForgeType::MockForge), - Some(common::config(1)), + Some(common::repo_config(1)), None, ); let forge = Forge::new_forgejo(repo_details, net); @@ -35,7 +35,7 @@ async fn test_branches_get() { let repo_details = common::repo_details( 1, common::forge_details(1, ForgeType::MockForge), - Some(common::config(1)), + Some(common::repo_config(1)), None, );