-
Notifications
You must be signed in to change notification settings - Fork 33
feat(tm-api): implement commit message linting and automation #71
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 complete commit message linting and enforcement system using Commitlint, Husky, Commitizen, and GitHub Actions. A new workflow is added to automatically check commit message compliance on pull requests. Husky is configured to lint commit messages locally via a Git hook. The Commitlint configuration is defined with specific rules for commit message structure and allowed types. Commitizen is set up to assist with standardized commit creation. The README is updated with detailed instructions on setting up and using these tools, including the commit message convention, prerequisites, and usage examples. Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Husky (Git Hook)
participant Commitlint
participant Commitizen
participant GitHub Actions
Developer->>Commitizen: Run "npm run commit"
Commitizen->>Developer: Prompt for commit message fields
Developer->>Husky (Git Hook): git commit
Husky (Git Hook)->>Commitlint: Lint commit message (--edit)
Commitlint-->>Husky (Git Hook): Pass/Fail result
Husky (Git Hook)-->>Developer: Allow/Block commit
Developer->>GitHub: Push changes / open PR
GitHub->>GitHub Actions: Trigger commit-lint workflow
GitHub Actions->>Commitlint: Lint all PR commit messages
Commitlint-->>GitHub Actions: Pass/Fail result
GitHub Actions-->>GitHub: Report status on PR
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:
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 (
|
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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: 2
🧹 Nitpick comments (5)
.github/workflows/commit-lint.yml (1)
30-30: Remove trailing spaces and ensure newline at end-of-file.YAMLlint reports trailing spaces on line 30 and no final newline. Please remove the extra whitespace and add a newline at EOF to satisfy linting rules.
🧰 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)
README.md (4)
32-32: Fix Markdown link formatting.There’s an unintended space in the link syntax which breaks the URL:
- For step-by-step guide, follow this [guide] (https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup) . + For step-by-step guide, follow this [guide](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup).🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
32-32: Bare URL used
null(MD034, no-bare-urls)
71-73: Specify language for fenced code block.To satisfy markdownlint (MD040) and improve readability, add a language identifier:
- ``` + ```bash node --version npm --version<details> <summary>🧰 Tools</summary> <details> <summary>🪛 markdownlint-cli2 (0.17.2)</summary> 71-71: Fenced code blocks should have a language specified null (MD040, fenced-code-language) </details> </details> --- `79-80`: **Specify language for fenced code block.** Add a language to the npm install code block for consistency: ```diff - ``` + ```bash npm ci--- `111-113`: **Specify language for Commitizen example code block.** Include a shell/language identifier: ```diff - ``` + ```bash npm run commit</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7c84b7393ff6ff469f62bf8ab4aff6250b156b40 and d13dd4477f868f158aae255a9bfc607947b56f09. </details> <details> <summary>⛔ Files ignored due to path filters (1)</summary> * `package-lock.json` is excluded by `!**/package-lock.json` </details> <details> <summary>📒 Files selected for processing (5)</summary> * `.github/workflows/commit-lint.yml` (1 hunks) * `.husky/commit-msg` (1 hunks) * `README.md` (3 hunks) * `commitlint.config.js` (1 hunks) * `package.json` (1 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 YAMLlint (1.35.1)</summary> <details> <summary>.github/workflows/commit-lint.yml</summary> [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) </details> </details> <details> <summary>🪛 LanguageTool</summary> <details> <summary>README.md</summary> [uncategorized] ~69-~69: The official spelling of this programming framework is “Node.js”. Context: ...d npm** - Download and install from [nodejs.org](https://nodejs.org/) - Verify i... (NODE_JS) --- [uncategorized] ~81-~81: Possible missing comma found. Context: ...``` - This will install all required dependencies including Husky and commitlint 3. **Ve... (AI_HYDRA_LEO_MISSING_COMMA) --- [grammar] ~95-~95: “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] ~98-~98: Loose punctuation mark. Context: ... changes (formatting, etc.) - `refactor`: Code changes that neither fix bugs nor ... (UNLIKELY_OPENING_PUNCTUATION) </details> </details> <details> <summary>🪛 markdownlint-cli2 (0.17.2)</summary> <details> <summary>README.md</summary> 71-71: Fenced code blocks should have a language specified null (MD040, fenced-code-language) --- 78-78: Fenced code blocks should have a language specified null (MD040, fenced-code-language) --- 110-110: Fenced code blocks should have a language specified null (MD040, fenced-code-language) </details> </details> </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>.github/workflows/commit-lint.yml (1)</summary> `1-29`: **Commit Compliance workflow is properly configured.** The GitHub Actions workflow triggers on pull request events, checks out the correct ref with full history, sets up Node.js, installs dependencies, and runs `commitlint` between head and base SHAs. This aligns with the PR objective to enforce commit message linting in CI. </details> <details> <summary>commitlint.config.js (1)</summary> `1-36`: **Commitlint configuration correctly enforces Conventional Commits.** The rules extend the conventional preset, enforce body/footer blank lines, limit line lengths, restrict subject punctuation and casing, and tightly define allowed types. This aligns with project objectives and ensures clear, consistent commit messages. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
| @@ -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.
🛠️ Refactor suggestion
Add Husky hook initialization and shebang to the commit-msg hook.
The current script omits the required shebang and Husky shim import, so Git won’t source the Husky environment. Without this, the hook may not execute correctly.
Apply this diff:
- npx --no -- commitlint --edit $1
+ #!/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" |
| "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.
Correct the prepare script to properly install Husky hooks.
Husky v7+ expects husky install to set up the .husky directory and hooks. Using husky alone may not install the hooks.
-"prepare": "husky",
+"prepare": "husky install",


📋 Description
Closes PSMRI/AMRIT#85
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