Skip to content

Conversation

@abhijeetw035
Copy link
Contributor

@abhijeetw035 abhijeetw035 commented Sep 25, 2025

📋 Description

JIRA ID:

GitHub Issue: Fixes PSMRI/AMRIT#82

This PR introduces commit message standardization for the HWC-UI project by setting up Commitlint, Husky, and Commitizen. This PR enforce a consistent commit message format across the repository to improve collaboration, readability, and enable automation (like changelogs and versioning) in the future.

These tools are now fully integrated:

  • Commitlint enforces conventional commit message structure.
  • Husky prevents non-compliant commits by using Git hooks.
  • Commitizen provides an easy, interactive CLI for making properly formatted commits.
  • GitHub Actions validate commit messages for all pull requests.

✅ 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

Changes Overview

  • Added commitlint.config.js with conventional commit rules.
  • Configured Husky to run Commitlint on every commit via .husky/commit-msg.
  • Set up Commitizen with configuration in package.json for interactive commit prompts.
  • Added GitHub Actions workflow .github/workflows/commit-lint.yml to check commit messages on PRs.
  • Updated package.json and package-lock.json with required dev dependencies:
    • @commitlint/cli
    • @commitlint/config-conventional
    • commitizen
    • cz-conventional-changelog

Testing & Validation

  • Invalid commit messages are blocked locally with clear lint errors.
  • Interactive commit flow works via npm run commit or npx cz.
  • GitHub Actions workflow correctly fails PRs with non-compliant commit messages.
  • No disruption to existing build or CI pipelines.

Screenshots

image

Summary by CodeRabbit

  • Chores
    • Added a CI workflow to validate commit messages on pull requests.
    • Added local commit hooks to run staged linters and commit message checks.
    • Added commit tooling (Commitizen, commitlint, cz-conventional-changelog), lint-staged setup and supporting scripts/configuration.
    • Updated ignore list to exclude node_modules.
  • Documentation
    • Added "Setting Up Commit Hooks" guide with prerequisites, setup steps, and commit message convention guidance.

@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Walkthrough

Adds commit-message tooling and enforcement: commitlint config, Husky hooks (pre-commit, commit-msg), Commitizen and lint-staged config in package.json, a GitHub Actions workflow to lint PR commit ranges, README guidance, and .gitignore update to exclude node_modules.

Changes

Cohort / File(s) Summary of changes
CI Workflow: Commit Linting
.github/workflows/commit-lint.yml
New GitHub Actions workflow "Commit Compliance" that runs on PR events, checks out the repo (full history & submodules), sets up Node 18, runs npm ci --legacy-peer-deps, and executes commitlint across the PR range (base..head) with verbose output.
Husky Git Hooks
.husky/commit-msg, .husky/pre-commit
Added commit-msg hook running npx --no -- commitlint --edit "$1" and pre-commit hook running npx --no -- lint-staged.
Commit Tooling Config
package.json, commitlint.config.js
New package.json adding scripts (test, prepare, commit), Commitizen config, lint-staged rules, and devDependencies (@commitlint/cli, @commitlint/config-conventional, commitizen, cz-conventional-changelog, husky, lint-staged). Added commitlint.config.js extending @commitlint/config-conventional with explicit rules and allowed commit types.
Documentation
README.md
Added "Setting Up Commit Hooks" instructions: prerequisites, setup steps (npm ci), verifying Husky, and commit message convention guidance.
Git Ignore Update
.gitignore
Added node_modules to ignored paths.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant CZ as Commitizen
  participant Git as Git
  participant Husky as Husky
  participant LS as lint-staged
  participant CL as Commitlint
  participant GHA as GitHub Actions

  Dev->>CZ: (optional) npm run commit — guided message
  Dev->>Git: git commit
  activate Husky
  Husky->>LS: pre-commit -> run lint-staged
  LS-->>Husky: fixes/results
  Husky->>CL: commit-msg -> validate message (edit file)
  CL-->>Husky: pass/fail
  alt pass
    Husky-->>Git: allow commit
  else fail
    Husky-->>Dev: block commit with errors
  end
  deactivate Husky

  Dev->>GHA: open/update PR
  GHA->>CL: run commitlint on PR range (base..head)
  CL-->>GHA: pass/fail
  GHA-->>Dev: PR check status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

"I hop and nibble lines of code,
I straighten headers on the road.
Husky guards and CI peers,
Commitizen hums to calm my fears.
A tidy history, carrot-cheered." 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes additional changes that are not outlined in the objectives of issue #82, specifically the Husky pre-commit hook and lint-staged configuration in package.json and the .gitignore update to ignore node_modules, which are unrelated to enforcing commit message standards. To maintain focus on commit message linting objectives, consider extracting the lint-staged setup and .gitignore modifications into a separate pull request or confirming their necessity within the current scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “feat: added commit message linting to Inventory API” clearly encapsulates the primary feature introduced by this pull request, namely the enforcement of commit message standards, and is concise and directly related to the changeset.
Linked Issues Check ✅ Passed This pull request addresses all core objectives defined in linked issue #82 by incorporating Commitlint configuration, setting up a Husky commit-msg hook, adding Commitizen support in package.json, and implementing a GitHub Actions workflow to validate commit messages on pull requests, fulfilling the acceptance criteria without impacting existing CI/CD pipelines.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eaf1e66 and 7ee445e.

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

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: 6

🧹 Nitpick comments (1)
README.md (1)

47-50: Add languages to fenced code blocks (markdownlint MD040)

Specify bash for shell snippets.

Apply this diff:

-     ```
+     ```bash
      node --version
      npm --version
      ```
@@
-     ```
+     ```bash
      npm ci

Also applies to: 54-55

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f039356 and 8658b5e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • README.md (1 hunks)
  • commit-lint.config.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-04-25T14:46:10.894Z
Learnt from: G4URAV001
PR: PSMRI/Inventory-API#75
File: .husky/commit-msg:1-1
Timestamp: 2025-04-25T14:46:10.894Z
Learning: For Husky v9.1.1+ hooks, the shebang line (#!/usr/bin/env sh) and sourcing of Husky's helper script (. "$(dirname -- "$0")/_/husky.sh") are deprecated and will fail in v10.0.0. Hook scripts should only contain the command to be executed without these header lines.

Applied to files:

  • .husky/pre-commit
  • .husky/commit-msg
📚 Learning: 2025-04-25T14:46:25.965Z
Learnt from: G4URAV001
PR: PSMRI/Inventory-API#75
File: package.json:6-6
Timestamp: 2025-04-25T14:46:25.965Z
Learning: For Husky v9+, the correct prepare script is "prepare": "husky" (not "husky install" which was used in v8 and earlier). This change was introduced in Husky v9 which simplified the setup process. Reference: https://typicode.github.io/husky/how-to.html

Applied to files:

  • .husky/pre-commit
🪛 markdownlint-cli2 (0.18.1)
README.md

47-47: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


53-53: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (2)
.gitignore (1)

4-5: LGTM: add node_modules to ignore

Appropriate for the newly added Node-based tooling.

package.json (1)

6-7: Husky prepare script looks correct for v9

"prepare": "husky" is the right setup for Husky v9+.

Please confirm husky@^9 is indeed installed (it is in devDependencies).

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: 0

🧹 Nitpick comments (1)
README.md (1)

47-55: Add fenced code languages for CLI snippets.

Markdownlint is flagging these code fences (MD040). Specify the shell language so local linting stays green.

-     ```
+     ```bash
      node --version
      npm --version
      ```
@@
-     ```
+     ```bash
      npm ci
      ```
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8658b5e and 2b636b4.

📒 Files selected for processing (1)
  • README.md (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
README.md

47-47: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


53-53: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

Copy link
Contributor Author

@abhijeetw035 abhijeetw035 left a comment

Choose a reason for hiding this comment

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

made required changes

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69199f0 and ef45175.

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

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef45175 and eaf1e66.

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 3, 2025

@drtechie drtechie merged commit e44c208 into PSMRI:main Oct 7, 2025
2 checks passed
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.

[C4GT Community]: Implement Commit Message Linting and Automation for Inventory-API

2 participants