Skip to content

Conversation

@G4URAV001
Copy link

@G4URAV001 G4URAV001 commented Apr 25, 2025

📋 Description

Closes PSMRI/AMRIT#84
JIRA ID: issue link

This PR implements commit message linting and automation for all contributors in the API repositories using Commitlint, Husky, and Commitizen. The aim of this initiative is to enforce a consistent and readable commit history, improving collaboration and enabling future automated changelogs and CI/CD processes. This setup aligns with the practices followed across all C4GT Community repositories.

  • Every commit in API repositories will follow the defined structure (e.g., Conventional Commits).

  • Husky will block non-compliant commit messages locally.

  • Contributors will use Commitizen (cz) to follow a guided commit format.

  • GitHub Actions will fail PR checks if commit messages do not follow the required format.

  • All changes will be compatible with the existing CI/CD pipelines, ensuring smooth integration.


✅ 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 ⁠ commitlint.config.js ⁠ with conventional commit rules.
•⁠ ⁠Configured Husky to run Commitlint on every commit via ⁠ .husky/commit-msg ⁠.
•⁠ ⁠Set up ⁠ Commitizen ⁠ with configuration in ⁠ package.json ⁠ for interactive commit prompts.
•⁠ ⁠Added GitHub Actions workflow ⁠ .github/workflows/commit-lint.yml ⁠ to check commit messages on PRs.
•⁠ ⁠Updated ⁠ package.json ⁠ and ⁠ package-lock.json ⁠ with required dev dependencies:

  • ⁠ @commitlint/cli ⁠
    ⁠ - @commitlint/config-conventional ⁠
    ⁠ - commitizen ⁠
    ⁠ - cz-conventional-changelog ⁠

Testing & Validation
•⁠ ⁠Invalid commit messages are blocked locally with clear lint errors.
•⁠ ⁠Interactive commit flow works via ⁠ npm run commit ⁠ or ⁠ npx cz ⁠.
•⁠ ⁠GitHub Actions workflow correctly fails PRs with non-compliant commit messages.
•⁠ ⁠No disruption to existing build or CI pipelines.

Screenshot 2025-04-25 205059
Screenshot 2025-04-25 205128

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting to ensure consistency and adherence to standards.
    • Added Git hooks to enforce commit message rules during the commit process.
    • Provided Commitizen integration for easier creation of standardized commit messages.
  • Documentation

    • Updated README with instructions for setting up commit hooks and guidelines for writing compliant commit messages.
  • Chores

    • Updated .gitignore to exclude Node.js-related files and directories.

@coderabbitai
Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This update introduces a comprehensive commit message linting and enforcement system for the project. It adds configuration files and dependencies for Commitlint, Husky, and Commitizen, establishes a GitHub Actions workflow for commit message compliance on pull requests, and documents the setup and usage in the README. The .gitignore is updated to exclude Node.js artifacts. These changes collectively ensure that commit messages follow the Conventional Commits specification through both local Git hooks and automated CI checks.

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 to lint commit messages locally using Commitlint.
commitlint.config.js Added Commitlint configuration enforcing the Conventional Commits specification with specific formatting rules.
package.json Added Node.js project metadata, npm scripts for testing, preparing Husky, and running Commitizen, Commitizen configuration, and devDependencies for Commitlint, Commitizen, Husky, and related tools.
.gitignore Updated to ignore node_modules/ and npm-debug.log for Node.js development artifacts.
README.md Added a section detailing the setup and usage of commit hooks, Commitlint, and Commitizen, including prerequisites, installation steps, and commit message conventions. Minor punctuation fix in the community invitation line.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky (commit-msg hook)
    participant Commitlint
    participant GitHub Actions (CI)
    participant Node.js/NPM

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

    Developer->>GitHub Actions (CI): Open/sync PR
    GitHub Actions (CI)->>Node.js/NPM: Setup environment, install dependencies
    GitHub Actions (CI)->>Commitlint: Lint PR commit messages
    Commitlint-->>GitHub Actions (CI): Pass/Fail result
    GitHub Actions (CI)-->>Developer: Report status on PR
Loading

Possibly related issues

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

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.

@sonarqubecloud
Copy link

@G4URAV001
Copy link
Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented May 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (4)
.github/workflows/commit-lint.yml (2)

30-30: Remove trailing spaces and ensure newline at end-of-file

Static analysis flagged trailing spaces on line 30 and no EOL at the end. Cleaning this up will satisfy YAML linters:

-          npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose␣
+          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)


[error] 30-30: trailing spaces

(trailing-spaces)


1-29: Optional: Enforce commit message linting on direct pushes

Currently the workflow only triggers on pull requests. To catch non-PR commits (e.g., direct pushes to main), you might also add:

on:
  push:
    branches:
      - main

This helps maintain commit consistency across all branches.

README.md (2)

34-43: Use consistent list markers

The new “Setting Up Commit Hooks” section mixes - for lists, whereas the rest of the README uses *. Switching to * maintains consistency:

- - Node.js (v14 or later)
- - npm (comes with Node.js)
+ * Node.js (v14 or later)
+ * npm (comes with Node.js)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

39-39: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


40-40: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


47-50: Specify a language for fenced code blocks

Adding bash or shell to your code fences improves readability and linting:

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

Repeat for the other code blocks (lines 55–56 and 87–88).

Also applies to: 55-56, 87-88

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

47-47: 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 feb504f and b7c4953.

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

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

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


[error] 30-30: trailing spaces

(trailing-spaces)

🪛 LanguageTool
README.md

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

(NODE_JS)


[grammar] ~71-~71: “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] ~74-~74: 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

39-39: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


40-40: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


45-45: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


46-46: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


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

(MD040, fenced-code-language)


53-53: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


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

(MD040, fenced-code-language)


57-57: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


60-60: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


61-61: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


66-66: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


67-67: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


70-70: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


71-71: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


72-72: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


73-73: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


74-74: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


75-75: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


76-76: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


77-77: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


78-78: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


79-79: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


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

(MD040, fenced-code-language)

🔇 Additional comments (5)
.gitignore (1)

39-43: Ignore local configuration and Node.js artifacts correctly

The added ignore patterns for src/main/environment/common_local.properties ensure that developers’ local config copies aren’t accidentally committed, and the Node.js entries (node_modules/, npm-debug.log) align with the newly introduced tooling.

commitlint.config.js (4)

1-36: Well-structured commitlint configuration that properly enforces conventional commits standards.

The configuration extends the standard @commitlint/config-conventional preset and defines a comprehensive set of rules that will ensure consistent commit messages across the project. The rules appropriately distinguish between critical requirements (error level 2) and stylistic preferences (warning level 1).


4-8: Good balance between strictness and flexibility in message formatting rules.

Setting body and footer blank line requirements as warnings (level 1) while making length limits errors (level 2) is a sensible approach that enforces important structural constraints without being overly strict about formatting.


9-15: Appropriate subject line constraints for readable commit messages.

The subject case restrictions and prohibition of trailing periods will help maintain consistent, readable commit messages. Setting these as errors (level 2) is appropriate since the subject line is the most visible part of commit messages.


16-34: Comprehensive and standard type enumeration for conventional commits.

The type enumeration includes all standard conventional commit types and enforces lowercase formatting. This will ensure that commits are properly categorized, making the repository history more navigable and enabling automated changelog generation.

@@ -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 a shebang to ensure hook runs with the expected shell

The Husky hook script needs a shebang (e.g., #!/usr/bin/env sh) at the top so Git will execute it correctly. Without it, some environments may not recognize how to run the script.

Apply this diff:

+#!/usr/bin/env 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
npx --no -- commitlint --edit $1

Comment on lines +4 to +8
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
},
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 correctly install Husky hooks

The prepare script should invoke husky install (not just husky) so that hooks are set up after npm ci:

 "scripts": {
-   "test": "echo \"Error: no test specified\" && exit 1",
-   "prepare": "husky",
+   "test": "echo \"Error: no test specified\" && exit 1",
+   "prepare": "husky install",
    "commit": "cz"
 }
📝 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
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
"commit": "cz"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install",
"commit": "cz"
},

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 Scheduler-API

1 participant