Repository navigation
chore: run global git pre-commits with husky - #4660
Conversation
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughIntroduces a conditional pre-step in the Husky pre-commit hook to execute a global gitleaks hook at Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer (git commit)
participant Git as Git
participant Husky as .husky/pre-commit
participant GL as Global gitleaks hook
participant Steps as Existing pre-commit steps
Dev->>Git: git commit
Git->>Husky: Invoke pre-commit
Note over Husky: New conditional pre-step
alt Global gitleaks exists and is executable
Husky->>GL: Execute $HOME/.git-hooks/pre-commit.d/gitleaks
GL-->>Husky: Exit (0 / non-zero)
opt Non-zero exit
Husky-->>Git: Fail pre-commit
Git-->>Dev: Abort commit
end
else Missing or non-executable
Note over Husky: Skip gitleaks (prints message and exits)
end
Husky->>Steps: Run existing logic (unchanged)
Steps-->>Husky: Exit
Husky-->>Git: Return status
Git-->>Dev: Commit proceeds or aborts
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Suggestion: consider making the global hook path configurable (env var) and add a brief unit/integration test or CI check to validate the hook's behavior. Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4660 +/- ##
========================================
Coverage 91.78% 91.78%
========================================
Files 642 642
Lines 33974 33974
Branches 8037 8034 -3
========================================
Hits 31184 31184
Misses 2560 2560
Partials 230 230 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.husky/pre-commit (1)
2-5: Option: respect core.hooksPath and run all global pre-commit.d hooksIf the goal is to run “global pre-commit hooks” (plural), consider discovering the global hooks directory (core.hooksPath) and executing all executables in pre-commit.d, not just gitleaks. This avoids hardcoding $HOME and supports multiple global hooks.
Alternative drop-in refactor:
-# run global hook if exists -if [ -x "$HOME/.git-hooks/pre-commit.d/gitleaks" ]; then - if ! "$HOME/.git-hooks/pre-commit.d/gitleaks"; then - printf 'Global gitleaks pre-commit hook failed. Aborting commit.\n' >&2 - exit 1 - fi -fi +# run global pre-commit.d hooks if present +global_hooks_root="${RUDDER_GLOBAL_HOOKS_PATH:-$(git config --global core.hooksPath 2>/dev/null || echo "$HOME/.git-hooks")}" +precommit_d="$global_hooks_root/pre-commit.d" +if [ -d "$precommit_d" ]; then + for hook in "$precommit_d"/*; do + [ -x "$hook" ] || continue + printf 'Running global hook: %s\n' "$(basename "$hook")" + if ! "$hook"; then + printf 'Global hook failed: %s. Aborting commit.\n' "$hook" >&2 + exit 1 + fi + done +fiPlease confirm whether the intent is to run only gitleaks or all global hooks.
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
Husky overrides globally configured git pre-commit hooks. Secret scanning global pre-commit hooks will not run because of this. We are forcing husky to run this in this PR. This is only a temporary solution. Ideal scenario is to completely avoid using husky as we want to avoid running npm lifecycle scripts as well which husky relies on.
What is the related Linear task?
Resolves INT-4168
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.