Skip to content

Conversation

@abhijeetw035
Copy link
Contributor

@abhijeetw035 abhijeetw035 commented Apr 13, 2025

📋 Description

JIRA ID:

GitHub Issue: Fixes PSMRI/AMRIT#62

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
    commitilint

  2. Commitizen

a.
first

b.
second

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message validation to ensure standardized and consistent commit logs during pull requests.
    • Enhanced the commit process with an integrated prompt that guides developers in meeting conventional commit guidelines.
  • Chores

    • Added a new GitHub Actions workflow for commit message linting.
    • Introduced a script to validate commit messages before finalizing commits.
    • Added new dependencies and scripts to facilitate commit message management and changelog generation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 13, 2025

Walkthrough

This pull request implements commit message validation across the repository. A GitHub Actions workflow is added to run commit message linting on pull request events. In addition, a Husky commit hook is configured to enforce commitlint rules locally, supported by a new commitlint configuration file. The package.json is updated with Commitizen integration and relevant dependencies, ensuring standardized commit messages during both local commits and pull request validations.

Changes

File(s) Change Summary
.github/workflows/commit-lint.yml, .husky/commit-msg, commitlint.config.js Introduce commit message linting: GitHub Actions workflow for PR validation, Husky hook for local commit checks, and commitlint configuration extending conventional commits rules.
package.json Updated scripts and dependencies to integrate Commitizen along with tools for commitlint and changelog standardization.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Git
    participant HuskyHook as Husky Hook
    participant Commitlint

    Developer->>Git: Create commit
    Git->>HuskyHook: Trigger commit-msg hook
    HuskyHook->>Commitlint: Execute commitlint with commit message file
    Commitlint-->>HuskyHook: Return validation result
    HuskyHook-->>Git: Allow or reject commit
Loading
sequenceDiagram
    participant Developer
    participant GHActions as GitHub Actions
    participant NodeEnv as Node Environment
    participant Commitlint

    Developer->>GHActions: Open Pull Request
    GHActions->>NodeEnv: Checkout repo, setup Node.js, install dependencies
    NodeEnv->>Commitlint: Run commitlint on commit range
    Commitlint-->>NodeEnv: Return validation result
    NodeEnv-->>GHActions: Log output and status
    GHActions-->>Developer: Report PR validation result
Loading

Assessment against linked issues

Objective Addressed Explanation
Standardize commit messages using Commitlint, Husky, and Commitizen (#62)
Enforce PR-level commit linting via GitHub Actions (#62)
Configure Husky to trigger commit-msg hooks (#62)
Add Commitizen for structured commit prompts (#62)

Possibly related issues

Poem

I'm a rabbit on a coding spree,
Hopping through commits so merrily.
With Husky and Commitlint in my trail,
Every commit is flawless without fail.
Thanks to Commitizen, my docs are neat—
My carrot-code dance is oh-so-sweet!
🥕🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

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

16-19: Add newline at end of file

The file is missing a newline at the end, which is considered a best practice for text files.

  echo "Validating commit messages against conventional commits standard..."
  npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54440e6 and 76ca16b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .husky/commit-msg (1 hunks)
  • commitlint.config.js (1 hunks)
  • package.json (2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (7)
.husky/commit-msg (1)

1-4: Good implementation of the commit message hook!

The script correctly sets up the Git hook to validate commit messages using commitlint. It uses the proper shebang line, sources the Husky setup script, and passes the commit message file to commitlint for validation.

commitlint.config.js (1)

1-36: Well-defined commitlint configuration!

The configuration extends the conventional commits standard and sets appropriate rules for message formatting. The type enumeration covers all common commit types, and the severity levels are reasonably set.

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

1-19: Great workflow implementation for CI validation

The GitHub Actions workflow is properly configured to validate commit messages for pull requests. It correctly sets up the environment, installs dependencies, and runs commitlint against the PR commits.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

package.json (4)

13-13: Good addition of Commitizen script

Adding the commit script provides an easy way for developers to create standardized commit messages through the Commitizen interactive CLI.


19-23: Proper Commitizen configuration

The configuration correctly sets up Commitizen to use the conventional changelog format.


75-76: Appropriate dependencies added

The added dependencies for commitlint and Commitizen are necessary for the commit standardization features and use appropriate versions.

Also applies to: 81-82


67-97:

Details

✅ Verification successful

Verify Node.js compatibility

The GitHub Actions workflow uses Node.js 16, but your Angular version (16.x) is compatible with newer Node.js versions. Consider ensuring consistent Node.js version usage across your CI workflow and local development environment.


🏁 Script executed:

#!/bin/bash
# Check the Angular version and suggested Node.js compatibility
echo "Checking Angular dependencies versions and Node.js compatibility..."
grep -A 5 "@angular/core" package.json
echo "Angular 16.x is compatible with Node.js 16.x, 18.x (recommended)"

Length of output: 571


Ensure Consistent Node.js Version Usage

The verification confirms that your Angular dependencies are set to 16.x (e.g., @angular/core is at ^16.2.0), and as noted, Angular 16.x is compatible with both Node.js 16.x and 18.x. Since the GitHub Actions workflow is currently using Node.js 16, please ensure that your local development environment uses a consistent Node.js version. This alignment will help prevent any subtle differences between CI and local runs.

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

♻️ Duplicate comments (1)
.github/workflows/commit-lint.yml (1)

11-14: 🛠️ Refactor suggestion

Update Node.js Version for Enhanced Security and Support

The workflow is currently configured to use Node.js version '16', which has reached end-of-life. Upgrading to a supported LTS version (e.g., '18' or '20') would improve both security and compatibility.

-          node-version: '16'
+          node-version: '18'
🧹 Nitpick comments (1)
.github/workflows/commit-lint.yml (1)

16-19: Commitlint Step & Trailing Newline Issue

The commit linting step is implemented well, with an informative echo statement and proper usage of the commitlint command. However, static analysis indicates that the file is missing a newline at the end. Please ensure that a trailing newline is added to comply with YAML lint rules.

+ (add a newline at the end of the file)
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76ca16b and bf74ac3.

📒 Files selected for processing (1)
  • .github/workflows/commit-lint.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/commit-lint.yml (1)

1-3: Workflow Trigger and Name Definition

The workflow is aptly named and correctly triggered on pull request events. No changes are needed in this section.

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

♻️ Duplicate comments (1)
.github/workflows/commit-lint.yml (1)

11-14: Updated Node.js Setup
The workflow now uses actions/setup-node@v4 with node-version: '18' and enables npm caching. This update follows best practices by upgrading from Node.js 16 to a supported LTS release, as previously recommended.

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

19-19: Newline at End of File Needed
A newline character should be added at the end of the file to comply with YAML linting rules (new-line-at-end-of-file).

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf74ac3 and b5efc1b.

📒 Files selected for processing (1)
  • .github/workflows/commit-lint.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (5)
.github/workflows/commit-lint.yml (5)

1-3: Workflow Header and Trigger Configuration
The workflow is configured with a clear header and is correctly set to trigger on pull request events. This aligns well with the commit message validation requirements.


4-7: Job Configuration is Clear and Maintainable
The jobs section and the definition of the commitlint job using the Ubuntu environment are straightforward and well-structured. This setup will help in maintaining clarity as the workflow evolves.


8-10: Proper Checkout Action Setup
Using actions/checkout@v4 with fetch-depth: 0 ensures that the full commit history is available. This is essential for the commitlint step to accurately validate commit messages across the PR's commit range.


15-15: Reliable Dependency Installation
Running npm ci --legacy-peer-deps is a good choice here. It ensures reproducible installations in the CI environment while addressing potential legacy peer dependency issues.


16-19: Effective Commit Message Linting Step
The step clearly logs the linting process and runs npx commitlint with the correct parameters to compare the commits between the base and head SHAs of the pull request. This implementation should enforce conventional commit messages as intended.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 19-19: no new line character at the end of file

(new-line-at-end-of-file)

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

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

30-30: Missing Newline at End-of-File.
YAML files should end with a newline character to conform to best practices and avoid linting issues. Please add a newline character at the end of the file.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5efc1b and ee79636.

📒 Files selected for processing (1)
  • .github/workflows/commit-lint.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (7)
.github/workflows/commit-lint.yml (7)

1-2: Descriptive Workflow Name.
The workflow name "Lint Commit Messages" clearly indicates the purpose of this job.


3-6: Pull Request Trigger Configuration.
The on section is correctly set up to trigger on pull request events (opened, synchronize, reopened), ensuring commit messages are evaluated at appropriate times.


7-10: Job and Runner Configuration.
The job commitlint is configured to run on ubuntu-latest, which is a suitable environment for this workflow.


11-19: Checkout Step Configuration.
The checkout step uses actions/checkout@v4 with proper submodule handling and a full fetch (fetch-depth: 0), which is essential for retrieving complete commit history when linting commit messages.


20-24: Node.js Setup Step.
The Node.js setup step uses actions/setup-node@v4 with Node.js version 18, addressing previous concerns about outdated Node.js versions and ensuring better security and compatibility.


25-27: Dependency Installation Step.
Using npm ci --legacy-peer-deps is appropriate here to install dependencies cleanly, which helps manage potential peer dependency conflicts effectively.


28-30: Commitlint Execution Step.
The final step correctly runs npx commitlint using commit range values between the base and head SHA with the --verbose flag. This ensures that commit messages in pull requests are properly validated. Ensure that the commitlint configuration in commitlint.config.js aligns with project standards.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

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

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

1-31: Great job implementing a robust commit message linting workflow!

The workflow is well-structured, uses best practices (full fetch, Node.js 18, proper commitlint range), and will effectively enforce commit message standards in PRs.

Just two minor YAML formatting issues to address:

  • Remove trailing spaces on line 31.
  • Add a newline at the end of the file.
-          
+
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 31-31: no new line character at the end of file

(new-line-at-end-of-file)


[error] 31-31: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee79636 and ce17959.

📒 Files selected for processing (1)
  • .github/workflows/commit-lint.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

[error] 31-31: no new line character at the end of file

(new-line-at-end-of-file)


[error] 31-31: trailing spaces

(trailing-spaces)

@sonarqubecloud
Copy link

@drtechie drtechie merged commit 0d8e8a2 into PSMRI:develop Apr 16, 2025
5 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]: Standardize Git Commit Messages using Commitlint, Husky & Commitizen for HWC-UI

2 participants