create branch

This commit is contained in:
2022-11-23 22:17:06 +01:00
parent 18ec10914b
commit 6e13263009
9 changed files with 126 additions and 37 deletions

View File

@@ -1,8 +1,9 @@
use std::path::PathBuf;
use std::{path::PathBuf, sync::Arc};
use clap::{Arg, ArgAction, ArgMatches, Command};
use octopush_core::schema;
use octopush_infra::service_register::ServiceRegister;
use tokio::sync::Mutex;
pub fn execute_cmd() -> Command {
Command::new("execute")
@@ -36,29 +37,49 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
schema::models::Schema::Action {
name,
select,
actions,
action,
} => {
tracing::debug!(name, "running action");
tracing::info!("fetching repos");
let mut repo_clones = Vec::with_capacity(select.repositories.len());
for repo in select.repositories {
let gp = service_register.git_provider.clone();
repo_clones.push(tokio::spawn(async move { gp.clone_from_url(repo).await }));
}
let mut paths = Vec::new();
for repo_clone in repo_clones {
let path = repo_clone.await??;
paths.push(path);
if let Some(git) = select.git.clone() {
let mut repo_clones = Vec::with_capacity(git.repositories.len());
for repo in git.repositories {
let gp = service_register.git_provider.clone();
repo_clones.push(tokio::spawn(async move { gp.clone_from_url(repo).await }));
}
for repo_clone in repo_clones {
let path = repo_clone.await??;
paths.push(path);
}
}
for path in paths {
for action in actions.clone() {
service_register
.executor
.execute(path.clone(), action_path.clone(), action)
.await?;
for (path, repo) in paths {
let repo = Arc::new(Mutex::new(repo));
if let Some(git) = select.git.clone() {
if let Some(push) = git.push {
service_register
.git_provider
.create_branch(repo.clone(), &push.branch)
.await?;
}
}
service_register
.executor
.execute(path.clone(), action_path.clone(), action.clone())
.await?;
if let Some(git) = select.git.clone() {
if let Some(push) = git.push {
service_register
.git_provider
.push_branch(repo, &push.branch)
.await?;
}
}
}
}