extract logic from execute

This commit is contained in:
2022-11-27 11:06:24 +01:00
parent 4ec5250a8d
commit a777b1d0a4
16 changed files with 159 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
use std::{path::PathBuf, sync::Arc};
use std::path::PathBuf;
use clap::{Arg, ArgAction, ArgMatches, Command};
use octopush_core::{
@@ -6,7 +6,6 @@ use octopush_core::{
schema,
};
use octopush_infra::service_register::ServiceRegister;
use tokio::sync::Mutex;
pub fn execute_cmd() -> Command {
Command::new("execute")
@@ -18,6 +17,7 @@ pub fn execute_cmd() -> Command {
.action(ArgAction::Set)
.help("action path to your local octopush.yaml file")
.long_help("action path to your local octopush.yaml file")
.default_value(".")
.required(true),
)
.arg(
@@ -60,89 +60,18 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> {
} => {
tracing::debug!(name, "running action");
tracing::info!("fetching repos");
let mut git_paths = Vec::new();
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??;
git_paths.push(path);
}
}
let mut gitea_paths = Vec::new();
if let Some(gitea) = select.gitea.clone() {
let mut repo_clones = Vec::with_capacity(gitea.repositories.len());
for repo in gitea.repositories {
let gp = service_register.gitea_provider.clone();
repo_clones.push(tokio::spawn(async move {
gp.clone_from_qualified(repo.clone())
.await
.map(|(p, r)| (p, r, repo))
}))
}
for repo_clone in repo_clones {
let path = repo_clone.await??;
gitea_paths.push(path);
}
}
for (path, repo) in git_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.name)
.await?;
}
}
if let Some(git) = &select.git {
service_register
.executor
.execute(path.clone(), action_path.clone(), action.clone())
.git_selector
.run(git, &action_path, &action)
.await?;
if let Some(git) = select.git.clone() {
if let Some(push) = git.push {
service_register
.git_provider
.push_branch(repo, &push.branch.name)
.await?;
}
}
}
for (path, repo, repo_name) in gitea_paths {
let repo = Arc::new(Mutex::new(repo));
if let Some(gitea) = select.gitea.clone() {
if let Some(push) = gitea.push {
service_register
.gitea_provider
.create_branch(repo.clone(), &push.pull_request)
.await?;
}
}
if let Some(gitea) = &select.gitea {
service_register
.executor
.execute(path.clone(), action_path.clone(), action.clone())
.gitea_selector
.run(gitea, &action_path, &action)
.await?;
if let Some(gitea) = select.gitea.clone() {
if let Some(push) = gitea.push {
service_register
.gitea_provider
.create_pull_request(repo, &repo_name, &push.pull_request)
.await?;
}
}
}
}
}