-
Notifications
You must be signed in to change notification settings - Fork 24
feat(beneficiaryid-generation-api): implement commit message linting and automation #33
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 standardized commit message enforcement system into the project. It adds configuration and tooling for commit message linting using Commitlint, integrates Husky for Git hooks, and sets up Commitizen for guided commit creation. A GitHub Actions workflow is added to automatically validate commit messages on pull requests. The Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Husky
participant Commitlint
participant GitHub Actions
Developer->>Husky: git commit
Husky->>Commitlint: Lint commit message
Commitlint-->>Husky: Pass/Fail
Husky-->>Developer: Allow/Block commit
Developer->>GitHub Actions: Open/sync PR
GitHub Actions->>Commitlint: Lint commits in PR
Commitlint-->>GitHub Actions: Pass/Fail
GitHub Actions-->>Developer: Status check result
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: 3
🔭 Outside diff range comments (1)
README.md (1)
9-11:⚠️ Potential issueFix hyperlink formatting
The extra space breaks the Markdown link syntax, so the URL won’t render as a link.- Find the detailed list of software dependencies [here] (https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup/software-dependencies) . + Find the detailed list of software dependencies [here](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup/software-dependencies).🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
10-10: Bare URL used
null(MD034, no-bare-urls)
🧹 Nitpick comments (5)
.gitignore (1)
31-31: Scope the local properties ignore to its directory
Usingbengen_local.propertiesalone will match any file with that name. To avoid unintentionally ignoring files elsewhere, specify the path:- bengen_local.properties + src/main/environment/bengen_local.properties.github/workflows/commit-lint.yml (1)
25-27: Speed up CI by caching npm modules
Installing dependencies on every run can be slow. Consider caching the npm cache between jobs:- - name: Install dependencies - run: npm ci --legacy-peer-deps + - name: Cache npm modules + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install dependencies + run: npm ci --legacy-peer-depspackage.json (1)
10-12: Use module name for Commitizen adapter path
Referencing the package by name improves maintainability and avoids path issues:- "path": "./node_modules/cz-conventional-changelog" + "path": "cz-conventional-changelog"README.md (1)
43-46: Specify language for fenced code blocks
Adding a language identifier (e.g.,bash,sh) enables syntax highlighting and improves readability.- ``` + ```bash node --version npm --version - ``` + ```Apply the same change to the other code fences in this section.
Also applies to: 50-52, 82-84
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
43-43: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
commitlint.config.js (1)
16-34: Commit type constraints are comprehensive
type-case,type-empty, andtype-enumrestrict commit types to lowercase and a well-defined set. Consider optionally addingscope-case: [2, 'always', 'lower-case']orscope-empty: [2, 'never']if you want to enforce consistent scope usage across commits.
📜 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 (6)
.github/workflows/commit-lint.yml(1 hunks).gitignore(1 hunks).husky/commit-msg(1 hunks)README.md(2 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)
[error] 30-30: trailing spaces
(trailing-spaces)
🪛 LanguageTool
README.md
[uncategorized] ~41-~41: The official spelling of this programming framework is “Node.js”.
Context: ...d npm** - Download and install from nodejs.org - Verify i...
(NODE_JS)
[grammar] ~67-~67: “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] ~70-~70: 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
35-35: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
36-36: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
41-41: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
42-42: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
43-43: 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)
50-50: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
53-53: 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)
62-62: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
63-63: 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)
72-72: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
73-73: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
74-74: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
75-75: Unordered list style
Expected: asterisk; Actual: dash
(MD004, ul-style)
82-82: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
🔇 Additional comments (3)
commitlint.config.js (3)
1-3: Extends conventional commit rules
Theextendsfield correctly pulls in@commitlint/config-conventionalto enforce standard commit conventions.
4-8: Validate body and footer formatting
Rules forbody-leading-blank,body-max-line-length,footer-leading-blank,footer-max-line-length, andheader-max-lengthare set with appropriate severity and line-length caps.
9-15: Enforce subject style
Thesubject-case,subject-empty, andsubject-full-stoprules ensure subjects are concise, non-empty, and without trailing periods.
| @@ -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.
Ensure Husky hook loads correctly and has valid shebang
The hook currently only calls npx --no -- commitlint --edit $1 without a shebang or sourcing Husky’s loader. Without these, the script might not execute properly in the Git hook context.
Apply this diff:
- npx --no -- commitlint --edit $1
+ #!/usr/bin/env 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 | |
| #!/usr/bin/env sh | |
| . "$(dirname "$0")/_/husky.sh" | |
| npx --no-install commitlint --edit "$1" |
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.
I would like to point out that the shebang (#!/usr/bin/env sh) and the sourcing of the Husky helper script (. "$(dirname "$0")/_/husky.sh") are now deprecated.
As of Husky v9.1.1, these lines are automatically removed during installation, and they will fail in Husky v10.0.0.
For compatibility with future versions of Husky, it’s recommended to remove these lines from the hook script.
The message from husky.sh -
echo "husky - DEPRECATED
Please remove the following two lines from $0:
#!/usr/bin/env sh
. \"\$(dirname -- \"\$0\")/_/husky.sh\"
They WILL FAIL in v10.0.0
"
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.
@G4URAV001 You're absolutely right. The --no flag is incorrect, and --no-install is the proper flag to prevent npx from installing packages if they're not found locally. Quoting the $1 parameter is also good practice to handle filenames with spaces correctly.
The suggested change looks good:
npx --no-install commitlint --edit "$1"
✏️ Learnings added
Learnt from: G4URAV001
PR: PSMRI/BeneficiaryID-Generation-API#33
File: .husky/commit-msg:1-1
Timestamp: 2025-04-25T16:51:01.946Z
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.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
|
|
||
| - 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.
Add newline at EOF and remove trailing spaces
YAML requires a newline at end-of-file and no trailing spaces; otherwise, the workflow may fail to parse.
- npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+ npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
+📝 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 commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose | |
| 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)
[error] 30-30: trailing spaces
(trailing-spaces)
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "prepare": "husky", | ||
| "commit": "cz" |
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 Husky installation command
The prepare script uses husky, but the recommended command is husky install. Please confirm that running npm run prepare correctly sets up the .husky directory.
Run:
Ensure the hooks directory and scripts are installed.
🏁 Script executed:
npm run prepare
ls -la .huskyLength of output: 280
Update prepare script to use husky install
Running npm run prepare currently errors with “husky: not found,” so the hooks aren’t being initialized correctly. Change the prepare script in package.json to invoke husky install.
• File: package.json
• Lines: 5–7
Suggested diff:
"test": "echo \"Error: no test specified\" && exit 1",
- "prepare": "husky",
+ "prepare": "husky install",
"commit": "cz"📝 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.
| "test": "echo \"Error: no test specified\" && exit 1", | |
| "prepare": "husky", | |
| "commit": "cz" | |
| "test": "echo \"Error: no test specified\" && exit 1", | |
| "prepare": "husky install", | |
| "commit": "cz" |



📋 Description
Closes PSMRI/AMRIT#88
JIRA ID: issue link
This PR implements commit message linting and automation for all contributors in the API repositories using Commitlint, Husky, and Commitizen. The aim of this initiative is to enforce a consistent and readable commit history, improving collaboration and enabling future automated changelogs and CI/CD processes. This setup aligns with the practices followed across all C4GT Community repositories.
Every commit in API repositories will follow the defined structure (e.g., Conventional Commits).
Husky will block non-compliant commit messages locally.
Contributors will use Commitizen (cz) to follow a guided commit format.
GitHub Actions will fail PR checks if commit messages do not follow the required format.
All changes will be compatible with the existing CI/CD pipelines, ensuring smooth integration.
✅ 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/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.
Summary by CodeRabbit
New Features
Documentation
Chores