-
Notifications
You must be signed in to change notification settings - Fork 24
Feat/linting : Added Commitlint , Commitzen , Husky configuration #54
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: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdds commit message linting and local git hooks (Commitlint, Husky, Commitizen), a GitHub Actions "Commit Compliance" workflow for PRs, updates .gitignore, package.json, commitlint config, Husky hooks, README documentation, and includes an unchanged test-coverage workflow file. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant Git as Local Git
participant Husky as Husky Hooks
participant LintStaged as lint-staged
participant Commitlint as Commitlint
participant Remote as Remote Repo
participant GH as GitHub Actions
Dev->>Git: git add & git commit
Git->>Husky: trigger pre-commit
Husky->>LintStaged: run lint-staged
LintStaged-->>Husky: pass/fail
Git->>Husky: trigger commit-msg
Husky->>Commitlint: npx commitlint --edit <msg>
Commitlint-->>Husky: pass/fail
alt local pass
Husky-->>Git: allow commit
Dev->>Remote: push / open PR
GH->>GH: run Commit Compliance workflow
GH->>GH: checkout, setup Node, npm install, run commitlint on PR range
GH-->>Remote: status (pass/fail)
else local fail
Husky-->>Git: block commit
end
sequenceDiagram
autonumber
actor Dev as Developer
participant GH as GitHub
participant Cov as Coverage Workflow
participant Maven as Maven
participant Art as Artifact
Dev->>GH: open/sync PR
GH->>Cov: trigger coverage workflow
Cov->>Cov: checkout, restore caches
Cov->>Maven: mvn build & test, generate JaCoCo
Maven-->>Cov: produce reports
Cov->>Art: upload coverage artifact / comment PR
Cov-->>GH: job status
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
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 (2)
README.md (1)
44-55: Add fenced-code languages for shell snippetsMarkdown lint is currently flagging these code fences. Annotate both shell command blocks (the Node.js/npm checks and the npm install) with an explicit language such as
bashto quiet the linter and improve readability.- ``` + ```bash node --version npm --version ``` … - ``` + ```bash npm ci ```Also applies to: 52-57
.github/workflows/commit-lint.yml (1)
25-28: Drop the redundantnpm install.
npm cialready installs dependencies from the lockfile. Following it withnpm iredoes the work, can mutate the lock, and runs the Huskypreparescript twice. Keeping justnpm ci --legacy-peer-depswill be faster and more deterministic.
📜 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 (8)
.github/workflows/commit-lint.yml(1 hunks).github/workflows/testcase-coverage.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
🧠 Learnings (2)
📚 Learning: 2025-04-18T12:26:29.228Z
Learnt from: rohan-019
PR: PSMRI/BeneficiaryID-Generation-API#30
File: .commitlintrc.json:9-13
Timestamp: 2025-04-18T12:26:29.228Z
Learning: In commitlint configuration, there is no explicit "imperative-case" option. The conventional approach to enforce imperative-style commit messages is to configure the "subject-case" rule to exclude other case types like sentence-case, start-case, pascal-case, and upper-case. This effectively guides users toward writing commits in imperative form.
Applied to files:
commitlint.config.js
📚 Learning: 2025-04-25T16:51:01.969Z
Learnt from: G4URAV001
PR: PSMRI/BeneficiaryID-Generation-API#33
File: .husky/commit-msg:1-1
Timestamp: 2025-04-25T16:51:01.969Z
Learning: When using npx with commitlint in Git hooks, the correct flag to prevent automatic installation is `--no-install` (not `--no`), and the commit file parameter ($1) should be quoted as "$1" to handle filenames with spaces properly.
Applied to files:
.husky/commit-msg
🪛 markdownlint-cli2 (0.18.1)
README.md
47-47: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
53-53: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🪛 actionlint (1.7.7)
.github/workflows/testcase-coverage.yml
34-34: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (3)
package.json (1)
14-20: Confirmxmllintavailability before enforcing this hook.
lint-stagedwill now invokexmllint --noouton staged XML files. On many contributor environments (especially Windows)xmllintis not present by default, so this hook would fail every commit until they install system-level libxml2 tooling. Can you confirm that we already provisionxmllintacross dev/CI environments or document/bundle it accordingly?.gitignore (1)
33-34: Solid ignore additions for tooling artifactsGood call on ignoring
node_modules; this will prevent local Commitizen/commitlint installs from polluting the repo. Section header keeps things readable.commitlint.config.js (1)
9-34: Well-scoped commit message guardrailsThe subject-case rule disallowing sentence/start/pascal/upper cases nicely enforces the imperative style we discussed in past reviews, and the type enum covers the expected workflow. Looks ready for Husky + CI usage.
.husky/commit-msg
Outdated
| @@ -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.
Fix commit-msg hook command
Same problem here: the missing shebang prevents execution, and npx --no -- is an invalid flag (it should be --no-install). Quote $1 so commit messages with spaces don’t break the command.
-npx --no -- commitlint --edit $1
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+
+npx --no-install 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 | |
| #!/bin/sh | |
| . "$(dirname "$0")/_/husky.sh" | |
| npx --no-install commitlint --edit "$1" |
🤖 Prompt for AI Agents
In .husky/commit-msg around line 1 the hook command is non-executable and uses
an invalid npx flag and an unquoted positional parameter; add a proper shebang
(#!/bin/sh or #!/bin/bash) as the first line, replace the invalid flag with
--no-install for npx, and quote the positional parameter as "$1" so commit
messages with spaces are passed correctly.
.husky/pre-commit
Outdated
| @@ -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.
Restore Husky shim and npx invocation
The hook file is missing the shebang and Husky bootstrap line, so Git will fail to execute it (exec format error). Add the standard Husky template and use --no-install to prevent npx from hitting the network.
- npx lint-staged
+#!/bin/sh
+. "$(dirname "$0")/_/husky.sh"
+
+npx --no-install 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 | |
| #!/bin/sh | |
| . "$(dirname "$0")/_/husky.sh" | |
| npx --no-install lint-staged |
🤖 Prompt for AI Agents
In .husky/pre-commit around lines 1 to 1, the hook is missing the required
shebang and Husky bootstrap line which causes exec format errors; restore the
standard Husky template by adding the top-line shebang (#!/bin/sh) and the Husky
bootstrap invocation (e.g., . "$(dirname "$0")/_/husky.sh"), then call
lint-staged with npx using the --no-install flag (npx --no-install lint-staged)
to avoid network installs.
| 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 | ||
| npm i --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 |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
|
@Zapper9982 can you please check code rabbit comments? |
|
@drtechie sure will do it by eod |
|
@Zapper9982 gentle reminder |
|
@drtechie , the coderabbit comment is talking about complying with latest , but according to husky docs. i think the use of that is unnecessary . |




Implemented it for BeneficiaryID-Generation-API
📋 Description
JIRA ID: N/A
GitHub Issue: Fixes PSMRI/AMRIT#88
This PR introduces commit message standardization for the Scheduler-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
Chores
Documentation