diff --git a/crates/octopush_cli/src/commands/execute.rs b/crates/octopush_cli/src/commands/execute.rs index 35c16e8..694b3ed 100644 --- a/crates/octopush_cli/src/commands/execute.rs +++ b/crates/octopush_cli/src/commands/execute.rs @@ -58,6 +58,13 @@ pub fn execute_cmd() -> Command { .env("GITHUB_USERNAME") .required(false), ) + .arg( + Arg::new("dry-run") + .long("dry-run") + .action(ArgAction::Set) + .env("OCTOPUSH_DRY_RUN") + .required(false), + ) } pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> { @@ -71,6 +78,7 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> { let github_http_token = args.get_one::("github-api-token"); let github_username = args.get_one::("github-username"); + let dryrun = args.get_one::("dry-run").unwrap_or(&false).clone(); let service_register = ServiceRegister::new( LocalGitProviderOptions { http_auth: None }, @@ -107,21 +115,21 @@ pub async fn execute_subcommand(args: &ArgMatches) -> eyre::Result<()> { if let Some(git) = &select.git { service_register .git_selector - .run(git, &action_path, &action) + .run(git, &action_path, &action, dryrun) .await?; } if let Some(gitea) = &select.gitea { service_register .gitea_selector - .run(gitea, &action_path, &action) + .run(gitea, &action_path, &action, dryrun) .await?; } if let Some(github) = &select.github { service_register .github_selector - .run(github, &action_path, &action) + .run(github, &action_path, &action, dryrun) .await?; } } diff --git a/crates/octopush_core/src/selectors/git_selector.rs b/crates/octopush_core/src/selectors/git_selector.rs index 303ac57..3f3c290 100644 --- a/crates/octopush_core/src/selectors/git_selector.rs +++ b/crates/octopush_core/src/selectors/git_selector.rs @@ -21,7 +21,13 @@ impl GitSelector { } } - pub async fn run(&self, git: &Git, action_path: &PathBuf, action: &Action) -> eyre::Result<()> { + pub async fn run( + &self, + git: &Git, + action_path: &PathBuf, + action: &Action, + dryrun: bool, + ) -> eyre::Result<()> { tracing::info!("fetching repos"); for repo in &git.repositories { let gp = self.git_provider.clone(); @@ -36,6 +42,10 @@ impl GitSelector { self.executor.execute(&path, action_path, action).await?; + if dryrun { + return Ok(()); + } + if let Some(push) = &git.push { self.git_provider .push_branch(repo, &push.branch.name) diff --git a/crates/octopush_core/src/selectors/gitea_selector.rs b/crates/octopush_core/src/selectors/gitea_selector.rs index 4b80b97..da089d1 100644 --- a/crates/octopush_core/src/selectors/gitea_selector.rs +++ b/crates/octopush_core/src/selectors/gitea_selector.rs @@ -32,6 +32,7 @@ impl GiteaSelector { git: &Gitea, action_path: &PathBuf, action: &Action, + dryrun: bool, ) -> eyre::Result<()> { tracing::info!("fetching repos"); for repo in &git.repositories { @@ -47,6 +48,10 @@ impl GiteaSelector { self.executor.execute(&path, action_path, action).await?; + if dryrun { + return Ok(()); + } + if let Some(push) = &git.push { self.git_provider .push_branch(repo, &push.pull_request.name) diff --git a/crates/octopush_core/src/selectors/github_selector.rs b/crates/octopush_core/src/selectors/github_selector.rs index 8b7efef..6bfe1ae 100644 --- a/crates/octopush_core/src/selectors/github_selector.rs +++ b/crates/octopush_core/src/selectors/github_selector.rs @@ -32,6 +32,7 @@ impl GitHubSelector { git: &GitHub, action_path: &PathBuf, action: &Action, + dryrun: bool, ) -> eyre::Result<()> { tracing::info!("fetching repos"); for repo in &git.repositories { @@ -47,6 +48,10 @@ impl GitHubSelector { self.executor.execute(&path, action_path, action).await?; + if dryrun { + return Ok(()); + } + if let Some(push) = &git.push { self.git_provider .push_branch(repo, &push.pull_request.name)