Skip to content

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

Open
DurgaPrasad-54 wants to merge 4 commits intoPSMRI:mainfrom
DurgaPrasad-54:feat/commitlint-setup
Open

feat(githooks): add commitlint, husky and commitizen setup#40
DurgaPrasad-54 wants to merge 4 commits intoPSMRI:mainfrom
DurgaPrasad-54:feat/commitlint-setup

Conversation

@DurgaPrasad-54
Copy link
Copy Markdown
Contributor

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

📋 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
    • Enforced conventional commit message validation across the project
    • Added automated commit-lint checks on pull requests
    • Installed local commit tooling and commit-msg hooks to block invalid commits
    • Added project manifest with commit-related scripts and dev tooling
    • Added ignore rule to exclude node_modules from version control
    • Introduced basic linter configuration scaffolding

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Adds commit message validation: commitlint config, Husky commit-msg hook, GitHub Actions workflow to lint PR commits (computes merge-base and runs commitlint from base→head), project package.json with commit tooling, ESLint config, and a .gitignore entry for node_modules.

Changes

Cohort / File(s) Summary
CI Workflow
.github/workflows/commit-lint.yml
New GitHub Actions workflow "Lint Commit Messages" triggered on PR open/synchronize/reopen; checks out repo with fetch-depth: 0, sets up Node.js (v18), installs deps (npm install --legacy-peer-deps), fetches base branch, computes merge-base, and runs npx commitlint --from "$FROM" --to ${{ github.event.pull_request.head.sha }} --verbose.
Commit Lint Configuration
commitlint.config.js
New commitlint config extending @commitlint/config-conventional with rules for header/body/footer lengths, subject-case/emptiness/full-stop, type-case/type-empty and a restricted type-enum list.
Local Hook
.husky/commit-msg
Adds Husky commit-msg hook running npx --no -- commitlint --edit $1 to validate commit messages locally.
Project Manifest & Tooling
package.json
New root package.json adding devDependencies for commit tooling (@commitlint/cli, @commitlint/config-conventional, commitizen, cz-conventional-changelog, husky), scripts (test, commit, prepare), and Commitizen config.
Linting Config
eslint.config.js
Adds basic ESLint config exporting ignore patterns (node_modules/**, dist/**) and a placeholder config for **/*.{js,ts} with empty rules.
Ignore File
.gitignore
Adds entry to ignore node_modules/.

Sequence Diagram(s)

sequenceDiagram
  participant PR as Pull Request
  participant GH as GitHub Actions
  participant Runner as Runner
  participant Node as Node.js (18)
  participant NPM as npm
  participant Commitlint as commitlint

  PR->>GH: PR opened/synchronized/reopened
  GH->>Runner: checkout repo (fetch-depth: 0)
  GH->>Runner: fetch base branch, compute merge-base (FROM)
  GH->>Runner: setup Node.js (v18)
  Runner->>NPM: run `npm install --legacy-peer-deps`
  Runner->>Commitlint: run `npx commitlint --from "$FROM" --to <headSHA> --verbose`
  Commitlint-->>GH: report results/logs
  GH-->>PR: annotate PR with pass/fail
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰
I hop through diffs with tidy paws and cheer,
Linting each message so the history's clear.
Husky guards the gate, Actions runs the test,
Conventional carrots make commits the best,
A little hop — and every log is dear! 🥕

🚥 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 PR title clearly and specifically describes the main change: introducing commit message linting and automation tooling (commitlint, husky, commitizen).
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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

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

2-18: Consider marking this tooling manifest as private.

If this package.json only exists to drive local commit tooling in a git-submodule repo, adding "private": true would reduce accidental npm publish risk from the new package metadata.

Suggested fix
 {
   "name": "common-ui",
+  "private": true,
   "version": "1.0.0",
Based on learnings: The Common-UI repository is designed to be used as a git submodule in other AMRIT applications.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` around lines 2 - 18, The package manifest for "common-ui"
should be marked private to prevent accidental npm publishes; update
package.json by adding the "private": true field at the top-level (alongside
"name", "version", "description", etc.) so the package is non-publishable;
ensure the entry is a boolean true and placed at root of the JSON object
(affecting the existing keys like "name": "common-ui" and "scripts") without
changing other fields.

9-9: Use the Husky v9 prepare command form.

The current Husky setup docs recommend running husky from prepare; keeping husky install here carries forward the older setup path instead of the current v9 one. (typicode.github.io)

Suggested fix
-    "prepare": "husky install"
+    "prepare": "husky"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 9, The package.json prepare script currently uses the
older invocation "husky install"; update the "prepare" script in package.json to
the Husky v9 recommended form by replacing that value with the v9 invocation
(run the `husky` command recommended by the v9 docs) so the "prepare" script
uses the current Husky v9 command rather than the legacy form.
🤖 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 20-23: The workflow currently pins the setup action to use Node.js
18 via "uses: actions/setup-node@v4" with "node-version: 18"; update the pinned
runtime to a supported LTS (e.g., change "node-version: 18" to "node-version:
20" or "node-version: '20.x'" or use "node-version: 'lts/*'") so the new CI
workflow does not rely on an EOL Node.js release and the actions/setup-node
usage remains the same.

In `@commitlint.config.js`:
- Around line 4-7: The rules 'body-leading-blank' and 'footer-leading-blank' are
currently set with severity 1 (warnings) so they won't block commits; update
their rule entries in commitlint.config.js to use severity 2 by changing
'body-leading-blank': [1, 'always'] and 'footer-leading-blank': [1, 'always'] to
'body-leading-blank': [2, 'always'] and 'footer-leading-blank': [2, 'always'] so
commitlint treats them as errors and fails the commit when violated.

In `@package.json`:
- Around line 6-10: The package.json currently defines a "test" npm script that
always exits with code 1 causing CI/bootstrap steps to fail; update the "test"
script (the "test" key in the scripts object) to a non-failing placeholder such
as a no-op or informative echo (for example: echo "No tests" && exit 0) or
remove the failing script entirely so running npm test does not return a failure
during installs and CI runs.

---

Nitpick comments:
In `@package.json`:
- Around line 2-18: The package manifest for "common-ui" should be marked
private to prevent accidental npm publishes; update package.json by adding the
"private": true field at the top-level (alongside "name", "version",
"description", etc.) so the package is non-publishable; ensure the entry is a
boolean true and placed at root of the JSON object (affecting the existing keys
like "name": "common-ui" and "scripts") without changing other fields.
- Line 9: The package.json prepare script currently uses the older invocation
"husky install"; update the "prepare" script in package.json to the Husky v9
recommended form by replacing that value with the v9 invocation (run the `husky`
command recommended by the v9 docs) so the "prepare" script uses the current
Husky v9 command rather than the legacy form.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2df0e42-ef7d-474b-a9ee-969fcf398565

📥 Commits

Reviewing files that changed from the base of the PR and between ad89e1e and 2357a86.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • .github/workflows/commit-lint.yml
  • .gitignore
  • .husky/commit-msg
  • commitlint.config.js
  • package.json

Comment thread .github/workflows/commit-lint.yml
Comment thread commitlint.config.js Outdated
Comment thread package.json
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
commitlint.config.js (1)

36-36: Minor: Inconsistent indentation on closing brace.

The closing brace uses 2-space indent while the rest of the object body uses 4-space indent. Consider aligning for consistency.

✏️ Suggested fix
-  };
+};

Note on pipeline failure: The ESLint failure is unrelated to this file's content — the CI workflow attempts to lint JS files but the project lacks an ESLint configuration. If commit linting is the only JavaScript tooling intended, consider either adding a minimal .eslintrc or updating the CI workflow to exclude commitlint config files from ESLint checks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@commitlint.config.js` at line 36, The closing brace and semicolon at the end
of the exported config object in commitlint.config.js are indented with 2
spaces, causing inconsistent indentation; change the closing token "};" (the end
of the module.exports object) to use 4-space indentation to match the rest of
the object's body so the file's indentation is consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@commitlint.config.js`:
- Line 36: The closing brace and semicolon at the end of the exported config
object in commitlint.config.js are indented with 2 spaces, causing inconsistent
indentation; change the closing token "};" (the end of the module.exports
object) to use 4-space indentation to match the rest of the object's body so the
file's indentation is consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0b40ad9-7017-499e-93ac-81cd87142a4d

📥 Commits

Reviewing files that changed from the base of the PR and between 2357a86 and 9d6456d.

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

@DurgaPrasad-54
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
eslint.config.js (2)

7-7: Empty rules object means no linting rules are enforced.

With rules: {}, ESLint will only validate syntax without enforcing any code quality rules. If this is intentional for a minimal setup, consider adding a comment to clarify the intent. Otherwise, consider extending a recommended configuration.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eslint.config.js` at line 7, The ESLint config currently has an empty rules
object (rules: {}) which disables all linting rules; update eslint.config.js to
either populate the rules with at least a baseline (e.g., extend
"eslint:recommended" or add a minimal ruleset) or, if intentionally empty, add a
clear comment above the rules property explaining the intent (e.g.,
"Intentionally empty to only validate syntax") so reviewers know this is
deliberate; locate the rules: {} entry in eslint.config.js and apply one of
these fixes.

5-8: Add TypeScript parser configuration to eslint.config.js.

The config targets .ts files but doesn't configure the TypeScript parser. While @typescript-eslint/parser and @typescript-eslint/eslint-plugin are already in devDependencies, the eslint.config.js doesn't reference them. ESLint will fail to parse TypeScript-specific syntax without this configuration.

♻️ Proposed configuration update
+const tseslint = require('@typescript-eslint/eslint-plugin');
+const tsParser = require('@typescript-eslint/parser');
+
 module.exports = [
   {
     ignores: ['node_modules/**', 'dist/**'],
   },
   {
     files: ['**/*.{js,ts}'],
+    languageOptions: {
+      parser: tsParser,
+    },
+    plugins: {
+      '@typescript-eslint': tseslint,
+    },
     rules: {},
   },
 ];

Alternatively, if TypeScript linting isn't intended, limit the file scope to JavaScript:

-    files: ['**/*.{js,ts}'],
+    files: ['**/*.js'],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eslint.config.js` around lines 5 - 8, The ESLint config currently lists
files: ['**/*.{js,ts}'] but doesn't set a TypeScript parser or plugin, so add
TypeScript parsing by updating eslint.config.js to set languageOptions.parser to
'@typescript-eslint/parser', include '@typescript-eslint' in
languageOptions.plugins, and add the recommended TypeScript configs (e.g.,
extend '@typescript-eslint/recommended' or set parserOptions.project if using
type-aware rules) so .ts files parse correctly; alternatively, if you don't want
TypeScript linting, narrow the files pattern to only js (remove .ts from files:
['**/*.js']) and keep rules as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@eslint.config.js`:
- Line 7: The ESLint config currently has an empty rules object (rules: {})
which disables all linting rules; update eslint.config.js to either populate the
rules with at least a baseline (e.g., extend "eslint:recommended" or add a
minimal ruleset) or, if intentionally empty, add a clear comment above the rules
property explaining the intent (e.g., "Intentionally empty to only validate
syntax") so reviewers know this is deliberate; locate the rules: {} entry in
eslint.config.js and apply one of these fixes.
- Around line 5-8: The ESLint config currently lists files: ['**/*.{js,ts}'] but
doesn't set a TypeScript parser or plugin, so add TypeScript parsing by updating
eslint.config.js to set languageOptions.parser to '@typescript-eslint/parser',
include '@typescript-eslint' in languageOptions.plugins, and add the recommended
TypeScript configs (e.g., extend '@typescript-eslint/recommended' or set
parserOptions.project if using type-aware rules) so .ts files parse correctly;
alternatively, if you don't want TypeScript linting, narrow the files pattern to
only js (remove .ts from files: ['**/*.js']) and keep rules as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aaba3a58-590f-4d42-92a4-23b51281bc41

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6456d and edca101.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .github/workflows/commit-lint.yml
  • eslint.config.js
  • package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/commit-lint.yml
  • package.json

@sonarqubecloud
Copy link
Copy Markdown

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