Skip to content

feat(commit): setup Husky, Commitlint,Commitzen #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

blazethunderstorm
Copy link

@blazethunderstorm blazethunderstorm commented Apr 19, 2025

Implemented it for Common-API

📋 Description

JIRA ID: Fixes PSMRI/AMRIT#79

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, improving collaboration, readability,
and enabling future automation (like changelogs and versioning).

These tools are now integrated:

  • Commitlint enforces the conventional commit message structure.
  • Husky prevents non-compliant commits by using Git hooks.
  • Commitizen provides an interactive CLI for making properly formatted commits.
  • GitHub Actions validate commit messages for all pull requests.

PS: Implemented with the same standardization as for the UI repositories to ensure clean and well-maintained code.

✅ 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 the following 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.

PROOF(SCREENSHOTS)

image

image

Summary by CodeRabbit

  • New Features

    • Introduced automated commit message linting on pull requests and during local commits to enforce
      consistent commit message standards.
    • Added pre-commit checks to automatically lint and format staged files for improved code quality.
  • Chores

    • Added project configuration files for commit message linting, code formatting, and development
      dependencies management.
    • Enhanced documentation with setup instructions for commit hooks and commit message conventions.

Summary by CodeRabbit

  • New Features
    • Introduced automated commit message validation for pull requests and local commits.
    • Added Git hooks for commit message and pre-commit checks to ensure code quality and commit consistency.
    • Provided configuration for standardized commit message formatting.
  • Documentation
    • Updated README with detailed project information, setup instructions, and commit message guidelines.
  • Chores
    • Updated .gitignore to exclude node_modules/ and .history/ directories.

Copy link
Contributor

coderabbitai bot commented Apr 19, 2025

Walkthrough

This update introduces automated commit message linting and developer tooling to the project. It adds configuration and scripts for Commitlint, Husky, Commitizen, and lint-staged to enforce conventional commit message standards and code quality checks. A GitHub Actions workflow is set up to validate commit messages on pull requests. The README is rewritten to reflect the new focus on healthcare interoperability and includes detailed setup instructions for the new developer tools. No changes are made to application code or exported entities; all modifications are related to configuration, automation, and documentation.

Changes

Files/Paths Change Summary
.github/workflows/commit-lint.yml Adds a GitHub Actions workflow to lint commit messages on pull request events using Commitlint.
.husky/commit-msg, .husky/pre-commit Introduces Husky Git hooks: commit-msg for Commitlint validation, pre-commit for lint-staged checks.
commitlint.config.js Adds Commitlint configuration enforcing strict conventional commit message standards.
package.json Adds project metadata, scripts for Commitizen and Husky, lint-staged config, and developer dependencies.
README.md Rewrites documentation to focus on healthcare interoperability, adds commit hook/tooling setup instructions.
.gitignore Updates to ignore node_modules/ and .history/ directories.

Sequence Diagram(s)

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

    Developer->>Commitizen (Local): Run "npm run commit"
    Commitizen (Local)->>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 / create PR
    GitHub->>GitHub Actions: Trigger commit-lint workflow
    GitHub Actions->>Commitlint (CI): Lint commit messages in PR
    Commitlint (CI)-->>GitHub Actions: Pass/Fail
    GitHub Actions-->>GitHub: Report PR status
Loading

Assessment against linked issues

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

Possibly related issues

Poem

In the garden of code, a new rule takes flight,
With Husky and Commitlint keeping things right.
Commitizen hops in, with prompts so neat—
Ensuring our messages are tidy and sweet.
On every PR, GitHub Actions will check,
So our commit history is a well-groomed trek.
🐇✨ Hooray for clean code—now, onward we leap!

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

🧹 Nitpick comments (6)
README.md (6)

1-4: Refine introductory section for clarity and grammar

Consider adding a comma after “systems” (line 3) for readability and inserting “the” before “rest of the 18 resources” (line 4). For example:

- COMMON-PAI provides a means for representing and sharing information among clinicians and organizations in a standard way regardless of how it is stored in those systems.
+ COMMON-PAI provides a means for representing and sharing information among clinicians and organizations in a standard way, regardless of how it is stored in those systems.

- Contributors are working on developing rest of the 18 resources which will make AMRIT to be compliant with ABDM guidelines.
+ Contributors are working on developing the rest of the 18 resources, which will make AMRIT compliant with ABDM guidelines.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...nicians and organizations in a standard way regardless of the ways local EHRs repre...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ...on, while being flexible enough to meet needs of a wide variety of use cases within t...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~4-~4: You might be missing the article “the” here.
Context: ... Contributors are working on developing rest of the 18 resources which will make AMR...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


26-27: Unify list marker style

The prerequisites list uses dashes (-) for bullets. Consider using a consistent style (e.g., asterisks *) throughout the README to align with markdownlint expectations.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD004, ul-style)


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

(MD004, ul-style)


31-37: Specify shell language in code fences

The version checks are wrapped in a code fence without a language specifier. Add bash (or sh) for syntax highlighting:

-    ```
+    ```bash
     node --version
     npm --version
     ```
🧰 Tools
🪛 LanguageTool

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

(NODE_JS)

🪛 markdownlint-cli2 (0.17.2)

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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)


38-43: Specify shell language in dependency installation snippet

Similarly, the npm ci snippet should be language-tagged:

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

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

(MD004, ul-style)


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

(MD040, fenced-code-language)


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

(MD004, ul-style)


45-46: Unify list marker style in verification steps

The verification steps also use dashes for bullets. For consistency (and to satisfy markdownlint), switch to asterisk-style bullets.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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-53: Verify commit types against configuration and add Commitizen usage

Ensure that the types listed here exactly match those in commitlint.config.js. Also consider adding a note on using Commitizen’s interactive CLI, for example:

+ 4. **Create conventional commits**
+    - Use Commitizen to scaffold commits:
+      ```bash
+      npm run commit
+      ```
🧰 Tools
🪛 LanguageTool

[grammar] ~53-~53: “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)

🪛 markdownlint-cli2 (0.17.2)

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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6af44ba and c711b15.

⛔ 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)
  • .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
🪛 LanguageTool
README.md

[uncategorized] ~3-~3: Possible missing comma found.
Context: ...nicians and organizations in a standard way regardless of the ways local EHRs repre...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ...on, while being flexible enough to meet needs of a wide variety of use cases within t...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~4-~4: You might be missing the article “the” here.
Context: ... Contributors are working on developing rest of the 18 resources which will make AMR...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


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

(NODE_JS)


[grammar] ~53-~53: “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] ~56-~56: 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

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)


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

(MD004, ul-style)


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

(MD040, fenced-code-language)


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


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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

(MD004, ul-style)


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


73-73: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)

🔇 Additional comments (3)
.github/workflows/commit-lint.yml (1)

1-31: Workflow correctly validates commit messages

The GitHub Actions workflow is properly configured to trigger on pull requests, check out the correct ref (including submodules), set up Node.js, install dependencies, and run commitlint between the base and head SHAs. It meets the objective of enforcing commit message standards in CI.

commitlint.config.js (1)

1-43: Commitlint configuration looks solid

The config extends the conventional preset, enforces body/footer/header length, and restricts types and scopes (including the new git-hooks scope). All rules align with the PR objective to standardize commit messages.

README.md (1)

21-24: Commit hooks introduction looks good

The new “Setting Up Commit Hooks” section clearly explains the Node‑powered Git hooks for a Java project and outlines the setup steps. No changes needed here.

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

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add Husky hook boilerplate header

Husky hook scripts require a shebang and sourcing of the Husky runner. Please add at the top of this file before the npx --no -- commitlint --edit $1 line:

#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the Husky prepare script

Husky v7+ uses husky install to setup Git hooks. The current "prepare": "husky" will not install them. Update as follows:

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

Comment on lines +5 to +12
### Key APIs in COMMON-PAI service
* Care Context Services
* e-Aushadhi
* ABHA Card Services
* OP Consultation Record Sharing
* Diagnostic Report Record Sharing
* Prescription Record Sharing
* Higher Health Facility
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Adjust heading level and improve content hierarchy

The “Key APIs in COMMON-PAI service” section uses an H3 (###) right after an H1 (#), skipping H2. For better hierarchy and consistency, change it to H2 (##):

- ### Key APIs in COMMON-PAI service
+ ## Key APIs in COMMON-PAI service
📝 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
### Key APIs in COMMON-PAI service
* Care Context Services
* e-Aushadhi
* ABHA Card Services
* OP Consultation Record Sharing
* Diagnostic Report Record Sharing
* Prescription Record Sharing
* Higher Health Facility
## Key APIs in COMMON-PAI service
* Care Context Services
* e-Aushadhi
* ABHA Card Services
* OP Consultation Record Sharing
* Diagnostic Report Record Sharing
* Prescription Record Sharing
* Higher Health Facility
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

@drtechie
Copy link
Member

drtechie commented May 9, 2025

@blazethunderstorm reminder to update the PR.

@blazethunderstorm
Copy link
Author

blazethunderstorm commented May 9, 2025

Yeah will do it today

Copy link

sonarqubecloud bot commented May 9, 2025

@blazethunderstorm
Copy link
Author

@drtechie i have made the required changes

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c711b15 and b00f655.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • .husky/pre-commit (1 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • .gitignore
  • package.json

Comment on lines +1 to +4
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect hook type for commitlint command

There appears to be a hook type mismatch. This file is named pre-commit, but the command being run (commitlint --edit ${1}) is typically used in a commit-msg hook, not a pre-commit hook.

Pre-commit hooks run before the commit message is created and are intended for code quality checks like linting and testing. The commit message (${1}) isn't available at this pre-commit stage.

For proper implementation:

  • A pre-commit hook should run commands like lint-staged or other code quality checks
  • The commitlint command should be in a commit-msg hook file instead
 #!/usr/bin/env sh
 . "$(dirname -- "$0")/_/husky.sh"
 
-npx --no -- commitlint --edit ${1}
+npx lint-staged

And ensure you have a separate .husky/commit-msg file containing:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}

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