Compare commits
No commits in common. "0622e6092bf05da949903c6c6159e3fd67b099aa" and "eca45d02384b92c5da7b3293b606cee2b431cae3" have entirely different histories.
0622e6092b
...
eca45d0238
1 changed files with 25 additions and 54 deletions
|
@ -1,15 +1,9 @@
|
|||
use actix::prelude::*;
|
||||
|
||||
use kxio::network::{self, Network};
|
||||
use kxio::network;
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
use crate::server::{
|
||||
actors::repo::ValidateRepo,
|
||||
config::{self, RepoConfig, RepoDetails},
|
||||
forge::{self, CommitHistories},
|
||||
git::Git,
|
||||
types::ResetForce,
|
||||
};
|
||||
use crate::server::{actors::repo::ValidateRepo, config, forge, git::Git, types::ResetForce};
|
||||
|
||||
use super::{RepoActor, StartMonitoring};
|
||||
|
||||
|
@ -21,8 +15,16 @@ pub async fn validate_positions(
|
|||
git: Git,
|
||||
net: network::Network,
|
||||
) {
|
||||
// Collect Commit Histories for `main`, `next` and `dev` branches
|
||||
let commit_histories = get_commit_histories(&repo_details, &config, &net).await;
|
||||
let commit_histories = 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
|
||||
}
|
||||
};
|
||||
let commit_histories = match commit_histories {
|
||||
Ok(commit_histories) => commit_histories,
|
||||
Err(err) => {
|
||||
|
@ -31,8 +33,6 @@ pub async fn validate_positions(
|
|||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Validations
|
||||
let Some(main) = commit_histories.main.first().cloned() else {
|
||||
warn!("No commits on main branch '{}'", config.branches().main());
|
||||
revalidate_positions(addr).await;
|
||||
|
@ -47,7 +47,15 @@ pub async fn validate_positions(
|
|||
let next_is_ancestor_of_dev = commit_histories.dev.iter().any(|dev| dev == &next);
|
||||
if !next_is_ancestor_of_dev {
|
||||
info!("Next is not an ancestor of dev - resetting next to main");
|
||||
reset_next_to_main(next, main, &repo_details, &config, &git);
|
||||
let reset = git.reset(
|
||||
&config.branches().next(),
|
||||
main.into(),
|
||||
ResetForce::Force(next.into()),
|
||||
&repo_details,
|
||||
);
|
||||
if let Err(err) = reset {
|
||||
warn!(?err, "Failed");
|
||||
}
|
||||
revalidate_positions(addr).await;
|
||||
return;
|
||||
}
|
||||
|
@ -59,11 +67,10 @@ pub async fn validate_positions(
|
|||
.collect::<Vec<_>>();
|
||||
if !next_commits.contains(&main) {
|
||||
warn!(
|
||||
"Main branch '{}' is not on the same commit as next branch '{}', or it's parent - resetting next to main",
|
||||
"Main branch '{}' is not on the same commit as next branch '{}', or it's parent",
|
||||
config.branches().main(),
|
||||
config.branches().next()
|
||||
);
|
||||
reset_next_to_main(next, main, &repo_details, &config, &git);
|
||||
revalidate_positions(addr).await;
|
||||
return;
|
||||
}
|
||||
|
@ -78,7 +85,7 @@ pub async fn validate_positions(
|
|||
.any(|commit| commit == &next_commits[0]);
|
||||
if !dev_has_next {
|
||||
warn!(
|
||||
"Dev branch '{}' is not based on next branch '{}' - next branch will be updated shortly",
|
||||
"Dev branch '{}' is not based on next branch '{}'",
|
||||
config.branches().dev(),
|
||||
config.branches().next()
|
||||
);
|
||||
|
@ -88,10 +95,9 @@ pub async fn validate_positions(
|
|||
let dev_has_main = commit_histories.dev.iter().any(|commit| commit == &main);
|
||||
if !dev_has_main {
|
||||
warn!(
|
||||
"Dev branch '{}' is not based on main branch '{}' - user should rebase onto main branch '{}'",
|
||||
"Dev branch '{}' is not based on main branch '{}'",
|
||||
config.branches().dev(),
|
||||
config.branches().main(),
|
||||
config.branches().main(),
|
||||
config.branches().main()
|
||||
);
|
||||
revalidate_positions(addr).await;
|
||||
return;
|
||||
|
@ -109,41 +115,6 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn reset_next_to_main(
|
||||
next: forge::Commit,
|
||||
main: forge::Commit,
|
||||
repo_details: &RepoDetails,
|
||||
repo_config: &RepoConfig,
|
||||
git: &Git,
|
||||
) {
|
||||
let reset = git.reset(
|
||||
&repo_config.branches().next(),
|
||||
main.into(),
|
||||
ResetForce::Force(next.into()),
|
||||
repo_details,
|
||||
);
|
||||
if let Err(err) = reset {
|
||||
warn!(?err, "Failed");
|
||||
}
|
||||
}
|
||||
|
||||
async fn revalidate_positions(addr: Addr<RepoActor>) {
|
||||
// TODO : (#18) sleep and restart while we don't have webhooks
|
||||
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
|
||||
|
|
Loading…
Reference in a new issue