Skip to content

Conversation

@mohan-bee
Copy link

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

📋 Description

To make commit messages consistent and easy to read across the AMRIT API repositories, I will introduce Commitlint based on the Conventional Commits specification. This will create a standardized guideline for commit messages. I will integrate Husky to ensure that these rules are enforced automatically on every commit, preventing non-conforming messages. To improve the process for contributors, I will add Commitizen, which will prompt users with a simple interface to write valid commit messages. Additionally, I will set up a GitHub Action that will run during every pull request to catch any non-compliant commits before they are merged into the main branch. The implementation will be thoroughly tested in forked branches to ensure smooth integration with the existing CI/CD workflow, ensuring there are no disruptions.


✅ 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

I have tested this approach in forked branches, ensuring compatibility with existing CI/CD workflows. The integration with Husky, Commitizen, and Commitlint was verified and worked smoothly without interrupting current processes. I also ran tests locally to verify that the automated checks were correctly applied to the commit messages.

Proofs

Screenshot 2025-04-17 at 1 36 48 PM
Screenshot 2025-04-17 at 1 36 18 PM

Summary by CodeRabbit

  • Chores
    • Added automated commit message linting for pull requests and local commits.
    • Updated project configuration to ignore node_modules in version control.
    • Introduced project metadata and development dependencies for commit message standards and tooling.

@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

Walkthrough

This update introduces automated commit message linting to the repository. It adds a GitHub Actions workflow to enforce commit message standards on pull requests, sets up Husky to run commit linting as a commit-msg hook, and configures Commitlint using the conventional commit rules. The changes also include a new package.json to manage development dependencies and scripts related to commit message formatting and linting, and updates .gitignore to exclude node_modules. These additions collectively establish a standardized process for validating and formatting commit messages.

Changes

File(s) Change Summary
.github/workflows/commitlint.yml Added a GitHub Actions workflow to lint commit messages on PR events using Commitlint.
.husky/commit-msg Added Husky commit-msg hook to run Commitlint locally on each commit.
commitlint.config.cjs Added Commitlint configuration file using the conventional commit rules.
package.json Introduced project metadata, scripts, and devDependencies for Commitlint, Husky, and Commitizen setup.
.gitignore Updated to ignore the node_modules/ directory.

Sequence Diagram(s)

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

    Developer->>Husky: git commit
    Husky->>Commitlint: Run commitlint on commit message
    Commitlint-->>Husky: Validate message (pass/fail)
    Husky-->>Developer: Allow or block commit

    Developer->>GitHub: Push PR
    GitHub->>GitHub Actions: Trigger commitlint workflow
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Report results (pass/fail)
    GitHub Actions-->>GitHub: Set PR status
Loading

Possibly related issues

Poem

In the warren of code, a new rule takes flight,
Commit messages now must be tidy and right.
With Husky and Commitlint, the standards are set,
No more messy logs—just the best you can get!
Actions on GitHub give every PR a glance,
While rabbits in code do a happy commit dance.
🐇✨

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 45da1cc and d44f361.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .husky/commit-msg (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .husky/commit-msg
  • package.json

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

@mohan-bee mohan-bee marked this pull request as ready for review April 17, 2025 08:27
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 (2)
package.json (1)

6-10: Add a dedicated npm script for commitlint
Providing a lint:commit script makes it easy for contributors to run commit message checks manually:

   "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1",
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "lint:commit": "commitlint --edit \"$1\"",
     "prepare": "husky install",
     "commit": "cz"
   },
commitlint.config.cjs (1)

1-5: Refactor to simplify config export
You can export the conventional config directly for brevity:

-const config = require('@commitlint/config-conventional');
-
-module.exports = {
-  ...config,
-};
+module.exports = require('@commitlint/config-conventional');
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0cce2b3 and 45da1cc.

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

13-13: 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)


18-18: 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)

🔇 Additional comments (2)
.gitignore (1)

13-13: Appropriate .gitignore update
Ignoring node_modules/ ensures Node.js dependencies are not committed, which aligns with the new package.json and prevents repository bloat.

.github/workflows/commitlint.yml (1)

1-29: Workflow correctly enforces commit message linting
The GitHub Action is well-configured to run commitlint on pull requests, uses official actions (actions/checkout@v3, actions/setup-node@v3), and fails on any warnings. It aligns perfectly with the new commitlint configuration.

🧰 Tools
🪛 actionlint (1.7.4)

13-13: 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)


18-18: 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)

@@ -0,0 +1 @@
npx --no -- commitlint --edit "$1"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure Husky hook script includes the proper header
The hook currently only runs the lint command but is missing the shebang and Husky loader. Without these, it may not execute correctly. Please apply:

+#!/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"

@sonarqubecloud
Copy link

@mohan-bee mohan-bee changed the title Implemented Commit Message Linting and Automation for TM-API #85 Implemented Commit Message Linting and Automation for TM-API Apr 17, 2025
@mohan-bee mohan-bee changed the title Implemented Commit Message Linting and Automation for TM-API Fix: Implemented Commit Message Linting and Automation for TM-API Issue#85 Apr 17, 2025
@drtechie
Copy link
Member

@mohan-bee
this is not TM-API.
PSMRI/AMRIT#85 TM-API seems to be assigned to someone else.

@mohan-bee mohan-bee changed the title Fix: Implemented Commit Message Linting and Automation for TM-API Issue#85 Fix: Implemented Commit Message Linting and Automation for Inventory-API Issue#85 Apr 21, 2025
@mohan-bee
Copy link
Author

@drtechie Sorry mistyped. Renamed !

@mohan-bee mohan-bee changed the title Fix: Implemented Commit Message Linting and Automation for Inventory-API Issue#85 Fix: Implemented Commit Message Linting and Automation for Identity-API Issue#85 Apr 21, 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.

2 participants