Skip to content

chore(commitlint): add commit-msg hook and workflow validation#122

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

chore(commitlint): add commit-msg hook and workflow validation#122
DurgaPrasad-54 wants to merge 3 commits intoPSMRI:mainfrom
DurgaPrasad-54:feat/commitlint-setup

Conversation

@DurgaPrasad-54
Copy link
Contributor

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

📋 Description

JIRA ID:

Updated the commit message validation setup by defining the commit rules directly in commitlint.config.js instead of extending @commitlint/config-conventional.


✅ 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)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • Chores

    • Enforced stricter, per-commit commit message validation and renamed the CI workflow.
    • Removed local commit hooks and deleted the project package manifest and related developer tooling config.
  • Documentation

    • Reordered and simplified setup steps; removed the prior commit-hook setup and conventions.
  • Refactor

    • CI validation updated to run on a newer Node runtime and streamlined validation steps.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4432d83c-4d56-4bee-85de-7894c0916dad

📥 Commits

Reviewing files that changed from the base of the PR and between 67efbf6 and a001b47.

📒 Files selected for processing (1)
  • .git-hooks/commit-msg
🚧 Files skipped from review as they are similar to previous changes (1)
  • .git-hooks/commit-msg

📝 Walkthrough

Walkthrough

Replaces Husky hooks with a native .git-hooks/commit-msg, removes Husky commit-msg and pre-commit, deletes package.json, simplifies commitlint.config.js, updates CI to validate each PR commit individually, and updates README setup steps and hooks guidance.

Changes

Cohort / File(s) Summary
Native Git Hook
​.git-hooks/commit-msg
Adds a commit-msg hook with #!/bin/sh and set -e that invokes npx @commitlint/cli@20.4.3 --edit "$1" to validate commit messages.
Removed Husky Hooks
.husky/commit-msg, .husky/pre-commit
Deletes Husky commit-msg (previously ran commitlint) and removes npx lint-staged from pre-commit (hook emptied).
CI Workflow
.github/workflows/commit-lint.yml
Renames workflow, upgrades Node to v20, removes dependency install and submodule checkout, and replaces a single PR-wide commitlint run with a per-commit loop that extracts each commit message and runs npx @commitlint/cli@20.4.3 --edit.
Commitlint Config
commitlint.config.js
Removes the extends: ['@commitlint/config-conventional'] entry; preserves the rules block.
Project Manifest
package.json
Removes the file entirely, deleting scripts, devDependencies (commitlint, husky, lint-staged, etc.), and lint-staged configuration.
Documentation
README.md
Removes the "Setting Up Commit Hooks" section, adds a step to enable git hooks, and reorders setup instructions accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer (local)
  participant Git as Git
  participant GH as GitHub Actions Runner
  participant CL as commitlint (npx)

  Note over Dev,Git: Local commit flow (native hooks)
  Dev->>Git: git commit
  Git->>Git: run .git-hooks/commit-msg (shell + set -e)
  Git->>CL: npx `@commitlint/cli`@20.4.3 --edit <msgfile>
  CL-->>Git: pass / fail
  Git-->>Dev: commit accepted / aborted

  Note over GH,CL: PR validation flow
  GH->>Git: fetch base..head commits
  loop for each commit sha
    GH->>Git: git show --format=%B <sha>
    GH->>CL: npx `@commitlint/cli`@20.4.3 --edit <tempfile>
    CL-->>GH: pass / fail
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble hooks at dawn's first light,
Shell set strict, commit rules tight,
CI reads each message line by line,
Husky gone, new paths align. ✨

🚥 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 title accurately describes the main changes: adding a commit-msg hook and updating workflow validation for commitlint enforcement.
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

@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: 2

🧹 Nitpick comments (1)
.git-hooks/commit-msg (1)

3-3: Consider pinning the commitlint CLI version for consistency with the CI workflow.

The CI workflow uses @commitlint/cli@20.4.3 but this hook uses an unpinned version. This could lead to different validation behavior locally vs. in CI if a breaking change is released.

Proposed fix
-npx --yes `@commitlint/cli` --edit "$1"
+npx --yes `@commitlint/cli`@20.4.3 --edit "$1"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.git-hooks/commit-msg at line 3, The commit hook invokes the commitlint CLI
without a fixed version; update the invocation in .git-hooks/commit-msg so it
pins the same version used in CI (e.g., replace "@commitlint/cli" with
"@commitlint/cli@20.4.3") to ensure local and CI validation remain consistent
when running npx --yes `@commitlint/cli` --edit "$1" (update that exact command).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.git-hooks/commit-msg:
- Around line 1-3: The commit-msg hook currently runs npx but doesn't enable
errexit, so failures may be ignored; modify the .git-hooks/commit-msg script
(the shebang + the existing npx invocation) to enable strict failure handling by
adding set -e immediately after the #!/bin/sh line so that the npx --yes
`@commitlint/cli` --edit "$1" command causes the hook to exit non‑zero when
commitlint rejects a message.

In @.github/workflows/commit-lint.yml:
- Around line 20-31: Replace the piped while-subshell approach with a
non-subshell loop and ensure failures propagate and temp files are always
cleaned up: add set -eo pipefail, capture commits into a variable (commits=$(git
log --no-merges --pretty=format:"%H" "${{ github.event.pull_request.base.sha
}}..${{ github.event.pull_request.head.sha }}")), iterate with for sha in
$commits; do ... done, create tmp via mktemp, run git log -1
--pretty=format:"%B" "$sha" > "$tmp" and npx --yes `@commitlint/cli`@20.4.3 --edit
"$tmp", and remove the tmp with rm "$tmp"; also register a trap (trap 'rm -f
"$tmp"' EXIT) before the loop to guarantee cleanup if commitlint fails.

---

Nitpick comments:
In @.git-hooks/commit-msg:
- Line 3: The commit hook invokes the commitlint CLI without a fixed version;
update the invocation in .git-hooks/commit-msg so it pins the same version used
in CI (e.g., replace "@commitlint/cli" with "@commitlint/cli@20.4.3") to ensure
local and CI validation remain consistent when running npx --yes `@commitlint/cli`
--edit "$1" (update that exact command).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 014bf00f-fa18-4a04-aad4-4d6814121749

📥 Commits

Reviewing files that changed from the base of the PR and between 0683b41 and a0eedd8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .git-hooks/commit-msg
  • .github/workflows/commit-lint.yml
  • .husky/commit-msg
  • .husky/pre-commit
  • README.md
  • commitlint.config.js
  • package.json
💤 Files with no reviewable changes (3)
  • package.json
  • .husky/pre-commit
  • .husky/commit-msg

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 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.

2 participants