refactor(repo_actor): merge config and load modules

This commit is contained in:
Paul Campbell 2024-05-23 17:53:36 +01:00
parent 64cbe36dac
commit 17b1629cdf
3 changed files with 24 additions and 29 deletions

View file

@ -1,25 +0,0 @@
use actix::prelude::*;
use git_next_forge as forge;
use git_next_git as git;
use tracing::{error, info};
use crate::load;
use super::{LoadedConfig, RepoActor};
/// Loads the [RepoConfig] from the `.git-next.toml` file in the repository
#[tracing::instrument(skip_all, fields(branch = %repo_details.branch))]
pub async fn load(repo_details: git::RepoDetails, addr: Addr<RepoActor>, forge: forge::Forge) {
info!("Loading .git-next.toml from repo");
let repo_config = match load::load(&repo_details, &forge).await {
Ok(repo_config) => repo_config,
Err(err) => {
error!(?err, "Failed to load config");
return;
}
};
info!("Loaded .git-next.toml from repo");
addr.do_send(LoadedConfig(repo_config));
}

View file

@ -1,5 +1,4 @@
mod branch; mod branch;
pub mod config;
mod load; mod load;
pub mod status; pub mod status;
pub mod webhook; pub mod webhook;
@ -11,6 +10,7 @@ use std::time::Duration;
use actix::prelude::*; use actix::prelude::*;
use crate as repo_actor;
use git_next_forge as forge; use git_next_forge as forge;
use git_next_git as git; use git_next_git as git;
@ -120,7 +120,7 @@ impl Handler<LoadConfigFromRepo> for RepoActor {
let details = self.details.clone(); let details = self.details.clone();
let addr = ctx.address(); let addr = ctx.address();
let forge = self.forge.clone(); let forge = self.forge.clone();
config::load(details, addr, forge) repo_actor::load::load_file(details, addr, forge)
.in_current_span() .in_current_span()
.into_actor(self) .into_actor(self)
.wait(ctx); .wait(ctx);

View file

@ -1,10 +1,30 @@
//
use actix::prelude::*;
use tracing::{error, info};
use git_next_config as config; use git_next_config as config;
use git_next_forge as forge; use git_next_forge as forge;
use git_next_git as git; use git_next_git as git;
use tracing::error; use super::{LoadedConfig, RepoActor};
pub async fn load( /// Loads the [RepoConfig] from the `.git-next.toml` file in the repository
#[tracing::instrument(skip_all, fields(branch = %repo_details.branch))]
pub async fn load_file(repo_details: git::RepoDetails, addr: Addr<RepoActor>, forge: forge::Forge) {
info!("Loading .git-next.toml from repo");
let repo_config = match load(&repo_details, &forge).await {
Ok(repo_config) => repo_config,
Err(err) => {
error!(?err, "Failed to load config");
return;
}
};
info!("Loaded .git-next.toml from repo");
addr.do_send(LoadedConfig(repo_config));
}
async fn load(
details: &git::RepoDetails, details: &git::RepoDetails,
forge: &forge::Forge, forge: &forge::Forge,
) -> Result<config::RepoConfig, Error> { ) -> Result<config::RepoConfig, Error> {