Skip to content

feat(githooks): add commitlint, husky and commitizen setup - #59

Closed
DurgaPrasad-54 wants to merge 3 commits into
PSMRI:mainfrom
DurgaPrasad-54:feat/commitlint-setup
Closed

feat(githooks): add commitlint, husky and commitizen setup#59
DurgaPrasad-54 wants to merge 3 commits into
PSMRI:mainfrom
DurgaPrasad-54:feat/commitlint-setup

Conversation

@DurgaPrasad-54

@DurgaPrasad-54 DurgaPrasad-54 commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

📋 Description

JIRA ID:

This PR introduces commit message linting and automation to enforce a standardized commit structure across the repository. It integrates Commitlint, Husky, and Commitizen to ensure contributors follow the Conventional Commits specification.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

Summary by CodeRabbit

  • Chores
    • Added git hooks to run lint-staged on commit and validate commit messages automatically.
    • Enforced conventional commit formatting via commitlint configuration and commitizen integration.
    • Added package scripts and dev tooling for consistent commit/lint workflows.
    • Added CI workflow to validate commit messages on pull requests.

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds Husky git hooks for commit-msg and pre-commit, a commitlint configuration, commit/prepare scripts and devDependencies in package.json, a lint-staged mapping, and a GitHub Actions workflow to run commitlint on pull requests.

Changes

Cohort / File(s) Summary
Husky Hooks
/.husky/commit-msg, /.husky/pre-commit
New git hook scripts: commit-msg runs commitlint on commit messages; pre-commit runs npx lint-staged to lint staged files.
Commit Linting Configuration
commitlint.config.js
Adds module.exports extending @commitlint/config-conventional with explicit rules for types, header/body/footer formatting, max lengths, subject-case, and no trailing punctuation.
Package Manifest
package.json
Adds prepare and commit scripts, config.commitizen, lint-staged mapping for src/**/*.ts, and devDependencies: @commitlint/cli, @commitlint/config-conventional, commitizen, cz-conventional-changelog, husky, lint-staged.
CI Workflow
.github/workflows/commit-lint.yml
New GitHub Actions workflow that checks commit messages across the PR commit range on PR events (opened, synchronize, reopened).

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant Git as Local Git
  participant Husky as Husky
  participant LintStaged as lint-staged
  participant Commitlint as commitlint
  participant GH as GitHub Actions

  Dev->>Git: create commit / push PR
  Git->>Husky: run pre-commit hook
  Husky->>LintStaged: run npx lint-staged
  LintStaged-->>Husky: exit status (pass/fail)
  Husky-->>Git: allow or abort commit

  Dev->>GH: open PR
  GH->>Commitlint: checkout + determine range
  GH->>Commitlint: run commitlint --from=base --to=head
  Commitlint-->>GH: report results
  GH-->>GitHub: mark check pass/fail
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 I hopped through hooks at dawn so spry,

Lint and commit checks kept trouble shy,
Pre-commit tidied staged code's song,
CI watched commits all day long,
Happy repo — hop along! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main changes: adding commitlint, husky, and commitizen setup to configure commit message linting and automation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
package.json (2)

98-98: Remove the duplicate xlsx declaration.

Line 98 re-declares xlsx even though it already exists in dependencies at Line 70. Keeping the same package in both sections with different version specs makes future upgrades ambiguous.

Suggested change
-    "xlsx": "^0.13.0",
     "@commitlint/cli": "^19.8.0",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 98, There is a duplicate dependency declaration for the
package "xlsx"; remove the redundant entry so only one "xlsx" remains (keep the
existing entry in dependencies with version "^0.13.0" and delete the second
declaration), then update lockfiles by running your package manager (npm install
or yarn install) to ensure versions are consistent.

15-15: Skip Husky installation during CI installs.

Line 15 runs on every npm install, including the PR workflow’s install step. Installing local git hooks in CI is unnecessary and can make the pipeline more brittle than it needs to be.

Suggested change
-    "prepare": "husky install",
+    "prepare": "[ -n \"$CI\" ] || husky install",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 15, The current "prepare" npm script runs husky install
on every npm install (including CI); change the script so husky is skipped in CI
by checking an environment flag before running husky. Update the "prepare"
script string (the value for the "prepare" key) to short-circuit when
HUSKY_SKIP_INSTALL or CI is set (for example: only run husky install when
HUSKY_SKIP_INSTALL != "1" and CI != "true"), or alternatively remove the global
prepare entry and run husky install only in developer setup steps (e.g., local
docs or a dev-specific script) so CI installs no git hooks. Ensure you edit the
"prepare" script in package.json (the "prepare" key) to implement this
conditional skip.
.husky/pre-commit (1)

1-1: Use the same npx --no guard here as in the commit-msg hook.

Plain npx can fall back to an on-demand install, which makes local commits depend on registry/network state. Using the same guarded form as .husky/commit-msg keeps hook execution deterministic.

Suggested change
-npx lint-staged
+npx --no -- lint-staged
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.husky/pre-commit at line 1, The pre-commit hook currently runs "npx
lint-staged" which can trigger an on-demand install; change it to the guarded
form used in the commit-msg hook (e.g., replace "npx lint-staged" with "npx
--no-install lint-staged" or the exact "--no" variant used in .husky/commit-msg)
so the hook will fail fast instead of attempting network installs; update
.husky/pre-commit accordingly and verify locally by running the hook to ensure
it behaves deterministically.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@commitlint.config.js`:
- Around line 4-7: Change the two commitlint rules 'body-leading-blank' and
'footer-leading-blank' from severity 1 to severity 2 so they become errors like
the other formatting rules; locate the rule entries named body-leading-blank and
footer-leading-blank in the commitlint config (currently set to [1, 'always'])
and update them to [2, 'always'] to ensure the commit-msg hook fails on missing
blank lines.

---

Nitpick comments:
In @.husky/pre-commit:
- Line 1: The pre-commit hook currently runs "npx lint-staged" which can trigger
an on-demand install; change it to the guarded form used in the commit-msg hook
(e.g., replace "npx lint-staged" with "npx --no-install lint-staged" or the
exact "--no" variant used in .husky/commit-msg) so the hook will fail fast
instead of attempting network installs; update .husky/pre-commit accordingly and
verify locally by running the hook to ensure it behaves deterministically.

In `@package.json`:
- Line 98: There is a duplicate dependency declaration for the package "xlsx";
remove the redundant entry so only one "xlsx" remains (keep the existing entry
in dependencies with version "^0.13.0" and delete the second declaration), then
update lockfiles by running your package manager (npm install or yarn install)
to ensure versions are consistent.
- Line 15: The current "prepare" npm script runs husky install on every npm
install (including CI); change the script so husky is skipped in CI by checking
an environment flag before running husky. Update the "prepare" script string
(the value for the "prepare" key) to short-circuit when HUSKY_SKIP_INSTALL or CI
is set (for example: only run husky install when HUSKY_SKIP_INSTALL != "1" and
CI != "true"), or alternatively remove the global prepare entry and run husky
install only in developer setup steps (e.g., local docs or a dev-specific
script) so CI installs no git hooks. Ensure you edit the "prepare" script in
package.json (the "prepare" key) to implement this conditional skip.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf84f9c8-77ed-46ec-8800-bf7933974053

📥 Commits

Reviewing files that changed from the base of the PR and between a9264ff and 61ae4b3.

📒 Files selected for processing (4)
  • .husky/commit-msg
  • .husky/pre-commit
  • commitlint.config.js
  • package.json

Comment thread commitlint.config.js Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/commit-lint.yml (1)

1-9: Declare read-only workflow permissions explicitly.

This job only needs repository read access. Without a top-level permissions block, the GITHUB_TOKEN scope depends on repo defaults, which is broader than necessary for a lint-only workflow.

🔒 Proposed change
 name: Lint Commit Messages
+
+permissions:
+  contents: read
 
 on:
   pull_request:
     types: [opened, synchronize, reopened]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/commit-lint.yml around lines 1 - 9, The workflow grants
default GITHUB_TOKEN scopes; add a top-level permissions block to restrict token
to read-only repository access for this lint-only job: insert a top-level
"permissions" mapping with "contents: read" (applies to the entire workflow) so
the "Lint Commit Messages" workflow and the "commitlint" job run with minimal
repo read privileges and no broader write permissions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/commit-lint.yml:
- Around line 12-18: The checkout step currently checks out the contributor fork
and can miss the base commit used by commitlint --from; update the "Checkout
code with submodule" step to check out the base repository at the PR head commit
(set repository to ${{ github.event.pull_request.base.repo.full_name }} and ref
to ${{ github.event.pull_request.head.sha }}) with fetch-depth: 0, and add an
explicit fetch step before running commitlint that fetches the base branch
(e.g., run: git fetch --no-tags --prune --depth=0 origin ${{
github.event.pull_request.base.ref }}) so that the base SHA referenced by
commitlint --from (github.event.pull_request.base.sha) exists locally.

---

Nitpick comments:
In @.github/workflows/commit-lint.yml:
- Around line 1-9: The workflow grants default GITHUB_TOKEN scopes; add a
top-level permissions block to restrict token to read-only repository access for
this lint-only job: insert a top-level "permissions" mapping with "contents:
read" (applies to the entire workflow) so the "Lint Commit Messages" workflow
and the "commitlint" job run with minimal repo read privileges and no broader
write permissions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8907a66b-05d2-4955-a7fd-b690c6e87ee3

📥 Commits

Reviewing files that changed from the base of the PR and between 61ae4b3 and 07f08ff.

📒 Files selected for processing (2)
  • .github/workflows/commit-lint.yml
  • commitlint.config.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • commitlint.config.js

Comment thread .github/workflows/commit-lint.yml Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
.github/workflows/commit-lint.yml (2)

8-9: Pin the job token to read-only permissions.

This workflow only needs repository reads, so declaring contents: read avoids relying on whatever the repo/org default GITHUB_TOKEN scope happens to be.

🔐 Proposed hardening
 jobs:
   commitlint:
+    permissions:
+      contents: read
     runs-on: ubuntu-latest
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/commit-lint.yml around lines 8 - 9, Update the commitlint
GitHub Actions job to restrict GITHUB_TOKEN scope by adding a permissions block
for that job (the commitlint job) and set contents: read so the job only has
repository read permissions; ensure the permissions block is placed at the job
level (under the commitlint job definition) rather than relying on repo/org
defaults.

22-23: Prefer npm ci here if the lockfile is committed.

For CI, npm ci --legacy-peer-deps is more reproducible than npm install --legacy-peer-deps and avoids resolver drift between runs.

📦 Proposed change
       - name: Install dependencies
-        run: npm install --legacy-peer-deps
+        run: npm ci --legacy-peer-deps
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/commit-lint.yml around lines 22 - 23, Replace the "Install
dependencies" step that currently runs `npm install --legacy-peer-deps` with
`npm ci --legacy-peer-deps` to ensure reproducible installs in CI; if the repo
may not always include a lockfile, add a guard/check for a committed lockfile
(package-lock.json or npm-shrinkwrap.json) or fall back to `npm install
--legacy-peer-deps` so the workflow doesn't fail when the lockfile is missing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/commit-lint.yml:
- Around line 8-9: Update the commitlint GitHub Actions job to restrict
GITHUB_TOKEN scope by adding a permissions block for that job (the commitlint
job) and set contents: read so the job only has repository read permissions;
ensure the permissions block is placed at the job level (under the commitlint
job definition) rather than relying on repo/org defaults.
- Around line 22-23: Replace the "Install dependencies" step that currently runs
`npm install --legacy-peer-deps` with `npm ci --legacy-peer-deps` to ensure
reproducible installs in CI; if the repo may not always include a lockfile, add
a guard/check for a committed lockfile (package-lock.json or
npm-shrinkwrap.json) or fall back to `npm install --legacy-peer-deps` so the
workflow doesn't fail when the lockfile is missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 377d42d9-12c2-43fb-98ae-484c7f586518

📥 Commits

Reviewing files that changed from the base of the PR and between 07f08ff and 921f871.

📒 Files selected for processing (1)
  • .github/workflows/commit-lint.yml

@DurgaPrasad-54 DurgaPrasad-54 closed this by deleting the head repository Jun 30, 2026
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.

1 participant