Skip to content

Conversation

@instinxt
Copy link

@instinxt instinxt commented May 5, 2025

📋 Description

Fixes : PSMRI/AMRIT#85
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

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

Commitzen working:
image

Summary by CodeRabbit

  • New Features
    • Introduced automated commit message linting to enforce conventional commit standards.
    • Added Git hooks to check commit messages before commits are finalized.
    • Provided interactive tooling for standardized commit message creation.
  • Documentation
    • Updated README with instructions on setting up commit hooks and commit message conventions.
  • Chores
    • Added configuration files and updated .gitignore to support commit linting and Git hook setup.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 5, 2025

Walkthrough

This update introduces a commit message linting system using Commitlint, Husky, and Commitizen, enforced both locally via Git hooks and remotely through a GitHub Actions workflow. Configuration files for Commitlint and Commitizen are added, along with a package.json specifying relevant development dependencies and scripts. The .gitignore file is updated to exclude package-lock.json, and the README is revised to document the new commit message standards and setup instructions. The Husky commit-msg hook ensures commit messages are linted before acceptance, while the GitHub workflow validates commit messages on pull requests.

Changes

File(s) Change Summary
.github/workflows/commit-lint.yml Added a GitHub Actions workflow to lint commit messages on pull request events using Commitlint.
.husky/commit-msg Introduced a Husky commit-msg hook script to run Commitlint on local commits.
commitlint.config.js Added Commitlint configuration enforcing conventional commit message rules and customizations.
package.json Added project metadata, scripts, devDependencies for Commitlint, Husky, Commitizen, and Commitizen configuration.
.gitignore Updated to exclude package-lock.json from version control.
README.md Updated documentation with setup instructions for commit hooks and commit message conventions.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Git
    participant Husky
    participant Commitlint
    participant GitHub
    participant GitHub Actions

    Developer->>Git: git commit
    Git->>Husky: Trigger commit-msg hook
    Husky->>Commitlint: Lint commit message
    Commitlint-->>Husky: Pass/Fail result
    Husky-->>Git: Allow or block commit

    Developer->>GitHub: Push branch / open PR
    GitHub->>GitHub Actions: Trigger commit-lint workflow
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Pass/Fail result
    GitHub Actions-->>GitHub: Update PR status
Loading

Possibly related issues

Poem

In the warren of code, where the carrots are sweet,
A rabbit now hops with Commitlint at its feet.
Husky guards the burrow, Commitizen shows the way,
GitHub Actions chime in, checking PRs every day.
With rules in our paws and a README to guide,
Our messages are tidy—no need to hide!
🐇✨


📜 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 455a5b7 and 5255ac8.

📒 Files selected for processing (1)
  • .husky/commit-msg (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .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
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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

🧹 Nitpick comments (7)
.gitignore (1)

61-63: Fix typo in ignore comment and confirm lockfile policy.

The comment says # Exclude pack-lock.json but the file is named package-lock.json. Please correct the typo:

- # Exclude pack-lock.json
+ # Exclude package-lock.json

Additionally, many teams prefer committing the lockfile to ensure reproducible installs. Verify that excluding package-lock.json aligns with your CI/CD strategy and team conventions.

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

18-18: Add a newline at end of file.

POSIX standards recommend ending text files with a newline. Please ensure there is a blank line at the end to avoid YAML or linter warnings.

🧰 Tools
🪛 YAMLlint (1.35.1)

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

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

README.md (4)

47-49: Specify languages for fenced code blocks.

To improve readability and syntax highlighting, add a language identifier (e.g., bash or shell) to your code fences. For example:

- ```
+ ```bash
  mvn clean install
- ```
+ ```

Please apply the same for the Maven run and npm ci blocks at lines 56–58 and 97–99.

Also applies to: 56-58, 97-99

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)


61-61: Remove or consolidate duplicate headings.

There are two ## Usage sections at lines 61 and 123. Consider merging them or renaming one to avoid confusion for readers.

Also applies to: 123-123


31-31: Correct markdown link formatting.

There’s an extra space before the URL in the link:

- follow this [guide] (https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup)
+ follow this [guide](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

31-31: Bare URL used
null

(MD034, no-bare-urls)


82-82: Align Node.js version with CI configuration.

The GitHub Actions workflow uses Node.js 16. Consider updating the README prerequisite:

- Node.js (v14 or later)
+ Node.js (v16 or later)
commitlint.config.js (1)

19-34: Consider Adding Scope Formatting Rules (Optional)
To further standardize commit messages, you might add rules for scopes. For example:

 module.exports = {
   // …existing settings…
   rules: {
+    "scope-case": [2, "always", "lower-case"],
+    "scope-empty": [2, "never"],
     // …existing rules…
   }
 };

This enforces lowercase scopes and disallows empty scopes, which helps maintain uniformity when using type(scope): subject.

📜 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 455a5b7.

📒 Files selected for processing (6)
  • .github/workflows/commit-lint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .husky/commit-msg (1 hunks)
  • README.md (3 hunks)
  • commitlint.config.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commit-lint.yml

8-8: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


11-11: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 YAMLlint (1.35.1)
.github/workflows/commit-lint.yml

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

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

🪛 markdownlint-cli2 (0.17.2)
README.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


123-123: Multiple headings with the same content
null

(MD024, no-duplicate-heading)

🪛 LanguageTool
README.md

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

(NODE_JS)


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

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (7)
package.json (2)

1-22: commitlint.config.js missing from review.

Your scripts and workflows reference commitlint.config.js, but it wasn’t included here. Please ensure the file exists at the repo root so that commitlint can enforce your conventional commit rules as intended.


1-22: package.json setup looks solid.

Dev dependencies, scripts (prepare, commit), and the Commitizen adapter configuration are correctly defined and should enable seamless commit message linting and generation.

commitlint.config.js (5)

1-3: Extend Conventional Commit Rules
Good use of extends: ["@commitlint/config-conventional"] to inherit the widely-adopted conventional commit rule set. This minimizes duplication and guarantees consistency with the standard.


4-8: Review Line Length Constraints
You’ve set the body and footer to an error at 100 characters, and the header max‐length to 100 as well. The Conventional Commits spec (and many teams) recommend a header limit of 50–72 characters for readability in terminals and changelogs. Please verify if 100 is intentional for your workflow; if not, consider reducing

"header-max-length": [2, "always", 72]

to align with best practices.


9-13: Enforce Subject Casing
The subject-case rule disallows sentence-case, start-case, pascal-case, and upper-case, effectively enforcing lowercase (or kebab–case) without being overly prescriptive. This aligns well with common conventions.


14-15: Prevent Empty Subjects and Trailing Periods
The subject-empty and subject-full-stop rules correctly enforce a non-empty subject and forbid trailing periods, which improves clarity and cleanliness of the commit header.


16-24: Restrict Commit Types to Approved Categories
Your configuration for type-case, type-empty, and type-enum properly enforces lowercase, non-empty types and limits them to the agreed-upon set (build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test). This ensures consistency and prevents ad-hoc types.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 5, 2025

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

1 participant