fix(server): reduce complexity of StartMonitoring handler
Closes kemitix/git-next#25
This commit is contained in:
parent
9469d27476
commit
7dab1da44b
1 changed files with 4 additions and 13 deletions
|
@ -90,33 +90,25 @@ pub struct StartMonitoring {
|
||||||
}
|
}
|
||||||
impl Handler<StartMonitoring> for RepoActor {
|
impl Handler<StartMonitoring> for RepoActor {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
#[allow(clippy::cognitive_complexity)] // TODO: (#25) this function is complex
|
|
||||||
fn handle(&mut self, msg: StartMonitoring, ctx: &mut Self::Context) -> Self::Result {
|
fn handle(&mut self, msg: StartMonitoring, ctx: &mut Self::Context) -> Self::Result {
|
||||||
info!("Monitoring started");
|
|
||||||
let Some(repo_config) = self.config.clone() else {
|
let Some(repo_config) = self.config.clone() else {
|
||||||
warn!("No config loaded");
|
warn!("No config loaded");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let next_ahead_of_main = msg.main != msg.next;
|
||||||
|
let dev_ahead_of_next = msg.next != msg.dev;
|
||||||
|
info!(%msg.main, %msg.next, %msg.dev, next_ahead_of_main, dev_ahead_of_next, "StartMonitoring");
|
||||||
|
|
||||||
let repo_details = self.details.clone();
|
let repo_details = self.details.clone();
|
||||||
let addr = ctx.address();
|
let addr = ctx.address();
|
||||||
let net = self.net.clone();
|
let net = self.net.clone();
|
||||||
|
|
||||||
info!(%msg.main, %msg.next, %msg.dev, "Checking positions");
|
|
||||||
let next_ahead_of_main = msg.main != msg.next;
|
|
||||||
let dev_ahead_of_next = msg.next != msg.dev;
|
|
||||||
info!(
|
|
||||||
?next_ahead_of_main,
|
|
||||||
?dev_ahead_of_next,
|
|
||||||
"Checking positions"
|
|
||||||
);
|
|
||||||
if next_ahead_of_main {
|
if next_ahead_of_main {
|
||||||
info!("Next is ahead of main");
|
|
||||||
status::check_next(msg.next, repo_details, addr, net)
|
status::check_next(msg.next, repo_details, addr, net)
|
||||||
.into_actor(self)
|
.into_actor(self)
|
||||||
.wait(ctx);
|
.wait(ctx);
|
||||||
} else if dev_ahead_of_next {
|
} else if dev_ahead_of_next {
|
||||||
info!("Dev is ahead of next");
|
|
||||||
branch::advance_next(
|
branch::advance_next(
|
||||||
msg.next,
|
msg.next,
|
||||||
msg.dev_commit_history,
|
msg.dev_commit_history,
|
||||||
|
@ -127,7 +119,6 @@ impl Handler<StartMonitoring> for RepoActor {
|
||||||
.into_actor(self)
|
.into_actor(self)
|
||||||
.wait(ctx);
|
.wait(ctx);
|
||||||
} else if self.webhook_id.is_none() {
|
} else if self.webhook_id.is_none() {
|
||||||
info!("No webhook registered");
|
|
||||||
webhook::register(repo_details, addr, net)
|
webhook::register(repo_details, addr, net)
|
||||||
.into_actor(self)
|
.into_actor(self)
|
||||||
.wait(ctx)
|
.wait(ctx)
|
||||||
|
|
Loading…
Reference in a new issue