refactor: rename config variables,etc as repo_config

This commit is contained in:
Paul Campbell 2024-04-21 19:33:18 +01:00
parent ee8b1e9fce
commit 32d54cfc1c
6 changed files with 19 additions and 18 deletions

View file

@ -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<RepoActor>, 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));
}

View file

@ -88,9 +88,9 @@ struct LoadedConfig(pub RepoConfig);
impl Handler<LoadedConfig> 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<ValidateRepo> 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<StartMonitoring> 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<AdvanceMainTo> 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;
};

View file

@ -92,7 +92,7 @@ pub async fn register(
addr: actix::prelude::Addr<super::RepoActor>,
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<WebhookMessage> for RepoActor {
match serde_json::from_str::<Push>(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,

View file

@ -326,7 +326,7 @@ pub struct RepoDetails {
pub repo_path: RepoPath,
pub branch: BranchName,
pub forge: ForgeDetails,
pub config: Option<RepoConfig>,
pub repo_config: Option<RepoConfig>,
pub gitdir: Option<GitDir>,
}
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 {

View file

@ -31,7 +31,7 @@ pub fn forge_name(n: u32) -> ForgeName {
pub fn repo_details(
n: u32,
forge: ForgeDetails,
config: Option<RepoConfig>,
repo_config: Option<RepoConfig>,
gitdir: Option<GitDir>,
) -> 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}"),

View file

@ -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,
);