refactor(repo/branch): extract get_commit_histories
This commit is contained in:
parent
eca45d0238
commit
2055421067
1 changed files with 29 additions and 12 deletions
|
@ -1,9 +1,15 @@
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
|
|
||||||
use kxio::network;
|
use kxio::network::{self, Network};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use crate::server::{actors::repo::ValidateRepo, config, forge, git::Git, types::ResetForce};
|
use crate::server::{
|
||||||
|
actors::repo::ValidateRepo,
|
||||||
|
config::{self, RepoConfig, RepoDetails},
|
||||||
|
forge::{self, CommitHistories},
|
||||||
|
git::Git,
|
||||||
|
types::ResetForce,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{RepoActor, StartMonitoring};
|
use super::{RepoActor, StartMonitoring};
|
||||||
|
|
||||||
|
@ -15,16 +21,8 @@ pub async fn validate_positions(
|
||||||
git: Git,
|
git: Git,
|
||||||
net: network::Network,
|
net: network::Network,
|
||||||
) {
|
) {
|
||||||
let commit_histories = match repo_details.forge.forge_type {
|
// Collect Commit Histories for `main`, `next` and `dev` branches
|
||||||
#[cfg(feature = "forgejo")]
|
let commit_histories = get_commit_histories(&repo_details, &config, &net).await;
|
||||||
config::ForgeType::ForgeJo => {
|
|
||||||
forge::forgejo::get_commit_histories(&repo_details, &config, &net).await
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
|
||||||
config::ForgeType::MockForge => {
|
|
||||||
forge::mock::get_commit_histories(&repo_details, &config, &net).await
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let commit_histories = match commit_histories {
|
let commit_histories = match commit_histories {
|
||||||
Ok(commit_histories) => commit_histories,
|
Ok(commit_histories) => commit_histories,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -33,6 +31,8 @@ pub async fn validate_positions(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Validations
|
||||||
let Some(main) = commit_histories.main.first().cloned() else {
|
let Some(main) = commit_histories.main.first().cloned() else {
|
||||||
warn!("No commits on main branch '{}'", config.branches().main());
|
warn!("No commits on main branch '{}'", config.branches().main());
|
||||||
revalidate_positions(addr).await;
|
revalidate_positions(addr).await;
|
||||||
|
@ -115,6 +115,23 @@ pub async fn validate_positions(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_commit_histories(
|
||||||
|
repo_details: &RepoDetails,
|
||||||
|
config: &RepoConfig,
|
||||||
|
net: &Network,
|
||||||
|
) -> Result<CommitHistories, network::NetworkError> {
|
||||||
|
match repo_details.forge.forge_type {
|
||||||
|
#[cfg(feature = "forgejo")]
|
||||||
|
config::ForgeType::ForgeJo => {
|
||||||
|
forge::forgejo::get_commit_histories(repo_details, config, net).await
|
||||||
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
config::ForgeType::MockForge => {
|
||||||
|
forge::mock::get_commit_histories(repo_details, config, net).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn revalidate_positions(addr: Addr<RepoActor>) {
|
async fn revalidate_positions(addr: Addr<RepoActor>) {
|
||||||
// TODO : (#18) sleep and restart while we don't have webhooks
|
// TODO : (#18) sleep and restart while we don't have webhooks
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
|
||||||
|
|
Loading…
Reference in a new issue