-
Notifications
You must be signed in to change notification settings - Fork 14
feat(commit): setup husky commitlint and commitzen #20
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis 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 Changes
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
Assessment against linked issues
Possibly related issues
Suggested reviewers
Poem
Tip ⚡️ Faster reviews with caching
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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-caserule 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:- ``` + ```bashAlso 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-commithook and alint-stagedconfiguration inpackage.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
Thelint-stagedconfig targets.ts,.css, and.htmlundersrc/, 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
⛔ Files ignored due to path filters (1)
package-lock.jsonis 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.gitignoreaddition 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 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| npx --no -- commitlint --edit "$1" | |
| #!/usr/bin/env sh | |
| . "$(dirname "$0")/_/husky.sh" | |
| npx --no -- commitlint --edit "$1" |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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", |
There was a problem hiding this comment.
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.
| "prepare": "husky", | |
| "prepare": "husky install", |
|
@yashpatil641 please refer to these PRs and add linting of Java files. |
|
@drtechie sure will make a commit |
There was a problem hiding this 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 thepreparescript to behusky installfor proper hook setup.
🧹 Nitpick comments (1)
package.json (1)
19-19: Remove trailing space in Checkstyle command
The extra space aftercheckstyle.xmlcan break the command.- "**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml "] + "**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml"]
| "lint-staged": { | ||
| "src/**/*.{ts,css,html,js}": ["eslint --fix"], | ||
| "**/*.java": ["java -jar checkstyle.jar -c checkstyle.xml "], | ||
| "**/*.xml": ["xmllint --noout"] | ||
| }, |
There was a problem hiding this comment.
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
fiLength 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" || trueLength 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.
📋 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:
✅ 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 commitizen cz-conventional-changelog Testing & Validation
Summary by CodeRabbit
New Features
Documentation
Chores
.gitignoreto excludenode_modules/.