refactor: reuse branch::reset to advance next towards dev
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

This commit is contained in:
Paul Campbell 2024-04-11 17:58:30 +01:00
parent 6bad8a27f7
commit e0b15712c2

View file

@ -108,6 +108,7 @@ pub async fn validate_positions(
} }
// advance next to the next commit towards the head of the dev branch // advance next to the next commit towards the head of the dev branch
#[tracing::instrument(fields(next), skip_all)]
pub async fn advance_next( pub async fn advance_next(
next: forge::Commit, next: forge::Commit,
dev_commit_history: Vec<forge::Commit>, dev_commit_history: Vec<forge::Commit>,
@ -115,38 +116,23 @@ pub async fn advance_next(
repo_config: config::RepoConfig, repo_config: config::RepoConfig,
addr: Addr<RepoActor>, addr: Addr<RepoActor>,
) { ) {
info!("Advance Next");
let user = repo_details.forge.user;
let token = repo_details.forge.token;
let hostname = repo_details.forge.hostname;
let path = repo_details.repo;
let next_commit = find_next_commit_on_dev(next, dev_commit_history); let next_commit = find_next_commit_on_dev(next, dev_commit_history);
let Some(commit) = next_commit else { let Some(commit) = next_commit else {
warn!("No commits to advance next to"); warn!("No commits to advance next to");
return; return;
}; };
let next = repo_config.branches().next(); match reset(
let command = &repo_config.branches().next(),
format!("/usr/bin/git push https://{user}:{token}@{hostname}/{path}.git {commit}:{next}"); commit,
info!("Running command: {}", command); ResetForce::Normal,
match gix::command::prepare(command) &repo_details,
.with_shell_allow_argument_splitting() ) {
.spawn() Ok(_) => {
{ info!("Success");
Ok(mut child) => {
match child.wait() {
Ok(exit_status) => {
info!(%exit_status, "Advance Next Success");
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
addr.do_send(StartRepo); addr.do_send(StartRepo);
} }
Err(err) => { Err(err) => {
warn!(?err, "Advance Next Failed (wait)") warn!(?err, "Failed")
}
};
}
Err(err) => {
warn!(?err, "Advance Next Failed (spawn)")
} }
}; };
} }
@ -166,7 +152,7 @@ fn find_next_commit_on_dev(
} }
// advance main branch to the commit 'next' // advance main branch to the commit 'next'
#[tracing::instrument(fields(next))] #[tracing::instrument(fields(next), skip_all)]
pub async fn advance_main( pub async fn advance_main(
next: forge::Commit, next: forge::Commit,
repo_details: config::RepoDetails, repo_details: config::RepoDetails,