Skip to content

Conversation

@yashpatil641
Copy link

@yashpatil641 yashpatil641 commented Apr 21, 2025

📋 Description

GitHub Issue: Fixes PSMRI/AMRIT#76

This PR introduces commit message standardization for the ⁠ FHIR-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 pre-commit code quality checks to enforce consistent commit standards.
    • Added interactive commit message creation using Commitizen for easier compliance with conventions.
  • Documentation

    • Expanded the README with detailed setup instructions for commit hooks and commit message conventions.
  • Chores

    • Added configuration files and scripts for commit linting, Git hooks, and code quality enforcement.
    • Updated .gitignore to exclude node_modules/.

@coderabbitai
Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

This pull request introduces commit message linting and automation to the project. It adds configuration and tooling for Commitlint, Husky, Commitizen, and lint-staged, along with a GitHub Actions workflow to enforce commit message standards on pull requests. The .gitignore is updated to exclude node_modules/, and the README is extended with setup and usage instructions for the new commit workflow. Husky hooks are configured for local pre-commit and commit-msg validation, and Commitizen is set up for guided commit message creation.

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 runs Commitlint on commit messages; pre-commit runs lint-staged.
.gitignore Adds rule to ignore node_modules/ with a clarifying comment.
commitlint.config.js Introduces Commitlint configuration enforcing conventional commit rules.
package.json Adds Node.js project metadata, scripts, devDependencies (Commitlint, Husky, Commitizen, lint-staged), and related configurations.
README.md Adds a section detailing setup and usage of commit hooks, Commitlint, Husky, and Commitizen.

Sequence Diagram(s)

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

    Developer->>Commitizen: Run "npm run commit"
    Commitizen->>Developer: Prompt for commit details
    Developer->>Husky (Local): git commit
    Husky (Local)->>Commitlint (Local): Validate commit message
    Commitlint (Local)-->>Husky (Local): Pass/Fail
    Husky (Local)-->>Developer: Allow/Block commit

    Developer->>GitHub: Push branch / open PR
    GitHub->>GitHub Actions: Trigger workflow on PR event
    GitHub Actions->>Commitlint (CI): Lint commit messages in PR
    Commitlint (CI)-->>GitHub Actions: Pass/Fail
    GitHub Actions-->>GitHub: Report status on PR
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate Commitlint to enforce commit message standards (#76)
Set up Husky to trigger commit-msg hooks (#76)
Add Commitizen for structured commit prompts (#76)
Configure GitHub Actions to verify commit format in PRs (#76)
Ensure compatibility with existing CI/CD workflows (#76)

Possibly related issues

Suggested reviewers

  • drtechie

Poem

In the warren where code bunnies dwell,
Commit messages must be written well.
With Husky and Commitlint, no more fright—
Each commit’s format is perfectly right!
Commitizen guides with a gentle paw,
And GitHub Actions enforces the law.
🐇✨ Hopping forward, clean and bright!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


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

@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 (5)
commitlint.config.js (1)

2-35: Consider enforcing scope formatting.

To further standardize commit messages, you may add a scope-case rule to enforce lowercase scopes:

 module.exports = {
   extends: ['@commitlint/config-conventional'],
   rules: {
+    'scope-case': [2, 'always', 'lower-case'],
     'body-leading-blank': [1, 'always'],
     // ...
   },
 };
README.md (2)

26-29: Specify fenced code block languages
To comply with markdownlint and improve readability, add a language identifier to each fenced code block. For example:

- ```
+ ```bash

Also applies to: 32-34, 62-64

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)


30-39: Document the pre-commit hook (lint-staged) setup
The README covers the commit-msg hook but omits instructions for the pre-commit hook provided by lint-staged. Since you’ve added a .husky/pre-commit hook and a lint-staged configuration in package.json, consider adding a step under Setup Steps such as:

npx husky add .husky/pre-commit "npx lint-staged"

and how to verify it. This will help contributors enforce code quality before they commit.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)

package.json (2)

17-19: Align lint-staged globs with your project files
The lint-staged config targets .ts, .css, and .html under src/, but this is a Java-based repo. Update these patterns to match your actual source files (e.g., **/*.java) or remove the section if you don’t plan to lint-staged code.


21-23: Simplify Commitizen adapter path
You can reference the adapter by its package name rather than a relative path for clarity and maintainability.

-      "path": "./node_modules/cz-conventional-changelog"
+      "path": "cz-conventional-changelog"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d14705b and 9419b2f.

⛔ 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] ~24-~24: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...

(NODE_JS)


[grammar] ~47-~47: “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] ~50-~50: 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

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)

🔇 Additional comments (2)
.gitignore (1)

34-35: Verify .gitignore addition for Node.js modules.

Adding node_modules/ is correct to prevent committing dependencies. Ensure this entry is committed in the appropriate section or consider grouping under a dedicated Node.js heading for clarity.

commitlint.config.js (1)

1-36: Configuration appears correct.

The commitlint rules comprehensively enforce conventional commits. Line-length limits, subject casing, and type constraints align with best practices.

@@ -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 the standard Husky hook header.

Husky hook scripts require a shebang and invocation of the Husky environment helper to execute properly. Without this header, the npx lint-staged command may not run as expected.

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 the standard Husky hook header.

Similar to the pre-commit hook, the commit-msg script needs the Husky shebang and environment setup. Without it, commit message linting may not be triggered locally.

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

Comment on lines +1 to +30
name: Commit Compliance

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
commitlint:
runs-on: ubuntu-latest

steps:
- name: Checkout code with submodule
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install dependencies
run: npm ci --legacy-peer-deps

- name: Run commitlint on PR
run: |
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose 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

Ensure newline at end of file to satisfy YAML linting.

YAML parsers require a trailing newline. Add an empty line after the last line to resolve the new-line-at-end-of-file lint error.

🧰 Tools
🪛 YAMLlint (1.35.1)

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

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

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

🛠️ Refactor suggestion

Use the recommended Husky install command
Husky v7+ requires "prepare": "husky install" to initialize Git hooks after dependencies are installed. The current "prepare": "husky" script may not install the hooks as expected.

-   "prepare": "husky",
+   "prepare": "husky 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",

@drtechie
Copy link
Member

drtechie commented May 1, 2025

@yashpatil641
PSMRI/MMU-API#76
PSMRI/MMU-API#74

please refer to these PRs and add linting of Java files.

@yashpatil641
Copy link
Author

@drtechie sure will make a commit

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

♻️ Duplicate comments (1)
package.json (1)

6-6: Use the recommended Husky install command
Husky v7+ expects the prepare script to be husky install for proper hook setup.

🧹 Nitpick comments (1)
package.json (1)

19-19: Remove trailing space in Checkstyle command
The extra space after checkstyle.xml can break the command.

- "**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml "]
+ "**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml"]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9419b2f and 3c850cc.

📒 Files selected for processing (1)
  • package.json (1 hunks)

Comment on lines +17 to +21
"lint-staged": {
"src/**/*.{ts,css,html,js}": ["eslint --fix"],
"**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml "],
"**/*.xml": ["xmllint --noout"]
},
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 Checkstyle configuration files
You've added Checkstyle within lint-staged, but ensure that checkstyle.jar and checkstyle.xml are present at the expected path so the hook doesn’t fail.

Please run:


🏁 Script executed:

#!/bin/bash
# Confirm Checkstyle files exist in repo root
if [[ -f checkstyle.jar && -f checkstyle.xml ]]; then
  echo "✅ checkstyle.jar and checkstyle.xml found"
else
  echo "❌ Missing checkstyle.jar or checkstyle.xml"
  exit 1
fi

Length of output: 129


🏁 Script executed:

#!/usr/bin/env bash
# Search for Checkstyle files anywhere in the repository
echo "🔍 Locating checkstyle.xml and checkstyle.jar in the repo..."
rg -l "checkstyle.xml" || true
rg -l "checkstyle.jar" || true

Length of output: 202


Missing Checkstyle configuration files in repository root
The lint-staged hook is referencing checkstyle.jar and checkstyle.xml, but neither file exists in the repo. Without these, running java -jar checkstyle.jar -c checkstyle.xml will always fail.

Please ensure the following files are committed at the repository root (or update paths accordingly):

  • checkstyle.jar
  • checkstyle.xml

If you intend to store them elsewhere, adjust the lint-staged entry in package.json to point to the correct relative paths.

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

2 participants