-
Notifications
You must be signed in to change notification settings - Fork 30
feat(commit): setup husky commitlint and commitzen #74
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 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 Changes
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
Assessment against linked issues
Possibly related issues
Poem
✨ Finishing Touches
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:
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 (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). Addbash
(orsh
) 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
- Specify a language for the fenced block:
- ``` - npm ci - ``` + ```bash + npm ci + ```
- 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 alicense
field
To alignpackage.json
metadata with the repository’s GPLv3 license, consider adding:"version": "1.0.0", + "license": "GPL-3.0", "scripts": {
5-5
: Enhance thetest
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
⛔ 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 |
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 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.
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 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.
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", |
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.
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.
"prepare": "husky", | |
"prepare": "husky install", |
"lint-staged": { | ||
"src/**/*.{ts,css,html}": [ | ||
"eslint --fix" | ||
] | ||
}, |
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 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.
"lint-staged": { | |
"src/**/*.{ts,css,html}": [ | |
"eslint --fix" | |
] | |
}, |
@yashpatil641 can you refer to these PRs and add linting too? |
@drtechie sure will make a commit |
📋 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:
✅ 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
Chores
Style