Skip to content

Conversation

@OVER-CODER
Copy link

@OVER-CODER OVER-CODER commented Apr 18, 2025

📋 Description

Github Issue Fixes: PSMRI/AMRIT/85
JIRA ID:

This PR introduces commit message standardization for the ⁠TM-API project by setting up Commitlint, Husky, and Commitizen. The goal is to 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

Added Configuration Files

  • commitlint.config.js - Defines commit message validation rules
  • .husky/commit-msg - Hook that runs validation on commit messages
  • .github/workflows/commitlint.yml - GitHub Actions workflow for PR validation

Dependencies Added

  • @commitlint/cli and @commitlint/config-conventional - For commit message linting
  • commitizen and cz-conventional-changelog - For guided commit creation

Package.json Updates

  • Added commit script for easy Commitizen access
  • Configured Commitizen adapter settings
  • Ensured compatibility with existing scripts

Testing Completed

  • Successfully blocked malformed commit messages locally
  • Generated proper commits using the new tooling
  • Verified GitHub Actions correctly validate PR commits
  • Ensured compatibility with existing development workflows

Changes Overview

Commitlint functionality working properly:
Screenshot 2025-04-18 151753

Commitzen working proper;y with npx cz command:
Screenshot 2025-04-18 151959

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting for pull requests and local commits to ensure standardized commit message formatting.
    • Added configuration for commit message conventions based on the conventional commit standard.
    • Integrated tools for managing Git hooks and commit message formatting.
  • Chores

    • Added project metadata, scripts, and development dependencies to support commit linting and Git hook automation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

This change introduces a comprehensive commit message linting and standardization system to the project. It adds configuration and tooling for Commitlint, Husky, and Commitizen, alongside a GitHub Actions workflow to automatically enforce commit message conventions on pull requests. The setup includes a commit message hook for local validation, a configuration file specifying detailed commit message rules, and a package manifest defining dependencies and scripts for managing commit hooks and standardized commit creation.

Changes

File(s) Change Summary
.github/workflows/commitlint.yml Adds a GitHub Actions workflow to lint commit messages on pull request events using Commitlint.
.husky/commit-msg Introduces a Husky Git hook that runs Commitlint locally on each commit message.
commitlint.config.js Adds Commitlint configuration enforcing conventional commit rules and customizes message validation parameters.
package.json Adds project manifest with Commitlint, Husky, and Commitizen as devDependencies, and sets up related scripts.
README.md Adds documentation for setting up commit hooks and commit message conventions.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky (Git Hook)
    participant Commitlint
    participant GitHub Actions
    participant Node.js

    Developer->>Husky (Git Hook): git commit
    Husky (Git Hook)->>Commitlint: Validate commit message
    Commitlint-->>Husky (Git Hook): Pass/Fail

    Developer->>GitHub Actions: Open/sync/reopen PR
    GitHub Actions->>Node.js: Setup environment
    GitHub Actions->>Commitlint: Lint all PR commits
    Commitlint-->>GitHub Actions: Pass/Fail
Loading

Possibly related issues

Poem

🐰
In the land of code, neat and bright,
Commitlint hops in to check what's right.
Husky guards each message with care,
While Actions in the cloud declare:
"Standard commits, tidy and true—
Our history’s clean, thanks to this crew!"
🥕


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
🪧 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 generate sequence diagram to generate a sequence diagram of the changes in 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: 2

🔭 Outside diff range comments (1)
.husky/commit-msg (1)

1-4: 💡 Verification agent

🧩 Analysis chain

Ensure Husky hook environment is loaded
The hook script needs to source Husky’s environment loader (husky.sh) so that the commit-msg hook runs correctly. Also verify the file is executable (chmod +x .husky/commit-msg).

Apply this diff to load Husky before running Commitlint:

 #!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
  npx --no -- commitlint --edit "$1"

Do you want assistance to update the script and confirm its executable bit?


🏁 Script executed:

#!/bin/bash
echo "=== Checking .husky/commit-msg ==="
if [ -f .husky/commit-msg ]; then
  ls -l .husky/commit-msg
  echo "---- First 5 lines ----"
  head -n 5 .husky/commit-msg
else
  echo ".husky/commit-msg not found"
fi

echo
echo "=== Checking .husky/_/husky.sh ==="
if [ -f .husky/_/husky.sh ]; then
  ls -l .husky/_/husky.sh
else
  echo ".husky/_/husky.sh not found"
fi

Length of output: 516


🏁 Script executed:

#!/bin/bash
echo "=== Searching for any husky.sh references ==="
grep -R "husky.sh" -n .

Length of output: 124


Source Husky hook loader & make script executable
Your commit-msg hook currently neither loads Husky’s environment nor is executable. Without sourcing husky.sh, built‑in Husky helpers (e.g. $HUSKY_GIT_PARAMS) won’t work, and the hook won’t run at all without the +x bit.

Please:

  • Add the loader invocation at the top of .husky/commit-msg
  • Commit or generate .husky/_/husky.sh (run npx husky install if missing)
  • Mark the hook executable

Suggested diff:

--- a/.husky/commit-msg
+++ b/.husky/commit-msg
@@ -1,2 +1,3 @@
 #!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
 npx --no -- commitlint --edit "$1"

Then:

git add .husky/_/husky.sh .husky/commit-msg
chmod +x .husky/commit-msg
🧹 Nitpick comments (3)
.github/workflows/commitlint.yml (2)

1-31: Add trailing newline for YAML compliance
YAML parsers and linters typically expect a newline at end‑of‑file. Please add a blank line after the last line to satisfy the new-line-at-end-of-file rule.

🧰 Tools
🪛 YAMLlint (1.35.1)

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

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


21-28: Optimize CI by caching NPM modules
Caching your dependencies can dramatically speed up the workflow and reduce network usage. Consider adding an actions/cache step between setting up Node.js and installing dependencies.

Example diff:

     - name: Setup Node.js
       uses: actions/setup-node@v4
       with:
         node-version: 18
+    - name: Cache NPM modules
+      uses: actions/cache@v3
+      with:
+        path: ~/.npm
+        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
+        restore-keys: |
+          ${{ runner.os }}-node-
     - name: Install dependencies
       run: npm ci --legacy-peer-deps
package.json (1)

11-12: Enhance package metadata
Consider adding "repository", "bugs", and "homepage" fields to improve package discoverability and enable proper links in registries.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c84b73 and d66e207.

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

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

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

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

1-36: Commitlint configuration follows conventional commit conventions
The configuration correctly extends @commitlint/config-conventional and enforces header length, subject-case, and allowed types per the Conventional Commits spec.

@sonarqubecloud
Copy link

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

67-70: Specify language for fenced code blocks
The code blocks for verifying Node/npm versions (lines 67–70) and for installing dependencies (lines 73–75) should declare a language (e.g., bash) to improve readability and enable proper syntax highlighting.

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

Also applies to: 73-75

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

67-67: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d66e207 and d338130.

📒 Files selected for processing (1)
  • README.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~65-~65: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...

(NODE_JS)


[grammar] ~87-~87: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation changes - `styl...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[uncategorized] ~90-~90: Loose punctuation mark.
Context: ... changes (formatting, etc.) - refactor: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)
README.md

67-67: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


73-73: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

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