From c00b3a97d2523df0b4d32b8ddbd5e68b4754e89d Mon Sep 17 00:00:00 2001 From: Kasper Juul Hermansen Date: Thu, 1 Dec 2022 08:14:01 +0000 Subject: [PATCH] feature/dry-run (#43) Co-authored-by: kjuulh Reviewed-on: https://git.front.kjuulh.io/kjuulh/octopush/pulls/43 --- _examples/actions/write_a_readme/octopush.yml | 24 +++++++++---------- crates/octopush_cli/src/commands/execute.rs | 10 +++++++- .../src/selectors/git_selector.rs | 2 +- .../src/selectors/gitea_selector.rs | 2 +- .../src/selectors/github_selector.rs | 2 +- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/_examples/actions/write_a_readme/octopush.yml b/_examples/actions/write_a_readme/octopush.yml index b45a24f..191ac06 100644 --- a/_examples/actions/write_a_readme/octopush.yml +++ b/_examples/actions/write_a_readme/octopush.yml @@ -1,12 +1,12 @@ apiVersion: action name: write-a-readme select: - github: - repositories: - - kjuulh/octopush-test - push: - pull-request: - name: "write a readme" + # github: + # repositories: + # - kjuulh/octopush-test + # push: + # pull-request: + # name: "write a readme" gitea: repositories: @@ -15,12 +15,12 @@ select: pull-request: name: "write a readme" - git: - repositories: - - git@git.front.kjuulh.io:kjuulh/octopush-test.git - push: - branch: - name: "write a readme" + # git: + # repositories: + # - git@git.front.kjuulh.io:kjuulh/octopush-test.git + # push: + # branch: + # name: "write a readme" action: type: go entry: "main.go" diff --git a/crates/octopush_cli/src/commands/execute.rs b/crates/octopush_cli/src/commands/execute.rs index 694b3ed..999a751 100644 --- a/crates/octopush_cli/src/commands/execute.rs +++ b/crates/octopush_cli/src/commands/execute.rs @@ -63,6 +63,7 @@ pub fn execute_cmd() -> Command { .long("dry-run") .action(ArgAction::Set) .env("OCTOPUSH_DRY_RUN") + .default_value("true") .required(false), ) } @@ -78,7 +79,14 @@ 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 dryrun: bool = args + .get_one::("dry-run") + .ok_or(eyre::anyhow!("--dry-run is required"))? + .parse()?; + + if dryrun { + tracing::info!("running in dry-run mode"); + } let service_register = ServiceRegister::new( LocalGitProviderOptions { http_auth: None }, diff --git a/crates/octopush_core/src/selectors/git_selector.rs b/crates/octopush_core/src/selectors/git_selector.rs index 3f3c290..0a6a7de 100644 --- a/crates/octopush_core/src/selectors/git_selector.rs +++ b/crates/octopush_core/src/selectors/git_selector.rs @@ -43,7 +43,7 @@ impl GitSelector { self.executor.execute(&path, action_path, action).await?; if dryrun { - return Ok(()); + continue; } if let Some(push) = &git.push { diff --git a/crates/octopush_core/src/selectors/gitea_selector.rs b/crates/octopush_core/src/selectors/gitea_selector.rs index da089d1..2071d74 100644 --- a/crates/octopush_core/src/selectors/gitea_selector.rs +++ b/crates/octopush_core/src/selectors/gitea_selector.rs @@ -49,7 +49,7 @@ impl GiteaSelector { self.executor.execute(&path, action_path, action).await?; if dryrun { - return Ok(()); + continue; } if let Some(push) = &git.push { diff --git a/crates/octopush_core/src/selectors/github_selector.rs b/crates/octopush_core/src/selectors/github_selector.rs index 6bfe1ae..af6dd26 100644 --- a/crates/octopush_core/src/selectors/github_selector.rs +++ b/crates/octopush_core/src/selectors/github_selector.rs @@ -49,7 +49,7 @@ impl GitHubSelector { self.executor.execute(&path, action_path, action).await?; if dryrun { - return Ok(()); + continue; } if let Some(push) = &git.push {