feat(commit): setup Husky, Commitlint,Commitzen - #72
Conversation
Implemented it for FHIR-API
WalkthroughThis change introduces a comprehensive commit message linting and automation system for the repository. It adds configuration and tooling for Commitlint, Husky, Commitizen, and lint-staged, as well as a GitHub Actions workflow to enforce commit message standards on pull requests. The setup ensures that commit messages follow the Conventional Commits specification, both locally (via Git hooks) and in CI. Contributors are guided to use structured commit messages, and automated checks prevent non-compliant commits from being merged. Changes
Sequence Diagram(s)sequenceDiagram
participant Contributor
participant Husky (Local)
participant Commitlint (Local)
participant Commitizen
participant GitHub
participant GitHub Actions (CI)
participant Commitlint (CI)
Contributor->>Commitizen: Run "npm run commit" (guided commit)
Commitizen->>Contributor: Prompt for commit details
Contributor->>Husky (Local): git commit
Husky (Local)->>Commitlint (Local): Validate commit message
Commitlint (Local)-->>Husky (Local): Pass/Fail
Husky (Local)-->>Contributor: Allow/Block commit
Contributor->>GitHub: Push branch/PR
GitHub->>GitHub Actions (CI): Trigger PR workflow
GitHub Actions (CI)->>Commitlint (CI): Lint all PR commit messages
Commitlint (CI)-->>GitHub Actions (CI): Pass/Fail
GitHub Actions (CI)-->>GitHub: Report status on PR
Assessment against linked issues
Possibly related issues
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
.github/workflows/commit-lint.yml (2)
30-30: Add newline at end of file
YAML requires a trailing newline to satisfy linters and avoid subtle parsing issues.Apply this diff:
@@ run: | 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)
1-29: Consider caching dependencies to speed up CI runs
Right now, each job installs Node modules from scratch. You can add anactions/cachestep beforenpm cito reuse the lockfile andnode_modules, reducing CI time.Example addition:
- name: Cache NPM modules uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} restore-keys: | ${{ runner.os }}-npm-
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (5)
.github/workflows/commit-lint.yml(1 hunks).husky/commit-msg(1 hunks).husky/pre-commit(1 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)
🔇 Additional comments (2)
commitlint.config.js (1)
1-36: Configuration aligns with Conventional Commits standards
The rules and presets are correctly set up to enforce Conventional Commits. No issues found.package.json (1)
9-9: Commitizen script looks good
The"commit": "cz"script correctly invokes Commitizen for structured commit messages.
| @@ -0,0 +1 @@ | |||
| npx lint-staged No newline at end of file | |||
There was a problem hiding this comment.
Missing Husky initialization in pre-commit hook
The hook should include the shebang and source the Husky environment script; otherwise the hook may not execute correctly across environments.
Apply this diff to bootstrap Husky properly:
- npx lint-staged
+ #!/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.
| npx lint-staged | |
| #!/usr/bin/env sh | |
| . "$(dirname "$0")/_/husky.sh" | |
| npx lint-staged |
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "prepare": "husky", |
There was a problem hiding this comment.
Fix prepare script for Husky installation
The "prepare": "husky" script won’t initialize hooks in Husky v7+. It should be "prepare": "husky install" to set up the Git hooks.
Apply this diff:
- "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.
| "prepare": "husky", | |
| "prepare": "husky install", |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
README.md (3)
30-33: Unify Markdown list style
The prerequisites list uses dashes (-), which conflicts with the project’s Markdown convention (asterisks*) and markdownlint rules. Consider switching to a consistent list style for better readability and lint compliance.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
31-31: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
32-32: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
39-43: Add language identifier to code fence
The fenced block for verifying Node.js/npm versions lacks a language specifier. Labeling it (e.g.,bash) improves syntax highlighting and clarity.Example diff:
- ``` + ```bash🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
39-39: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
46-49: Add language identifier to code fence
Likewise, the dependency installation snippet should specify a language tag for consistency and better formatting.Example diff:
- ``` + ```bash🧰 Tools
🪛 LanguageTool
[uncategorized] ~49-~49: Possible missing comma found.
Context: ...``` - This will install all required dependencies including Husky and commitlint 3. **Ve...(AI_HYDRA_LEO_MISSING_COMMA)
🪛 markdownlint-cli2 (0.17.2)
46-46: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
49-49: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
README.md(1 hunks)package.json(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- package.json
🧰 Additional context used
🪛 LanguageTool
README.md
[uncategorized] ~37-~37: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...
(NODE_JS)
[uncategorized] ~49-~49: Possible missing comma found.
Context: ...``` - This will install all required dependencies including Husky and commitlint 3. **Ve...
(AI_HYDRA_LEO_MISSING_COMMA)
[grammar] ~63-~63: “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] ~66-~66: 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
31-31: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
32-32: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
37-37: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
38-38: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
39-39: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
45-45: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
46-46: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
49-49: 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)
58-58: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
59-59: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
62-62: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
63-63: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
64-64: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
65-65: 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)
68-68: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
69-69: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
70-70: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
🔇 Additional comments (1)
README.md (1)
26-34: Clarify Husky installation step
The setup steps rely on Husky’s hooks, but you haven’t mentioned runningnpx husky installor having a"prepare": "husky install"script inpackage.json. Without this, Husky won’t activate its Git hooks in some environments.Please verify that your
package.jsonincludes a"prepare": "husky install"script or explicitly instruct users to run:npx husky install🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
31-31: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
32-32: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
README.md (4)
25-29: Clarify Node.js usage in hook setup
The note “Even though this is a Java project, the hooks are powered by Node.js” could be more explicit about which tools require Node.js (e.g., Husky, Commitlint, lint‑staged). Consider rephrasing for clarity, for example:
“Since Husky and Commitlint are Node.js‑based, ensure Node.js is installed to power the Git hooks.”
39-42: Add language identifiers to code fences
To improve readability and syntax highlighting, specify the shell language for the fenced code blocks. For example:- ``` + ```bashApply this change to both the
node --version/npm --versionblock (lines 39–42) and thenpm ciblock (lines 46–48).Also applies to: 46-48
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
39-39: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
44-50: Comma and capitalization for readability
At line 49:“- This will install all required dependencies including Husky and commitlint”
For clarity and consistency, insert a comma and capitalize the package name:- This will install all required dependencies including Husky and commitlint + This will install all required dependencies, including Husky and Commitlint.🧰 Tools
🪛 LanguageTool
[uncategorized] ~49-~49: Possible missing comma found.
Context: ...``` - This will install all required dependencies including Husky and commitlint 3. **Ve...(AI_HYDRA_LEO_MISSING_COMMA)
🪛 markdownlint-cli2 (0.17.2)
45-45: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
46-46: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
49-49: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
61-71: Align unordered list style with markdownlint
The commit types list currently uses dashes (-). According to the project’s markdown style (MD004), consider switching to asterisks (*) for unordered items. Example:- - `feat`: A new feature - - `fix`: A bug fix + * `feat`: A new feature + * `fix`: A bug fix ...🧰 Tools
🪛 LanguageTool
[grammar] ~63-~63: “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] ~66-~66: Loose punctuation mark.
Context: ... changes (formatting, etc.) -refactor: Code changes that neither fix bugs nor ...(UNLIKELY_OPENING_PUNCTUATION)
🪛 markdownlint-cli2 (0.17.2)
62-62: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
63-63: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
64-64: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
65-65: 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)
68-68: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
69-69: 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)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
README.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[uncategorized] ~37-~37: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...
(NODE_JS)
[uncategorized] ~49-~49: Possible missing comma found.
Context: ...``` - This will install all required dependencies including Husky and commitlint 3. **Ve...
(AI_HYDRA_LEO_MISSING_COMMA)
[grammar] ~63-~63: “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] ~66-~66: 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
31-31: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
32-32: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
37-37: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
38-38: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
39-39: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
45-45: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
46-46: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
49-49: 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)
58-58: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
59-59: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
62-62: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
63-63: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
64-64: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
65-65: 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)
68-68: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
69-69: 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)
🔇 Additional comments (2)
README.md (2)
30-33: Prerequisites section looks good
Listing Node.js (v14+) and npm is clear and accurate.🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
31-31: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
32-32: Unordered list style
Expected: asterisk; Actual: dash(MD004, ul-style)
73-73: Commit validation note is clear
The final reminder that commits are automatically validated upon commit is concise and helpful.



Implemented it for FHIR-API
📋 Description
JIRA ID: N/A
GitHub Issue: Fixes PSMRI/AMRIT#89
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.
PS : @drtechie @Sneha6003 Implemented with the same standardization as for the UI repositories to ensure , clean code and well maintained code .
✅ Type of Change
ℹ️ 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 commitizencz-conventional-changelogTesting & 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.
Screenshots
Summary by CodeRabbit
Summary by CodeRabbit