Skip to content

Conversation

yashpatil641
Copy link

@yashpatil641 yashpatil641 commented Apr 25, 2025

📋 Description

GitHub Issue: Fixes PSMRI/AMRIT#77

This PR introduces commit message standardization for the ⁠ADMIN-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 ⁠ 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.

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting and formatting using commit hooks and GitHub Actions.
    • Added interactive commit message helper for easier adherence to commit conventions.
  • Chores

    • Updated project configuration files to support commit linting, staged file linting, and commit message standards.
    • Updated documentation with setup instructions and commit message guidelines.
  • Style

    • Ensured consistent formatting and validation of commit messages across the project.

Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This change introduces a comprehensive commit message linting and automation setup for the repository. It adds configuration and tooling for Commitlint, Husky, Commitizen, and lint-staged, ensuring that all commit messages follow the Conventional Commits standard. Husky hooks are configured to enforce commit message compliance and staged file linting locally, while a new GitHub Actions workflow checks commit messages in pull requests. The README is updated with setup instructions and commit conventions. The .gitignore is updated to exclude node_modules/. No changes are made to application logic or exported entities.

Changes

File(s) Change Summary
.github/workflows/commitlint.yml Adds a GitHub Actions workflow to lint commit messages on PR events using Commitlint.
.husky/commit-msg, .husky/pre-commit Adds Husky hooks: commit-msg to enforce commit message linting, pre-commit to run lint-staged on staged files.
commitlint.config.js Introduces Commitlint configuration enforcing Conventional Commits rules and customizes linting constraints.
package.json Adds project metadata, scripts, devDependencies for commit linting, Husky, Commitizen, and lint-staged configuration.
.gitignore Updates to ignore node_modules/ directory.
README.md Adds documentation for setting up commit hooks, commit message conventions, and Commitizen usage.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky (Local)
    participant Commitlint
    participant GitHub Actions
    participant Commitizen

    Developer->>Commitizen: (Optional) Run `npm run commit`
    Commitizen->>Developer: Prompt for commit details, generate message

    Developer->>Husky (Local): Attempt to commit
    Husky (Local)->>Commitlint: Validate commit message (commit-msg hook)
    Commitlint-->>Husky (Local): Accept/Reject commit

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

Assessment against linked issues

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

Possibly related issues

Poem

In the warren of code, where changes hop,
A rabbit ensures commits never flop.
With Husky and Commitlint, the rules are tight,
Commitizen guides you, making messages right.
GitHub Actions watch with a vigilant eye,
Only the best commits will ever fly.
🐇✨ Hooray for a history neat and spry!

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

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 (9)
.github/workflows/commitlint.yml (1)

30-30: Add trailing newline at end of file
YAML linting flags missing newline at EOF—please add a blank line after the last line.

🧰 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 (5)

51-52: Maintain list style consistency
Use * for unordered lists instead of - to follow the project's markdown conventions and satisfy MD004.

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

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

(MD004, ul-style)


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

(MD004, ul-style)


59-62: Specify code fence language
The shell snippet showing how to verify your Node.js and npm versions is missing a language identifier (MD040). Add bash (or sh) after the opening backticks:

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

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

(MD040, fenced-code-language)


64-67: Refine setup steps formatting

  1. Specify a language for the fenced block:
- ```
- npm ci
- ```
+ ```bash
+ npm ci
+ ```
  1. Use * instead of - for the child list item:
- - This will install all required dependencies including Husky and commitlint
+ * This will install all required dependencies including Husky and commitlint
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD004, ul-style)


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

(MD040, fenced-code-language)


79-88: Unify unordered list syntax
Replace leading - with * for the commit types list to comply with MD004:

- - `feat`: A new feature
- - `fix`: A bug fix
- - `docs`: Documentation changes
- - `style`: Code style changes (formatting, etc.)
- - `refactor`: Code changes that neither fix bugs nor add features
- - `perf`: Performance improvements
- - `test`: Adding or fixing tests
- - `build`: Changes to build process or tools
- - `ci`: Changes to CI configuration
- - `chore`: Other changes (e.g., maintenance tasks, dependencies)
+ * `feat`: A new feature
+ * `fix`: A bug fix
+ * `docs`: Documentation changes
+ * `style`: Code style changes (formatting, etc.)
+ * `refactor`: Code changes that neither fix bugs nor add features
+ * `perf`: Performance improvements
+ * `test`: Adding or fixing tests
+ * `build`: Changes to build process or tools
+ * `ci`: Changes to CI configuration
+ * `chore`: Other changes (e.g., maintenance tasks, dependencies)
🧰 Tools
🪛 LanguageTool

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

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)

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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


95-97: Add code fence language identifier
The example for using Commitizen needs a language tag for syntax highlighting:

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

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

(MD040, fenced-code-language)

package.json (3)

1-4: Add a license field
To align package.json metadata with the repository’s GPLv3 license, consider adding:

  "version": "1.0.0",
+ "license": "GPL-3.0",
  "scripts": {

5-5: Enhance the test script
The current "test" script simply errors out. If no npm-based tests exist, remove it or replace it with a meaningful command (e.g., mvn test for Java):

- "test": "echo \"Error: no test specified\" && exit 1",
+ "test": "mvn test",

23-25: Simplify Commitizen adapter path
You can reference the adapter by package name rather than a relative path:

- "path": "./node_modules/cz-conventional-changelog"
+ "path": "cz-conventional-changelog"

This makes the config more concise and portable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bf8de9 and 39e1b05.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .github/workflows/commitlint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • README.md (1 hunks)
  • commitlint.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] ~57-~57: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...

(NODE_JS)


[grammar] ~80-~80: “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] ~83-~83: 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

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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)


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


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)

🔇 Additional comments (2)
.gitignore (1)

39-41: Ignore node_modules directory
This ensures Node.js dependencies installed via npm are not committed to the repository.

commitlint.config.js (1)

1-36: Commitlint configuration is correct
The file properly extends the conventional commit rules and enforces header, body, and footer formatting, including type and subject constraints.

@@ -0,0 +1 @@
npx lint-staged 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 header and loader script
Husky hook scripts need a shebang and sourcing of the Husky helper for hooks to execute correctly.

Apply this diff:

+#!/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 header and loader script
Husky hook scripts require a shebang and sourcing of the Husky helper to run the commitlint command.

Apply this diff:

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

"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

Correct the Husky installation script
For Husky v7+ the prepare script must call husky install to set up Git hooks. Update as follows:

- "prepare": "husky",
+ "prepare": "husky install",

This ensures hooks are wired correctly after npm 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",

Comment on lines +17 to +21
"lint-staged": {
"src/**/*.{ts,css,html}": [
"eslint --fix"
]
},
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify lint-staged targets
The current lint-staged config only covers src/**/*.{ts,css,html}, but this is a Java service—these patterns may match nothing. Either adjust to relevant file types (e.g., .java, .xml) or remove the config. To verify which staged files match:


🏁 Script executed:

#!/bin/bash
# List staged files that lint-staged would process
git diff --cached --name-only | grep -E '\.(ts|css|html)$'

Length of output: 60


#!/bin/bash
echo "Checking for TypeScript files:"
fd --extension ts || echo "  No .ts files found"
echo ""
echo "Checking for CSS files:"
fd --extension css || echo "  No .css files found"
echo ""
echo "Checking for HTML files:"
fd --extension html || echo "  No .html files found"
echo ""
echo "Checking for Java files:"
fd --extension java || echo "  No .java files found"
echo ""
echo "Checking for XML files:"
fd --extension xml || echo "  No .xml files found"

🏁 Script executed:

#!/bin/bash
echo "Checking for TypeScript, CSS, and HTML files:"
rg --files -g '*.ts' -g '*.css' -g '*.html' || echo "  No .ts/.css/.html files found"
echo ""
echo "Checking for Java and XML files:"
rg --files -g '*.java' -g '*.xml' || echo "  No .java/.xml files found"

Length of output: 38419


Update or remove the lint-staged block in package.json
No .ts, .css, or .html files live under src/ in this Java service, so the current lint-staged config never runs. You should either:

  • Remove the entire lint-staged section from package.json, or
  • Change the glob to match files you actually want to lint (e.g. add *.java/*.xml and hook up a Java linter).

• File: package.json (lines 17–21)
Suggested removal:

-  "lint-staged": {
-    "src/**/*.{ts,css,html}": [
-      "eslint --fix"
-    ]
-  },
📝 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
"lint-staged": {
"src/**/*.{ts,css,html}": [
"eslint --fix"
]
},

@drtechie
Copy link
Member

drtechie commented May 1, 2025

@yashpatil641 can you refer to these PRs and add linting too?
PSMRI/MMU-API#76
PSMRI/MMU-API#74

@yashpatil641
Copy link
Author

@drtechie sure will make a commit

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 Admin-API
2 participants