Compare commits
2 commits
8decf941c8
...
5b9a8906d2
Author | SHA1 | Date | |
---|---|---|---|
5b9a8906d2 | |||
04f94f5aab |
5 changed files with 75 additions and 108 deletions
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
|
|
||||||
use tracing::{debug, info, instrument, Instrument as _};
|
use tracing::{debug, instrument, Instrument as _};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
repo::{
|
repo::{
|
||||||
|
@ -13,8 +13,8 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use git_next_core::git::{
|
use git_next_core::git::{
|
||||||
self,
|
|
||||||
validation::positions::{validate, Error, Positions},
|
validation::positions::{validate, Error, Positions},
|
||||||
|
UserNotification,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Handler<ValidateRepo> for RepoActor {
|
impl Handler<ValidateRepo> for RepoActor {
|
||||||
|
@ -63,26 +63,19 @@ impl Handler<ValidateRepo> for RepoActor {
|
||||||
};
|
};
|
||||||
logger(self.log.as_ref(), "have repo config");
|
logger(self.log.as_ref(), "have repo config");
|
||||||
|
|
||||||
info!("collecting git graph log");
|
match validate(&**open_repository, &self.repo_details, &repo_config) {
|
||||||
let git_log = git::graph::log(&self.repo_details);
|
Ok((
|
||||||
info!(?git_log, "collected git graph log");
|
Positions {
|
||||||
self.update_tui_log(git_log.clone());
|
main,
|
||||||
info!("sent to ui git graph log");
|
next,
|
||||||
|
dev,
|
||||||
match validate(
|
dev_commit_history,
|
||||||
&**open_repository,
|
next_is_valid,
|
||||||
&self.repo_details,
|
},
|
||||||
&repo_config,
|
git_log,
|
||||||
git_log,
|
)) => {
|
||||||
) {
|
|
||||||
Ok(Positions {
|
|
||||||
main,
|
|
||||||
next,
|
|
||||||
dev,
|
|
||||||
dev_commit_history,
|
|
||||||
next_is_valid,
|
|
||||||
}) => {
|
|
||||||
debug!(%main, %next, %dev, "positions");
|
debug!(%main, %next, %dev, "positions");
|
||||||
|
self.update_tui_log(git_log);
|
||||||
if next_is_valid && next != main {
|
if next_is_valid && next != main {
|
||||||
do_send(&ctx.address(), CheckCIStatus::new(next), self.log.as_ref());
|
do_send(&ctx.address(), CheckCIStatus::new(next), self.log.as_ref());
|
||||||
} else if next != dev {
|
} else if next != dev {
|
||||||
|
@ -118,7 +111,13 @@ impl Handler<ValidateRepo> for RepoActor {
|
||||||
.wait(ctx);
|
.wait(ctx);
|
||||||
}
|
}
|
||||||
Err(Error::UserIntervention(user_notification)) => {
|
Err(Error::UserIntervention(user_notification)) => {
|
||||||
|
// FIXME: end up here when doing git force push to leave this situation
|
||||||
self.alert_tui(format!("[USER INTERVENTION: {user_notification}]"));
|
self.alert_tui(format!("[USER INTERVENTION: {user_notification}]"));
|
||||||
|
if let UserNotification::CICheckFailed { log, .. }
|
||||||
|
| UserNotification::DevNotBasedOnMain { log, .. } = &user_notification
|
||||||
|
{
|
||||||
|
self.update_tui_log(log.clone());
|
||||||
|
}
|
||||||
notify_user(
|
notify_user(
|
||||||
self.notify_user_recipient.as_ref(),
|
self.notify_user_recipient.as_ref(),
|
||||||
user_notification,
|
user_notification,
|
||||||
|
|
|
@ -3,10 +3,7 @@ use actix::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
alerts::messages::NotifyUser,
|
alerts::messages::NotifyUser,
|
||||||
server::{
|
server::{actor::messages::RepoUpdate, ServerActor},
|
||||||
actor::messages::{RepoUpdate, ServerUpdate},
|
|
||||||
ServerActor,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use derive_more::Deref;
|
use derive_more::Deref;
|
||||||
use kxio::network::Network;
|
use kxio::network::Network;
|
||||||
|
@ -114,6 +111,7 @@ impl RepoActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
fn update_tui_log(&self, log: git::graph::Log) {
|
fn update_tui_log(&self, log: git::graph::Log) {
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
{
|
{
|
||||||
|
@ -121,6 +119,7 @@ impl RepoActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
fn alert_tui(&self, alert: impl Into<String>) {
|
fn alert_tui(&self, alert: impl Into<String>) {
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
{
|
{
|
||||||
|
@ -130,6 +129,7 @@ impl RepoActor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
fn update_tui(&self, repo_update: RepoUpdate) {
|
fn update_tui(&self, repo_update: RepoUpdate) {
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
{
|
{
|
||||||
|
@ -137,7 +137,7 @@ impl RepoActor {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let update = ServerUpdate::RepoUpdate {
|
let update = crate::server::actor::messages::ServerUpdate::RepoUpdate {
|
||||||
forge_alias: self.repo_details.forge.forge_alias().clone(),
|
forge_alias: self.repo_details.forge.forge_alias().clone(),
|
||||||
repo_alias: self.repo_details.repo_alias.clone(),
|
repo_alias: self.repo_details.repo_alias.clone(),
|
||||||
repo_update,
|
repo_update,
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use tracing::{debug, instrument};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
use crate::{
|
use crate::{
|
||||||
git::{self, repository::open::OpenRepositoryLike, RepoDetails, UserNotification},
|
git::{self, repository::open::OpenRepositoryLike, RepoDetails, UserNotification},
|
||||||
BranchName, RepoConfig,
|
BranchName, RepoConfig,
|
||||||
};
|
};
|
||||||
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
pub type Result<T> = core::result::Result<T, Error>;
|
pub type Result<T> = core::result::Result<T, Error>;
|
||||||
|
|
||||||
|
@ -29,13 +28,14 @@ pub fn validate(
|
||||||
open_repository: &dyn OpenRepositoryLike,
|
open_repository: &dyn OpenRepositoryLike,
|
||||||
repo_details: &git::RepoDetails,
|
repo_details: &git::RepoDetails,
|
||||||
repo_config: &RepoConfig,
|
repo_config: &RepoConfig,
|
||||||
log: git::graph::Log,
|
) -> Result<(Positions, git::graph::Log)> {
|
||||||
) -> Result<Positions> {
|
|
||||||
let main_branch = repo_config.branches().main();
|
let main_branch = repo_config.branches().main();
|
||||||
let next_branch = repo_config.branches().next();
|
let next_branch = repo_config.branches().next();
|
||||||
let dev_branch = repo_config.branches().dev();
|
let dev_branch = repo_config.branches().dev();
|
||||||
// Collect Commit Histories for `main`, `next` and `dev` branches
|
// Collect Commit Histories for `main`, `next` and `dev` branches
|
||||||
open_repository.fetch()?;
|
open_repository.fetch()?;
|
||||||
|
let git_log = git::graph::log(repo_details);
|
||||||
|
|
||||||
let commit_histories = get_commit_histories(open_repository, repo_config)?;
|
let commit_histories = get_commit_histories(open_repository, repo_config)?;
|
||||||
// branch tips
|
// branch tips
|
||||||
let main = commit_histories
|
let main = commit_histories
|
||||||
|
@ -64,7 +64,7 @@ pub fn validate(
|
||||||
main_branch,
|
main_branch,
|
||||||
dev_commit: dev,
|
dev_commit: dev,
|
||||||
main_commit: main,
|
main_commit: main,
|
||||||
log,
|
log: git_log,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -80,23 +80,38 @@ pub fn validate(
|
||||||
&main,
|
&main,
|
||||||
) {
|
) {
|
||||||
tracing::info!("Main not on same commit as next, or it's parent - resetting next to main",);
|
tracing::info!("Main not on same commit as next, or it's parent - resetting next to main",);
|
||||||
return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch);
|
return Err(reset_next_to_main(
|
||||||
|
open_repository,
|
||||||
|
repo_details,
|
||||||
|
&main,
|
||||||
|
&next,
|
||||||
|
&next_branch,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
// verify that next is an ancestor of dev, else reset it back to main if dev not ahead of main
|
// verify that next is an ancestor of dev, else reset it back to main if dev not ahead of main
|
||||||
if is_not_based_on(&commit_histories.dev, &next)
|
if is_not_based_on(&commit_histories.dev, &next)
|
||||||
&& commit_histories.main.first() == commit_histories.dev.first()
|
&& commit_histories.main.first() == commit_histories.dev.first()
|
||||||
{
|
{
|
||||||
tracing::info!("Next is not an ancestor of dev - resetting next to main");
|
tracing::info!("Next is not an ancestor of dev - resetting next to main");
|
||||||
return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch);
|
return Err(reset_next_to_main(
|
||||||
|
open_repository,
|
||||||
|
repo_details,
|
||||||
|
&main,
|
||||||
|
&next,
|
||||||
|
&next_branch,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let next_is_valid = is_based_on(&commit_histories.dev, &next);
|
let next_is_valid = is_based_on(&commit_histories.dev, &next);
|
||||||
Ok(git::validation::positions::Positions {
|
Ok((
|
||||||
main,
|
git::validation::positions::Positions {
|
||||||
next,
|
main,
|
||||||
dev,
|
next,
|
||||||
dev_commit_history: commit_histories.dev,
|
dev,
|
||||||
next_is_valid,
|
dev_commit_history: commit_histories.dev,
|
||||||
})
|
next_is_valid,
|
||||||
|
},
|
||||||
|
git_log,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::result_large_err)]
|
#[allow(clippy::result_large_err)]
|
||||||
|
@ -106,22 +121,20 @@ fn reset_next_to_main(
|
||||||
main: &git::Commit,
|
main: &git::Commit,
|
||||||
next: &git::Commit,
|
next: &git::Commit,
|
||||||
next_branch: &BranchName,
|
next_branch: &BranchName,
|
||||||
) -> Result<Positions> {
|
) -> Error {
|
||||||
git::push::reset(
|
if let Err(err) = git::push::reset(
|
||||||
open_repository,
|
open_repository,
|
||||||
repo_details,
|
repo_details,
|
||||||
next_branch,
|
next_branch,
|
||||||
&main.clone().into(),
|
&main.clone().into(),
|
||||||
&git::push::Force::From(next.clone().into()),
|
&git::push::Force::From(next.clone().into()),
|
||||||
)
|
) {
|
||||||
.map_err(|err| {
|
|
||||||
Error::NonRetryable(format!(
|
Error::NonRetryable(format!(
|
||||||
"Failed to reset branch '{next_branch}' to commit '{next}': {err}"
|
"Failed to reset branch '{next_branch}' to commit '{next}': {err}"
|
||||||
))
|
))
|
||||||
})?;
|
} else {
|
||||||
Err(Error::Retryable(format!(
|
Error::Retryable(format!("Branch {next_branch} has been reset"))
|
||||||
"Branch {next_branch} has been reset"
|
}
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_not_based_on(commits: &[git::commit::Commit], needle: &git::Commit) -> bool {
|
fn is_not_based_on(commits: &[git::commit::Commit], needle: &git::Commit) -> bool {
|
||||||
|
|
|
@ -75,12 +75,7 @@ mod positions {
|
||||||
);
|
);
|
||||||
let repo_config = given::a_repo_config();
|
let repo_config = given::a_repo_config();
|
||||||
|
|
||||||
let result = validate(
|
let result = validate(&*repository, &repo_details, &repo_config);
|
||||||
&*repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default(),
|
|
||||||
);
|
|
||||||
println!("{result:?}");
|
println!("{result:?}");
|
||||||
let_assert!(Err(err) = result, "validate");
|
let_assert!(Err(err) = result, "validate");
|
||||||
|
|
||||||
|
@ -120,12 +115,7 @@ mod positions {
|
||||||
"open repo"
|
"open repo"
|
||||||
);
|
);
|
||||||
|
|
||||||
let result = validate(
|
let result = validate(&*open_repository, &repo_details, &repo_config);
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default(),
|
|
||||||
);
|
|
||||||
println!("{result:?}");
|
println!("{result:?}");
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
@ -164,12 +154,7 @@ mod positions {
|
||||||
"open repo"
|
"open repo"
|
||||||
);
|
);
|
||||||
|
|
||||||
let result = validate(
|
let result = validate(&*open_repository, &repo_details, &repo_config);
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default(),
|
|
||||||
);
|
|
||||||
println!("{result:?}");
|
println!("{result:?}");
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
@ -208,12 +193,7 @@ mod positions {
|
||||||
"open repo"
|
"open repo"
|
||||||
);
|
);
|
||||||
|
|
||||||
let result = validate(
|
let result = validate(&*open_repository, &repo_details, &repo_config);
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default(),
|
|
||||||
);
|
|
||||||
println!("{result:?}");
|
println!("{result:?}");
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
@ -260,12 +240,7 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Err(err) = validate(
|
Err(err) = validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -350,12 +325,7 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Err(err) = validate(
|
Err(err) = validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -424,12 +394,7 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Err(err) = validate(
|
Err(err) = validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -516,12 +481,7 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Err(err) = validate(
|
Err(err) = validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&*open_repository,
|
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -607,12 +567,8 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(positions) = validate(
|
Ok((positions, _git_log)) =
|
||||||
&*open_repository,
|
validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -671,12 +627,8 @@ mod positions {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
let_assert!(
|
let_assert!(
|
||||||
Ok(positions) = validate(
|
Ok((positions, _git_log)) =
|
||||||
&*open_repository,
|
validate(&*open_repository, &repo_details, &repo_config),
|
||||||
&repo_details,
|
|
||||||
&repo_config,
|
|
||||||
git::graph::Log::default()
|
|
||||||
),
|
|
||||||
"validate"
|
"validate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
3
justfile
3
justfile
|
@ -21,6 +21,9 @@ start-ngrok:
|
||||||
ngrok http --domain=${NGROK_DOMAIN} 8080
|
ngrok http --domain=${NGROK_DOMAIN} 8080
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
start-mac-tunnel:
|
||||||
|
ssh dagon -R7777:localhost:8888
|
||||||
|
|
||||||
coverage-update:
|
coverage-update:
|
||||||
cargo tarpaulin --lib --out html
|
cargo tarpaulin --lib --out html
|
||||||
echo "Now:\n\topen tarpaulin-report.html"
|
echo "Now:\n\topen tarpaulin-report.html"
|
||||||
|
|
Loading…
Reference in a new issue