From 824c41aafa7d84698533823d6e1801439bfa82f5 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 28 Sep 2023 14:45:24 -0700 Subject: [PATCH] fix: Include args when generating Git hooks. (#1081) * Pass args. * Fix hook args. * Fix format. --- crates/core/moon/src/lib.rs | 2 +- nextgen/api/src/launchpad.rs | 4 +--- nextgen/vcs-hooks/src/hooks_generator.rs | 8 ++++++-- .../hooks_generator_test__unix__links_git_hooks-2.snap | 2 +- .../hooks_generator_test__unix__links_git_hooks.snap | 2 +- .../hooks_generator_test__windows__links_git_hooks-2.snap | 2 +- .../hooks_generator_test__windows__links_git_hooks.snap | 2 +- packages/cli/CHANGELOG.md | 2 ++ 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/core/moon/src/lib.rs b/crates/core/moon/src/lib.rs index d25cf79700b..d61d95bfa23 100644 --- a/crates/core/moon/src/lib.rs +++ b/crates/core/moon/src/lib.rs @@ -44,7 +44,7 @@ pub async fn load_workspace() -> miette::Result { if !is_test_env() { if workspace.vcs.is_enabled() { if let Ok(slug) = workspace.vcs.get_repository_slug().await { - env::set_var("MOON_REPO_SLUG", slug); + env::set_var("MOONBASE_REPO_SLUG", slug); } } diff --git a/nextgen/api/src/launchpad.rs b/nextgen/api/src/launchpad.rs index 962868f2e32..726137158c5 100644 --- a/nextgen/api/src/launchpad.rs +++ b/nextgen/api/src/launchpad.rs @@ -47,9 +47,7 @@ fn create_anonymous_rid(workspace_root: &Path) -> String { format!( "{:x}", md5::compute( - env::var("MOONBASE_REPO_SLUG") - .or_else(|_| env::var("MOON_REPO_SLUG")) - .unwrap_or_else(|_| fs::file_name(workspace_root)), + env::var("MOONBASE_REPO_SLUG").unwrap_or_else(|_| fs::file_name(workspace_root)), ) ) } diff --git a/nextgen/vcs-hooks/src/hooks_generator.rs b/nextgen/vcs-hooks/src/hooks_generator.rs index 6658edce1ca..f32b13c3465 100644 --- a/nextgen/vcs-hooks/src/hooks_generator.rs +++ b/nextgen/vcs-hooks/src/hooks_generator.rs @@ -141,7 +141,7 @@ impl<'app> HooksGenerator<'app> { self.create_file( &external_path, format!( - "#!/bin/sh\n{} -NoProfile -ExecutionPolicy Bypass -File '{}'", + "#!/bin/sh\n{} -NoProfile -ExecutionPolicy Bypass -File \"{} $1 $2 $3\"", powershell_exe, external_command ), )?; @@ -151,7 +151,11 @@ impl<'app> HooksGenerator<'app> { #[cfg(not(windows))] { // pre-commit - self.create_hook_file(&external_path, &[external_command], false)?; + self.create_hook_file( + &external_path, + &[format!("{} $1 $2 $3", external_command)], + false, + )?; } } diff --git a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks-2.snap b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks-2.snap index 6a998ea9bbf..b4e01f98710 100644 --- a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks-2.snap +++ b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks-2.snap @@ -5,4 +5,4 @@ expression: "fs::read_to_string(post_push).unwrap()" #!/usr/bin/env bash set -eo pipefail -./.moon/hooks/post-push.sh +./.moon/hooks/post-push.sh $1 $2 $3 diff --git a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks.snap b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks.snap index 0da8457fbe3..75bb2333095 100644 --- a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks.snap +++ b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__unix__links_git_hooks.snap @@ -5,4 +5,4 @@ expression: "fs::read_to_string(pre_commit).unwrap()" #!/usr/bin/env bash set -eo pipefail -./.moon/hooks/pre-commit.sh +./.moon/hooks/pre-commit.sh $1 $2 $3 diff --git a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks-2.snap b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks-2.snap index d6463479eea..e125777c4c1 100644 --- a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks-2.snap +++ b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks-2.snap @@ -3,4 +3,4 @@ source: nextgen/vcs-hooks/tests/hooks_generator_test.rs expression: "out2.replace(\"powershell.exe\", \"pwsh.exe\")" --- #!/bin/sh -pwsh.exe -NoProfile -ExecutionPolicy Bypass -File '.\.moon\hooks\post-push.ps1' +pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\.moon\hooks\post-push.ps1 $1 $2 $3" diff --git a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks.snap b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks.snap index b33ba14cd3f..f788be19de6 100644 --- a/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks.snap +++ b/nextgen/vcs-hooks/tests/snapshots/hooks_generator_test__windows__links_git_hooks.snap @@ -3,4 +3,4 @@ source: nextgen/vcs-hooks/tests/hooks_generator_test.rs expression: "out1.replace(\"powershell.exe\", \"pwsh.exe\")" --- #!/bin/sh -pwsh.exe -NoProfile -ExecutionPolicy Bypass -File '.\.moon\hooks\pre-commit.ps1' +pwsh.exe -NoProfile -ExecutionPolicy Bypass -File ".\.moon\hooks\pre-commit.ps1 $1 $2 $3" diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 468b2a9c1af..4fc8ae910d1 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -15,6 +15,8 @@ #### 🐞 Fixes - Fixed an issue where non-YAML files in `.moon/tasks` would be parsed as YAML configs. +- Fixed an issue where arguments were not passed to generated Git hooks. +- Fixed an issue where moonbase would fail to sign in in CI. ## 1.14.1