From 3a761b5b21f464eac889209234d0ff4a7cdd6661 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 10 Apr 2024 17:36:08 +0100 Subject: [PATCH] feat(server): Implement advancing main branch to the next commit Closes kemitix/git-next#19 --- src/server/actors/repo/branch.rs | 35 +++++++++++++++++++++++++++----- src/server/actors/repo/mod.rs | 7 +++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/server/actors/repo/branch.rs b/src/server/actors/repo/branch.rs index 7196e620..ba3f081a 100644 --- a/src/server/actors/repo/branch.rs +++ b/src/server/actors/repo/branch.rs @@ -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, - _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)] diff --git a/src/server/actors/repo/mod.rs b/src/server/actors/repo/mod.rs index 6f64b5b6..d2e3dad4 100644 --- a/src/server/actors/repo/mod.rs +++ b/src/server/actors/repo/mod.rs @@ -143,9 +143,12 @@ impl Handler 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); }