Skip to content

Conversation

@Sahil1694
Copy link

@Sahil1694 Sahil1694 commented Apr 20, 2025

📋 Description

Github Issues: Fixes PSMRI/AMRIT#82

This PR introduces commit message standardization for the Inventory-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:

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

✅ Type of Change
⚙️ Config change (configuration file or build script updates)

ℹ️ Additional Information

Changes Overview

Added Configuration Files

  • commitlint.config.js - Defines commit message validation rules
  • .husky/commit-msg - Hook that runs validation on commit messages
  • .github/workflows/commit-compliance.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
  • husky - For Git hooks management

Package.json Updates

  • Added commit script for easy Commitizen access
  • Configured Commitizen adapter settings
  • Added prepare script for Husky installation

Testing Completed

  • Successfully blocked malformed commit messages locally
  • Generated proper commits using the new tooling
  • Ensured compatibility with existing development workflows
    image
    image

Changes Overview

  • Commitlint functionality working properly
  • Commitizen working smoothly with npm run commit

Summary

New Features

  • Introduced automated commit message linting for pull requests to ensure consistent commit message formatting
  • Added Git hooks to validate commit messages locally before commits are made
  • Enabled interactive commit message prompts for standardized commit creation

Chores

  • Added configuration files and dependencies to support commit message linting and formatting tools
  • Updated documentation with commit message conventions

Summary by CodeRabbit

  • Chores
    • Introduced automated commit message linting for pull requests targeting main and develop branches.
    • Added Husky Git hook to enforce commit message standards during commits.
    • Updated .gitignore to exclude node_modules directory.
    • Added configuration files and dependencies to support commit message linting and standardized commit prompts.
  • New Features
    • Added a new logging dependency (slf4j-simple) to the project.

@coderabbitai
Copy link

coderabbitai bot commented Apr 20, 2025

Walkthrough

This update introduces a comprehensive commit message linting and enforcement system to the project. It adds configuration for Commitlint, Husky Git hooks, and Commitizen, ensuring standardized commit messages. A new GitHub Actions workflow is set up to automatically check commit message compliance on pull requests targeting the main and develop branches. Supporting configuration files and dependencies are added for Node.js tooling, and the .gitignore is updated to exclude node_modules. Additionally, the Maven pom.xml is updated to include the slf4j-simple logging implementation.

Changes

File(s) Change Summary
.github/workflows/lint-commits.yml Added new GitHub Actions workflow to lint commit messages on PRs to main and develop using Commitlint.
.husky/commit-msg Added Husky Git hook to run Commitlint on commit messages during the commit process.
commitlint.config.js Added Commitlint configuration file enforcing conventional commit message rules.
package.json Introduced Node.js project file with devDependencies and scripts for Commitlint, Commitizen, and Husky.
.gitignore Updated to ignore node_modules/ directory with a clarifying comment.
pom.xml Added slf4j-simple logging dependency version 2.0.7 to Maven configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky
    participant Commitlint
    participant GitHub Actions

    Developer->>Husky: git commit
    Husky->>Commitlint: Lint commit message
    Commitlint-->>Husky: Pass/Fail
    Husky-->>Developer: Allow/Block commit

    Developer->>GitHub Actions: Open/Synchronize PR to main/develop
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Compliance report
    GitHub Actions-->>Developer: PR check result
Loading

Possibly related issues

Poem

In the warren, we code with delight,
Our commits now tidy, precise, and bright.
With Husky on guard and Commitlint in tow,
Each message is perfect, as standards now show.
GitHub Actions will check with a hop and a spin,
And node_modules? Ignored—let’s keep our repo thin!
🐇✨

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.

📜 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 ec84a61 and 3eef052.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

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.

@Sahil1694 Sahil1694 changed the title Implement Commit Message Linting and Automation for Inventory-APIRetryClaude can make mistakes. Please double-check responses. Implement Commit Message Linting and Automation for Inventory. . Apr 20, 2025
@Sahil1694 Sahil1694 changed the title Implement Commit Message Linting and Automation for Inventory. . Implement Commit Message Linting and Automation for Inventory. Apr 20, 2025
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: 2

🧹 Nitpick comments (5)
.gitignore (1)

26-28: Nit: Improve comment readability
For consistency with other comment blocks, add a space after # in the new section header. For example:

-#Node modules
+# Node modules
pom.xml (1)

63-67: Optional: centralize SLF4J version
Consider defining a <slf4j.version>2.0.7</slf4j.version> property in the <properties> section and referencing it here. Centralizing the version makes future upgrades simpler and keeps dependency versions consistent.

commitlint.config.js (1)

1-36: Approve commitlint rules, but ignore merge commits
The configuration correctly extends the conventional preset and enforces message structure. To avoid failures on auto-generated merge commits (e.g., Merge pull request #...), add an ignores function:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  // Skip merge commits
  ignores: [(commit) => commit.startsWith('Merge ')],
  rules: {
    /* existing rules */
  },
};
package.json (1)

9-12: Optional: add a manual linting script
To run commitlint outside of hooks or CI, consider adding:

"scripts": {
   "lint:commits": "commitlint --config commitlint.config.js --from=origin/main --to=HEAD"
}
.github/workflows/lint-commits.yml (1)

30-30: Add newline at end of file
A trailing newline satisfies the YAML lint rule and POSIX file conventions.

--- a/.github/workflows/lint-commits.yml
+++ b/.github/workflows/lint-commits.yml
@@ -29,1 +29,2
-        run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+        run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+
🧰 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 c3323d0 and da158af.

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

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

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

🔇 Additional comments (9)
pom.xml (1)

63-67: Addition of slf4j-simple is appropriate
The new slf4j-simple dependency (v2.0.7) matches the slf4j-api version and, combined with the exclusion of Spring Boot’s default logging, ensures a consistent logging implementation.

package.json (2)

2-8: Approve devDependencies setup
The selected versions of @commitlint, commitizen, cz-conventional-changelog, and husky are appropriate to enforce commit message linting and interactive commit prompts.


1-18: Verify CI workflow inclusion
This package.json configures local hooks, but please confirm that the GitHub Actions workflow file (e.g., .github/workflows/lint-commits.yml) has been added to enforce commit message linting on PRs against main/develop.

.github/workflows/lint-commits.yml (6)

1-2: Workflow name is descriptive
The name: Commit Compliance clearly communicates the workflow’s purpose and aligns with its functionality.


3-7: Trigger events are correctly scoped
Listening on opened, synchronize, and reopened for main and develop ensures PRs are validated at the right times and branches.


13-18: Checkout step fetches full history
Setting fetch-depth: 0 is essential so commitlint can analyze all commits in the PR, not just the most recent one.


20-25: Node.js environment setup is optimal
Using actions/setup-node@v4 with Node.js 18 and npm caching speeds up installs while ensuring compatibility with the tooling.


26-28: Dependency installation includes devDependencies
Running npm ci --legacy-peer-deps installs both production and development deps (including @commitlint/cli), which is necessary for linting commits.


29-30: Commitlint validation command is accurate
The --from and --to flags correctly scope the commit range between the PR’s base and head, ensuring all new commits are checked.

🧰 Tools
🪛 YAMLlint (1.35.1)

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

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

@Sahil1694
Copy link
Author

@drtechie can you please review the changes ?

@sonarqubecloud
Copy link

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