2024-04-09 18:18:19 +01:00
|
|
|
use tracing::{error, warn};
|
|
|
|
|
2024-04-09 16:16:01 +01:00
|
|
|
use crate::server::forge;
|
|
|
|
|
2024-04-09 18:18:19 +01:00
|
|
|
use super::StartMonitoring;
|
|
|
|
|
2024-04-09 16:16:01 +01:00
|
|
|
#[tracing::instrument(fields(forge_name = %repo_details.forge.name, repo_name = %repo_details.name))]
|
|
|
|
pub async fn validate_positions(
|
|
|
|
repo_details: crate::server::config::RepoDetails,
|
|
|
|
config: crate::server::config::RepoConfig,
|
2024-04-09 18:18:19 +01:00
|
|
|
addr: actix::prelude::Addr<super::RepoActor>,
|
2024-04-09 16:16:01 +01:00
|
|
|
net: kxio::network::Network,
|
2024-04-09 15:31:59 +01:00
|
|
|
) {
|
2024-04-09 18:18:19 +01:00
|
|
|
let commit_histories = match repo_details.forge.forge_type {
|
2024-04-09 16:16:01 +01:00
|
|
|
crate::server::config::ForgeType::ForgeJo => {
|
2024-04-09 18:18:19 +01:00
|
|
|
forge::forgejo::get_commit_histories(&repo_details, &config, &net).await
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let commit_histories = match commit_histories {
|
|
|
|
Ok(commit_histories) => commit_histories,
|
|
|
|
Err(err) => {
|
|
|
|
error!(?err, "Failed to get commit histories");
|
|
|
|
return;
|
2024-04-09 16:16:01 +01:00
|
|
|
}
|
|
|
|
};
|
2024-04-09 18:18:19 +01:00
|
|
|
|
|
|
|
let Some(main) = commit_histories.main.first().cloned() else {
|
|
|
|
warn!("No commits on main branch '{}'", config.branches().main());
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
let next_commits = commit_histories
|
|
|
|
.next
|
|
|
|
.into_iter()
|
|
|
|
.take(2)
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
if !next_commits.contains(&main) {
|
|
|
|
warn!(
|
|
|
|
"Main branch '{}' is not on the same commit as next branch '{}', or it's parent",
|
|
|
|
config.branches().main(),
|
|
|
|
config.branches().next()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let next = next_commits[0].clone();
|
|
|
|
let dev_has_next = commit_histories
|
|
|
|
.dev
|
|
|
|
.iter()
|
|
|
|
.any(|commit| commit == &next_commits[0]);
|
|
|
|
if !dev_has_next {
|
|
|
|
warn!(
|
|
|
|
"Dev branch '{}' is not based on next branch '{}'",
|
|
|
|
config.branches().dev(),
|
|
|
|
config.branches().next()
|
|
|
|
);
|
|
|
|
return; // dev is not based on next
|
|
|
|
}
|
|
|
|
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 '{}'",
|
|
|
|
config.branches().dev(),
|
|
|
|
config.branches().main()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let dev = commit_histories.dev[0].clone();
|
|
|
|
addr.do_send(StartMonitoring { main, next, dev });
|
2024-04-09 15:31:59 +01:00
|
|
|
}
|
2024-04-09 19:30:05 +01:00
|
|
|
|
|
|
|
pub async fn advance_next(
|
|
|
|
_next: forge::Commit,
|
|
|
|
_repo_details: crate::server::config::RepoDetails,
|
|
|
|
_addr: actix::prelude::Addr<super::RepoActor>,
|
|
|
|
_net: kxio::network::Network,
|
|
|
|
) {
|
|
|
|
// TODO: (#14) advance next one commit towards dev
|
|
|
|
}
|