Skip to content

chore: run global git pre-commits with husky - #4660

Merged
krishna2020 merged 2 commits into
developfrom
chore.run-global-pre-commit-hook
Sep 22, 2025
Merged

krishna2020 merged 2 commits into
developfrom
chore.run-global-pre-commit-hook

Conversation

@vinayteki95

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Automatic secret scanning runs on each commit using gitleaks and blocks commits when leaks are detected.
  • Chores
    • Integrates a global pre-commit check that executes gitleaks first and aborts with a clear message on failure.
    • Provides informative output if the secret-scanning hook isn’t executable.
    • Maintains existing pre-commit behaviors (change detection, test generation, diff checks, and npm scripts) without modification.

Summary by CodeRabbit

  • Chores
    • Updated pre-commit workflow to invoke an optional global hook if present, ensuring it runs before existing checks.
    • No changes to existing local checks or commands executed by the pre-commit process.
    • No user-facing impact; application behavior remains unchanged outside development workflows.

Walkthrough

Introduces a conditional pre-step in the Husky pre-commit hook to execute a global gitleaks hook at $HOME/.git-hooks/pre-commit.d/gitleaks if it exists and is executable; all existing pre-commit steps remain unchanged.

Changes

Cohort / File(s) Change Summary
Husky pre-commit hook
\.husky/pre-commit
Adds a conditional check and execution of $HOME/.git-hooks/pre-commit.d/gitleaks before existing steps; no modifications to changed sources detection, test generation, diff status checks, or npm pre-commit invocation.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • krishna2020

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)
Check name Status Explanation
Title Check ✅ Passed The PR title "chore: run global git pre-commits with husky" concisely and accurately summarizes the primary change (forcing Husky to execute global pre-commit hooks) and is directly related to the modification in .husky/pre-commit. It is specific, readable, and appropriate for a chore-type commit.
Description Check ✅ Passed The PR description follows the repository template by explaining the change, stating the Linear task (INT-4168), outlining objectives and the temporary nature of the fix, and including the developer/reviewer checklist; it therefore covers the main required sections and intent of the change. Several non-critical fields are marked N/A and the developer checklist items are unchecked, but the description is still sufficiently informative to understand what and why.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore.run-global-pre-commit-hook

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fde945f and f8c82f4.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .husky/pre-commit
⏰ 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)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (bde0785) to head (f8c82f4).
⚠️ Report is 14 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vinayteki95
vinayteki95 marked this pull request as ready for review September 22, 2025 10:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
.husky/pre-commit (1)

2-5: Option: respect core.hooksPath and run all global pre-commit.d hooks

If 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
+fi

Please confirm whether the intent is to run only gitleaks or all global hooks.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff66dbf and fde945f.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)

Comment thread .husky/pre-commit Resolved
Comment thread .husky/pre-commit Resolved
krishna2020
krishna2020 previously approved these changes Sep 22, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@krishna2020
krishna2020 merged commit 4c88811 into develop Sep 22, 2025
@krishna2020
krishna2020 deleted the chore.run-global-pre-commit-hook branch September 22, 2025 13:44
@coderabbitai coderabbitai Bot mentioned this pull request Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants