Skip to content

Conversation

@abhijeetw035
Copy link
Contributor

@abhijeetw035 abhijeetw035 commented Sep 25, 2025

📋 Description

JIRA ID:

GitHub Issue: Fixes PSMRI/AMRIT#85

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

  1. Commitlint
image
  1. Commitizen
image

Summary by CodeRabbit

  • Chores

    • Added CI workflow enforcing commit message compliance on pull requests.
    • Enabled commit-msg and pre-commit hooks to run commit message linting and pre-commit checks.
    • Configured commitlint, commitizen, husky, and lint-staged along with project scripts and dev dependencies to standardize commits.
  • Documentation

    • Added a "Setting Up Commit Hooks" guide with prerequisites, setup steps, and commit message conventions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Adds commit-message enforcement and automation: Commitlint config, Husky hooks (pre-commit and commit-msg), Commitizen/lint-staged tooling in package.json, a GitHub Actions workflow to lint commits on PRs, and README setup instructions.

Changes

Cohort / File(s) Summary
GitHub Actions: Commit Linting
.github/workflows/commit-lint.yml
New “Commit Compliance” workflow triggered on PR events; checks out the repo (including submodules, full history), sets up Node 18, installs deps, and runs commitlint between base and head SHAs.
Husky Hooks
.husky/commit-msg, .husky/pre-commit
Adds commit-msg hook running npx commitlint --edit "$1" and pre-commit hook running npx lint-staged.
Commitlint Configuration
commitlint.config.js
New configuration extending conventional commits and enforcing rules for header/body/footer formatting, subject casing, line lengths, and allowed commit types.
Project Tooling & Scripts
package.json
Adds devDependencies (commitlint, @config, commitizen, cz-conventional-changelog, husky, lint-staged), scripts (prepare, commit), commitizen config, and lint-staged mappings.
Documentation
README.md
Inserts "Setting Up Commit Hooks" instructions (Node/npm prerequisites, setup steps, verification, and commit message types); section appears in two locations.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Git as Local Git
  participant Husky as Husky Hooks
  participant LS as lint-staged
  participant CL as Commitlint

  Dev->>Git: git commit
  Git->>Husky: pre-commit
  Husky->>LS: npx lint-staged
  LS-->>Husky: results
  alt staged checks pass
    Husky-->>Git: continue
    Git->>Husky: commit-msg
    Husky->>CL: npx commitlint --edit $1
    CL-->>Husky: pass/fail
    alt valid
      Husky-->>Git: allow commit
    else invalid
      Husky-->>Dev: block commit with errors
    end
  else staged checks fail
    Husky-->>Dev: block commit
  end
Loading
sequenceDiagram
  autonumber
  participant GH as GitHub
  participant WF as Workflow: Commit Compliance
  participant Repo as Repository
  participant Node as Node 18
  participant CL as Commitlint

  GH-->>WF: PR opened/synchronize/reopened
  WF->>Repo: actions/checkout (fetch-depth: 0, include submodules, PR head)
  WF->>Node: setup-node@v4 (Node 18)
  WF->>Repo: npm ci --legacy-peer-deps
  WF->>CL: commitlint --from ${{base}} --to ${{head}} --verbose
  CL-->>WF: pass/fail
  WF-->>GH: report status on PR
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

A hop, a prompt, a tidy line,
I polish commits till they shine.
Hooks at the gate, CI keeps pace,
Conventional joy in every trace.
I nibble bugs and tidy the log—happy rabbit, tidy repo. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The addition of a Husky pre-commit hook to run lint-staged for code linting falls outside the scope of issue #85, which focuses solely on commit message linting and related automation, and introduces functionality not requested in the linked objectives. Remove the lint-staged pre-commit hook and its configuration or migrate these code-linting changes to a separate pull request so that this PR remains focused on commit message linting.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title succinctly captures the primary feature introduced—commit message linting—and aligns with the changeset that adds Commitlint, Husky hooks, Commitizen, and a GitHub Actions workflow to enforce commit standards.
Linked Issues Check ✅ Passed The changes fully implement the objectives of issue #85 by integrating Commitlint with conventional commit rules, setting up a Husky commit-msg hook, configuring Commitizen for guided commits, and adding a GitHub Actions workflow to validate commit messages on pull requests, thereby satisfying the acceptance criteria and expected outcomes.
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

📜 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 3a94730 and 79af1c0.

📒 Files selected for processing (3)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • .husky/commit-msg

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
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)
README.md (1)

69-96: Add languages to fenced code blocks

Markdown lint (MD040) is flagging the unlabeled fences here. Tagging them as bash/shell keeps docs clean and silences CI. Example:

-     ```
+     ```bash
      node --version
      npm --version
      ```

Please do the same for the other new blocks in this section.

.github/workflows/commit-lint.yml (1)

25-30: Optional: Cache npm dependencies to speed up this job

Line 25 currently re-installs everything on each run. Adding cache: 'npm' to the actions/setup-node step would reuse the cache between runs and keep this workflow snappy.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf9f71c and 3a94730.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • README.md (1 hunks)
  • commitlint.config.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
README.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)

🔇 Additional comments (1)
commitlint.config.js (1)

22-33: Commit type whitelist matches the conventional set

Line 22 onward covers the standard Conventional Commit types, so the enforcement looks solid.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 1, 2025

@drtechie drtechie merged commit dc84bd9 into PSMRI:main Oct 7, 2025
2 of 3 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 TM-API

2 participants