feat(server): Implement advancing main branch to the next commit

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' // advance main branch to the commit 'next'
#[allow(dead_code)] #[allow(dead_code)]
pub async fn advance_main( pub async fn advance_main(
_next: forge::Commit, next: forge::Commit,
_repo_details: config::RepoDetails, repo_details: config::RepoDetails,
repo_config: config::RepoConfig,
addr: Addr<RepoActor>, addr: Addr<RepoActor>,
_net: network::Network,
) { ) {
// TODO: (#19) advance main to next
info!("Advance Main"); 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)] #[cfg(test)]

View file

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