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