Skip to content

Conversation

@mohan-bee
Copy link

@mohan-bee mohan-bee commented Apr 19, 2025

Description

JIRA ID:

Github Issues: Fixes PSMRI/AMRIT#83

This pull request introduces automated commit message validation and linting using Commitlint, Husky, and Commitizen for the Inventory API project. The goal is to enforce a consistent commit message format (using the Conventional Commits standard) across all contributions. Additionally, this setup allows for easier collaboration and improved changelog generation in the future.

Changes include:

  • Commitlint: Added configuration to enforce commit message standards.
  • Husky: Set up Git hooks to ensure commit messages are linted before commits are accepted.
  • Commitizen: Integrated prompts for contributors to help them write standardized commit messages.
  • Updated the README to provide setup instructions for these tools.

The primary motivation behind these changes is to standardize commit messages, improve collaboration, and lay the groundwork for automated changelog generation.


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

Testing

  • Pre-commit Hook Testing: I tested the pre-commit hooks locally by attempting to commit with improperly formatted commit messages. The commit was blocked, ensuring that the hooks are working as expected.
Screenshot 2025-04-19 at 11 22 54 PM
  • Commit Message Testing: I used the npm run commit command (via Commitizen) to ensure that the prompts guide contributors correctly. It works as expected, ensuring standardized commit messages.
Screenshot 2025-04-19 at 11 23 19 PM
  • Husky Hooks: I verified that the Husky hooks were installed correctly by checking the .husky directory and ensuring that the commit-msg hook is triggering commitlint for validation.

Screenshots/Logs

Screenshot 2025-04-19 at 11 23 58 PM

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting and enforcement using Commitlint and Husky Git hooks.
    • Added pre-commit checks to run linters on staged files for improved code quality.
    • Provided npm scripts and configuration for standardized commit creation with Commitizen.
  • Documentation

    • Updated README with detailed instructions for setting up and using commit hooks, commit message conventions, and Commitizen.
  • Chores

    • Added configuration files for ESLint, Commitlint, Husky, and lint-staged.
    • Updated .gitignore to exclude Node.js dependencies and lock files.

@coderabbitai
Copy link

coderabbitai bot commented Apr 19, 2025

Walkthrough

This change introduces a comprehensive commit message linting and automation system for the repository. It adds configuration and setup for Commitlint, Husky, Commitizen, and GitHub Actions to enforce conventional commit message standards. New configuration files and scripts are included for commit message validation both locally (via Git hooks) and in CI (via a GitHub Actions workflow). The .gitignore is updated to exclude Node.js-related files, and the README is expanded with instructions for contributors on using the new tools and conventions.

Changes

File(s) Change Summary
.github/workflows/commitlint.yml Added GitHub Actions workflow to lint commit messages on PR events.
.husky/commit-msg, .husky/pre-commit Added Husky Git hooks for commit message linting and staged file linting.
.gitignore Updated to ignore Node.js dependencies and lock files (/node_modules, package-lock.json).
README.md Expanded with setup instructions for commit hooks, Commitizen usage, and commit message conventions.
commitlint.config.js Added Commitlint configuration enforcing conventional commit message rules.
eslint.config.js Added ESLint configuration for TypeScript with recommended rules.
package.json Added Node.js project manifest with scripts, Commitizen, lint-staged, Husky, Commitlint, and ESLint devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky
    participant Commitlint
    participant Commitizen
    participant GitHub Actions

    Developer->>Commitizen: Run `npm run commit`
    Commitizen->>Developer: Prompt for commit details (conventional format)
    Developer->>Husky: Attempt commit
    Husky->>Commitlint: Validate commit message (commit-msg hook)
    Commitlint-->>Husky: Pass/Fail
    Husky-->>Developer: Allow/Block commit

    Developer->>GitHub Actions: Open/Update PR
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Pass/Fail
    GitHub Actions-->>Developer: PR check result
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate Commitlint to enforce commit message standards (#83)
Set up Husky to trigger commit-msg hooks (#83)
Add Commitizen to provide structured commit prompts to contributors (#83)
Configure GitHub Actions to verify commit format in Pull Requests (#83)

Possibly related issues

Poem

In the warren where the coders dwell,
A rabbit hops with rules to tell—
"Your commits must be neat and clean,
With Husky, Lint, and cz seen!
Now every message hops in line,
Our history’s clear, our standards fine.
🐇✨ Code on, friends, commit with glee!"

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

commitlint.config.js

Oops! Something went wrong! :(

ESLint: 9.25.0

A config object is using the "extends" key, which is not supported in flat config system.

Instead of "extends", you can include config objects that you'd like to extend from directly in the flat config array.

If you're using "extends" in your config file, please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-and-shareable-configs

If you're not using "extends" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

eslint.config.js

Oops! Something went wrong! :(

ESLint: 9.25.0

A config object is using the "extends" key, which is not supported in flat config system.

Instead of "extends", you can include config objects that you'd like to extend from directly in the flat config array.

If you're using "extends" in your config file, please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-and-shareable-configs

If you're not using "extends" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

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.
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@sonarqubecloud
Copy link

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

🧹 Nitpick comments (7)
.gitignore (2)

4-5: Ignore Node.js dependencies
Great addition of /node_modules under the new # dependencies section to prevent tracking installed packages. Consider also ignoring other lockfiles used by alternative package managers (e.g., yarn.lock, .pnpm-lock.yaml) to ensure consistency across different workflows.


33-33: Group lockfile ignore under dependencies
The package-lock.json entry currently sits under # Config. For clarity and maintainability, you may want to relocate it to the # dependencies section so all package-manager artifacts are collated together.

.github/workflows/commitlint.yml (1)

28-30: Commitlint invocation is appropriate
Linting commits between the base and head SHA with --verbose provides clear feedback on commit message violations.

YAML files should end with a newline character.
Please add a blank line after the last run command to satisfy YAML lint rules.

🧰 Tools
🪛 YAMLlint (1.35.1)

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

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

README.md (4)

45-48: Specify code block language for syntax highlighting
Please add a language identifier to the fenced code block:

-    ```
+    ```bash
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)


53-55: Add language specifier to the code block
Using a language marker improves readability:

-     ```
+     ```bash

63-65: Include language for the Commitizen command snippet
Enhance clarity by specifying the shell:

-     ```
+     ```bash
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)


90-90: Convert bare URL into markdown link
Wrap the URL for consistency with markdown best practices:

-Open the application in your browser. The inventory module will be accessible at http://localhost:3000/inventory.
+Open the application in your browser. The inventory module will be accessible at [http://localhost:3000/inventory](http://localhost:3000/inventory).
🧰 Tools
🪛 LanguageTool

[style] ~90-~90: Consider removing “of” to be more concise
Context: ... your browser. You will be able to view all of the items in your inventory, create purchas...

(ALL_OF_THE)

🪛 markdownlint-cli2 (0.17.2)

90-90: Bare URL used
null

(MD034, no-bare-urls)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3323d0 and b959ffb.

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

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

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

🪛 LanguageTool
README.md

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

(NODE_JS)


[grammar] ~76-~76: “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] ~79-~79: Loose punctuation mark.
Context: ... changes (formatting, etc.) - refactor: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~90-~90: Consider removing “of” to be more concise
Context: ... your browser. You will be able to view all of the items in your inventory, create purchas...

(ALL_OF_THE)

🪛 markdownlint-cli2 (0.17.2)
README.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


90-90: Bare URL used
null

(MD034, no-bare-urls)

🔇 Additional comments (9)
.github/workflows/commitlint.yml (3)

1-6: Workflow trigger configuration looks correct
The workflow is appropriately named and set to run on pull_request events (opened, synchronize, reopened), ensuring commit message validation on all PR updates.


12-19: Checkout step is correctly configured
Using actions/checkout@v4 with fetch-depth: 0 and submodules ensures full commit history is available for linting commit messages.


20-27: Node.js setup and dependency installation are solid
Setting up Node.js v18 and running npm ci --legacy-peer-deps guarantees a reproducible install of the linting tools.

README.md (1)

38-41: Commit hook instructions are clear and comprehensive
The new section outlines prerequisites and setup steps for Husky and Commitizen, fitting seamlessly into the existing documentation.

commitlint.config.js (5)

1-3: Extends standard Conventional Commit configuration
Leveraging @commitlint/config-conventional provides a solid base for commit message rules.


4-8: Body, footer, and header length rules are well-defined
Enforcing blank lines and max-line-length constraints helps maintain readable commit messages.


9-13: Subject casing rules are properly configured
Disallowing sentence-case, start-case, pascal-case, and upper-case ensures consistent subject formatting.


14-18: Subject and type presence rules are strict and appropriate
Preventing empty subjects and enforcing lowercase types aligns with Conventional Commits standards.


19-34: Type enumeration covers all relevant commit types
The predefined list of types is comprehensive and matches the README documentation.

Comment on lines +1 to +9
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint']
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Include root and environment settings
The current ESLint configuration lacks the root flag and an env block. Without these, ESLint may not recognize globals (e.g., process, window) or correctly determine the project root.
Apply this diff to harden the config:

 module.exports = {
+  root: true,
+  env: {
+    node: true,
+    es2020: true
+  },
   extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
   parser: '@typescript-eslint/parser',
   parserOptions: {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint']
};
module.exports = {
root: true,
env: {
node: true,
es2020: true
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint']
};

"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the prepare script to install Husky hooks
Husky v9 requires the install command to set up Git hooks. The current "prepare": "husky" invocation will not create the hooks.
Apply this diff:

-    "prepare": "husky",
+    "prepare": "husky install",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"prepare": "husky",
"prepare": "husky install",

@@ -0,0 +1 @@
npx lint-staged
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add Husky hook boilerplate
Husky hook scripts must start with the standard header to source the Husky runtime; otherwise the hook won’t execute.
Apply this diff:

- npx lint-staged
+ #!/usr/bin/env sh
+ . "$(dirname "$0")/_/husky.sh"
+ npx lint-staged
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx lint-staged
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged

@@ -0,0 +1 @@
npx --no -- commitlint --edit $1 No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add Husky hook boilerplate
Similarly, include the shebang and Husky shim in the commit-msg hook so commitlint is properly invoked.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

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

@mohan-bee
Copy link
Author

@drtechie Please Review it : )

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

1 participant