Compare commits

..

2 commits

Author SHA1 Message Date
9e37c073c2 refactor(repo_actor): consitent use of config crate
All checks were successful
Rust / build (push) Successful in 1m17s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-23 17:56:47 +01:00
17b1629cdf refactor(repo_actor): merge config and load modules
All checks were successful
Rust / build (push) Successful in 2m39s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-05-23 17:53:36 +01:00
4 changed files with 32 additions and 36 deletions

View file

@ -2,7 +2,7 @@ use std::time::Duration;
use actix::prelude::*;
use git_next_config::RepoConfig;
use git_next_config as config;
use git_next_forge as forge;
use git_next_git as git;
use tracing::{info, warn};
@ -14,7 +14,7 @@ use crate::{MessageToken, ValidateRepo};
pub async fn advance_next(
next: git::Commit,
dev_commit_history: Vec<git::Commit>,
repo_config: RepoConfig,
repo_config: config::RepoConfig,
forge: forge::Forge,
repository: git::OpenRepository,
addr: Addr<super::RepoActor>,
@ -78,7 +78,7 @@ pub fn find_next_commit_on_dev(
#[tracing::instrument(fields(next), skip_all)]
pub async fn advance_main(
next: git::Commit,
repo_config: &RepoConfig,
repo_config: &config::RepoConfig,
forge: &forge::Forge,
repository: &git::OpenRepository,
) {

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;
pub mod config;
mod load;
pub mod status;
pub mod webhook;
@ -11,6 +10,8 @@ use std::time::Duration;
use actix::prelude::*;
use crate as repo_actor;
use git_next_config as config;
use git_next_forge as forge;
use git_next_git as git;
@ -23,7 +24,7 @@ pub struct RepoActor {
generation: git::Generation,
message_token: MessageToken,
details: git::RepoDetails,
webhook: git_next_config::server::Webhook,
webhook: config::server::Webhook,
webhook_id: Option<webhook::WebhookId>, // INFO: if [None] then no webhook is configured
webhook_auth: Option<webhook::WebhookAuth>, // INFO: if [None] then no webhook is configured
last_main_commit: Option<git::Commit>,
@ -36,17 +37,17 @@ pub struct RepoActor {
impl RepoActor {
pub fn new(
details: git::RepoDetails,
webhook: git_next_config::server::Webhook,
webhook: config::server::Webhook,
generation: git::Generation,
net: Network,
repo: git::Repository,
) -> Self {
let forge = match details.forge.forge_type() {
#[cfg(feature = "forgejo")]
git_next_config::ForgeType::ForgeJo => {
config::ForgeType::ForgeJo => {
forge::Forge::new_forgejo(details.clone(), net.clone(), repo)
}
git_next_config::ForgeType::MockForge => forge::Forge::new_mock(),
config::ForgeType::MockForge => forge::Forge::new_mock(),
};
debug!(?forge, "new");
Self {
@ -120,7 +121,7 @@ impl Handler<LoadConfigFromRepo> for RepoActor {
let details = self.details.clone();
let addr = ctx.address();
let forge = self.forge.clone();
config::load(details, addr, forge)
repo_actor::load::load_file(details, addr, forge)
.in_current_span()
.into_actor(self)
.wait(ctx);

View file

@ -1,10 +1,30 @@
//
use actix::prelude::*;
use tracing::{error, info};
use git_next_config as config;
use git_next_forge as forge;
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,
forge: &forge::Forge,
) -> Result<config::RepoConfig, Error> {