feat(server): Implement advancing main branch to the next commit
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful

Closes kemitix/git-next#19
This commit is contained in:
Paul Campbell 2024-04-10 17:36:08 +01:00
parent 98a94ea855
commit 3a761b5b21
2 changed files with 35 additions and 7 deletions

View file

@ -135,14 +135,39 @@ fn find_next_commit_on_dev(
// advance main branch to the commit 'next'
#[allow(dead_code)]
pub async fn advance_main(
_next: forge::Commit,
_repo_details: config::RepoDetails,
next: forge::Commit,
repo_details: config::RepoDetails,
repo_config: config::RepoConfig,
addr: Addr<RepoActor>,
_net: network::Network,
) {
// TODO: (#19) advance main to next
info!("Advance Main");
addr.do_send(StartRepo);
let user = repo_details.forge.user;
let token = repo_details.forge.token;
let hostname = repo_details.forge.hostname;
let path = repo_details.repo;
let main = repo_config.branches().main();
let command =
format!("/usr/bin/git push https://{user}:{token}@{hostname}/{path}.git {next}:{main}");
info!("Running command: {}", command);
match gix::command::prepare(command)
.with_shell_allow_argument_splitting()
.spawn()
{
Ok(mut child) => {
match child.wait() {
Ok(exit_status) => {
info!(%exit_status, "Advance Next Success");
addr.do_send(StartRepo);
}
Err(err) => {
warn!(?err, "Advance Next Failed (wait)")
}
};
}
Err(err) => {
warn!(?err, "Advance Next Failed (spawn)")
}
};
}
#[cfg(test)]

View file

@ -143,9 +143,12 @@ impl Handler<AdvanceMainTo> for RepoActor {
type Result = ();
fn handle(&mut self, msg: AdvanceMainTo, ctx: &mut Self::Context) -> Self::Result {
let repo_details = self.details.clone();
let Some(repo_config) = self.config.clone() else {
warn!("No config loaded");
return;
};
let addr = ctx.address();
let net = self.net.clone();
branch::advance_main(msg.0, repo_details, addr, net)
branch::advance_main(msg.0, repo_details, repo_config, addr)
.into_actor(self)
.wait(ctx);
}