use crate::config::global::BGitGlobalConfig;
use crate::config::local::{StepFlags, WorkflowRules};
use crate::events::AtomicEvent;
use crate::events::git_pull::GitPull;
use crate::events::git_push::GitPush;
use crate::rules::Rule;
use crate::rules::a14_big_repo_size::IsRepoSizeTooBig;
use crate::rules::a18_remote_exists::RemoteExists;
use crate::step::PromptStep;
use crate::{bgit_error::BGitError, step::Step};
pub(crate) struct PullAndPush {
name: String,
}
impl PromptStep for PullAndPush {
fn new() -> Self
where
Self: Sized,
{
PullAndPush {
name: "pull_and_push".to_owned(),
}
}
fn get_name(&self) -> &str {
&self.name
}
fn execute(
&self,
_step_config_flags: Option<&StepFlags>,
workflow_rules_config: Option<&WorkflowRules>,
global_config: &BGitGlobalConfig,
) -> Result<Step, Box<BGitError>> {
let mut git_pull = GitPull::new(global_config).with_rebase(true);
git_pull.add_pre_check_rule(Box::new(RemoteExists::new(workflow_rules_config)));
match git_pull.execute() {
Ok(_) => {
let mut git_push = GitPush::new(global_config);
git_push.add_pre_check_rule(Box::new(RemoteExists::new(workflow_rules_config)));
git_push.add_pre_check_rule(Box::new(IsRepoSizeTooBig::new(workflow_rules_config)));
git_push
.with_force_with_lease(false)
.with_upstream_flag(false);
match git_push.execute() {
Ok(_) => Ok(Step::Stop),
Err(e) => {
Err(e)
}
}
}
Err(e) => {
Err(e)
}
}
}
}