Skip to content

Conversation

@rohan-019
Copy link

@rohan-019 rohan-019 commented Apr 17, 2025

Fixes : PSMRI/AMRIT#88

Description

This PR implements a robust commit message standardization system for the BeneficiaryID-Generation-API repository. The changes ensure consistent commit message formatting across all contributions.

Changes

  • Integrated Commitlint for enforcing conventional commit messages
  • Set up Husky hooks for pre-commit validation
  • Added Commitizen for interactive commit message creation
  • Configured GitHub Actions workflow for PR validation
  • Added documentation about commit standards

Testing

  • Commit messages are validated locally
  • Pre-commit hooks run successfully
  • GitHub Actions workflow validates PR commits
  • Commitizen prompts work as expected

Related Issues

  • Implements commit message standards
  • Enables automated changelog generation
  • Improves collaboration through consistent commits

Checklist

  • Follows conventional commits specification
  • Maintains compatibility with existing CI/CD
  • Includes clear documentation
  • Passes all validation checks

Summary by CodeRabbit

  • New Features
    • Introduced commit message linting and enforcement using Conventional Commits standards.
    • Added automated commit message checks on pull requests and during local commits.
    • Integrated Husky hooks for pre-commit testing and commit message validation.
    • Provided a Visual Studio Code setting for Java null analysis.
  • Chores
    • Updated .gitignore to better handle Java and Node.js files.
    • Added project metadata and scripts for commit management and code formatting.
  • Documentation
    • Expanded README with commit message standards and tool usage details.

This change implements a robust commit message standardization system for the
BeneficiaryID-Generation-API repository. We've integrated Commitlint, Husky, and Commitizen to
enforce consistent commit message formatting across all contributions. The setup includes pre-commit
hooks for test validation and commit message linting, ensuring that all commits follow the
Conventional Commits specification. The GitHub Actions workflow has been configured to validate
commit messages in pull requests, checking the entire commit history for compliance. We've also
added clear documentation in the README about commit message standards and the tools used. The
implementation maintains compatibility with existing CI/CD pipelines while providing contributors
with an interactive commit message creation process through Commitizen.
This change implements a robust commit message standardization system for the
BeneficiaryID-Generation-API repository. We've
@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

Walkthrough

This change introduces commit message linting and automation tools into the repository. It adds configuration files for Commitlint, Husky, and Commitizen to enforce the Conventional Commits specification. Git hooks are set up to validate commit messages and run tests before commits. A GitHub Actions workflow is included to check commit messages on pull requests. The .gitignore and VS Code settings are updated for better environment handling, and the README is revised to document the new commit message standards and related tooling.

Changes

Files / Paths Change Summary
.commitlintrc.json, .github/commitlint.config.js Added Commitlint configuration files to enforce conventional commit message standards with custom rules.
.github/workflows/commitlint.yml Introduced GitHub Actions workflow for commit message linting on pull requests targeting main branch.
.husky/commit-msg, .husky/pre-commit Added Husky Git hooks for commit message validation and pre-commit test execution.
.gitignore Extended to ignore common Java crash logs and Node.js environment files and directories.
.vscode/settings.json Added VS Code workspace setting to enable automatic Java null analysis mode.
README.md Added "Commit Message Standards" section describing Conventional Commits usage and tooling; minor typo fix.
package.json New file with project metadata, scripts for commitlint, Husky, Commitizen, lint-staged config, and devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky
    participant Commitlint
    participant CI (GitHub Actions)

    Developer->>Husky: git commit
    Husky->>Commitlint: Validate commit message
    Commitlint-->>Husky: Pass/Fail
    alt If commit message is valid
        Husky->>Husky: Run pre-commit tests (npm run test:ci)
        Husky-->>Developer: Allow commit if tests pass
    else If commit message is invalid or tests fail
        Husky-->>Developer: Block commit
    end

    Developer->>GitHub: Push PR
    CI->>Commitlint: Lint commit messages in PR
    Commitlint-->>CI: Pass/Fail
    CI-->>Developer: Report result in PR checks
Loading

Possibly related issues

Poem

In a warren of code, neat and bright,
The rabbits now hop with their commits in sight.
With Husky and Commitlint, they check every line,
Ensuring conventions are followed just fine.
Commitizen guides with a gentle nudge,
And GitHub Actions won’t let standards budge.
🐇✨ Our code garden grows, tidy and right!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (2)
.github/commitlint.config.js (1)

1-1: Remove the BOM character from the file.

There appears to be a Byte Order Mark (BOM) character at the beginning of this file (indicated by the UTF-8 BOM character "" in line 1). This can cause issues with some JavaScript parsers.

-module.exports = {
+module.exports = {
README.md (1)

9-15: Specify a language for the fenced code block.
Adding a language identifier improves readability and syntax highlighting. For example:

- ```
+ ```text
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

9-9: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb64a74 and 79ad081.

⛔ Files ignored due to path filters (3)
  • hs_err_pid9248.log is excluded by !**/*.log
  • package-lock.json is excluded by !**/package-lock.json
  • replay_pid9248.log is excluded by !**/*.log
📒 Files selected for processing (9)
  • .commitlintrc.json (1 hunks)
  • .github/commitlint.config.js (1 hunks)
  • .github/workflows/commitlint.yml (1 hunks)
  • .gitignore (1 hunks)
  • .husky/commit-msg (1 hunks)
  • .husky/pre-commit (1 hunks)
  • .vscode/settings.json (1 hunks)
  • README.md (2 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/commitlint.yml

11-11: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


14-14: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 LanguageTool
README.md

[grammar] ~19-~19: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation only changes - ...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)

🪛 markdownlint-cli2 (0.17.2)
README.md

9-9: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (12)
.vscode/settings.json (1)

1-3: Good addition for consistent Java development environment.

This VS Code setting enables automatic nullability checks during Java compilation, which helps catch potential null pointer exceptions early in the development process. This aligns well with the overall goal of improving code quality and standardization.

.gitignore (2)

5-8: Great addition for Java-specific ignore patterns.

These ignore patterns for Java crash logs are appropriate and follow standard practices.


9-19: Appropriate Node.js ignore patterns for the new tooling.

These additions properly ignore Node.js artifacts and environment files, which is essential now that you're introducing Node.js-based tooling (Commitlint, Husky, Commitizen). The environment file patterns ensure sensitive information doesn't get committed.

.husky/pre-commit (1)

1-6:

Details

✅ Verification successful

Verify the test:ci script exists in package.json.

The pre-commit hook is set up correctly to run tests before allowing commits, but I need to verify if the test:ci script is defined in your package.json file.


🏁 Script executed:

#!/bin/bash
# Check if the test:ci script is defined in package.json
if [ -f package.json ]; then
  if grep -q "\"test:ci\":" package.json; then
    echo "✅ test:ci script is defined in package.json"
  else
    echo "❌ test:ci script is not defined in package.json"
    echo "The pre-commit hook may fail if the script doesn't exist."
  fi
else
  echo "⚠️ package.json file not found"
fi

Length of output: 158


test:ci script verified in package.json

No changes required—your pre-commit hook will run successfully.

• package.json: "test:ci" script is defined.
• .husky/pre-commit: invokes npm run test:ci, which now exists.

.github/commitlint.config.js (1)

1-3: Properly configured Commitlint with conventional commits standard.

The configuration correctly extends the @commitlint/config-conventional preset to enforce conventional commit message standards. This is consistent with the PR objective of standardizing commit messages.

.commitlintrc.json (1)

1-3: Commitlint configuration is correct and minimal.
This file properly extends the Conventional Commits rules via @commitlint/config-conventional, ensuring commit messages follow the spec.

.husky/commit-msg (1)

1-3: Commit-msg hook correctly validates commit messages.
The hook sources Husky’s environment and invokes commitlint --edit "$1", enforcing your configured rules on every commit.

README.md (2)

6-30: New "Commit Message Standards" section is clear and comprehensive.
The documentation accurately outlines the Conventional Commits format, enumerates allowed types, and lists the enforcement tools (Commitlint, Husky, Commitizen).

🧰 Tools
🪛 LanguageTool

[grammar] ~19-~19: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - feat: A new feature - fix: A bug fix - docs: Documentation only changes - ...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)

🪛 markdownlint-cli2 (0.17.2)

9-9: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


65-65: Typographical refinement applied correctly.
The contraction “We'd” uses a standard apostrophe and reads well in context.

.github/workflows/commitlint.yml (1)

1-21: GitHub Actions workflow for commitlint is well-defined.
The workflow triggers on pull requests to main, checks out full history, sets up Node.js, runs npm ci, and lints commit messages between the base and head commits using .commitlintrc.json. This aligns perfectly with the PR objective to enforce commit standards in CI.

🧰 Tools
🪛 actionlint (1.7.4)

11-11: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


14-14: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

package.json (2)

13-21: Lint-staged configuration looks solid.
Your patterns for JavaScript/TypeScript and JSON/Markdown will format and lint staged files automatically, improving code quality before commits.


32-36: Commitizen configuration is correctly set up.
The cz-conventional-changelog adapter in config.commitizen will drive interactive commit prompts via npm run commit.

rohan-019 and others added 3 commits April 17, 2025 21:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.husky/commit-msg (1)

1-2: LGTM! Correctly sets up the commit-msg hook for Commitlint.

The script properly invokes the npm commitmsg script, passing the commit message file path as an argument. This is the standard pattern for Husky Git hooks.

For added robustness, consider adding error handling:

#!/bin/sh
-npm run commitmsg -- "$1"
+# Validate commit message using Commitlint
+npm run commitmsg -- "$1" || {
+  echo "Error: Commit message validation failed"
+  exit 1
+}

Also, ensure this file has executable permissions (chmod +x .husky/commit-msg).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 161844a and f8580ed.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • .husky/commit-msg (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

@drtechie
Copy link
Member

@rohan-019
Refer to
PSMRI/MMU-API#74

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't check in log files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't check in log files.

. "$(dirname "$0")/_/husky.sh"

# Run tests if they exist
npm run test:ci
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file about? I don't see this command in package.json scripts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, @drtechie ,
The pre-commit hook has been updated to use lint-staged instead of the placeholder test command. This change is more meaningful because it actually performs code quality checks on staged files before commits, running ESLint and Prettier on JavaScript/TypeScript files, and Prettier on JSON/Markdown files. This ensures consistent code formatting and quality across the repository.
Also, I've excluded log files from being checked in .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohan-019 the test:ci script in package.json does nothing.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
.commitlintrc.json (1)

4-8: Review blank-line and line-length limits
While enforcing leading blank lines and 100‑character max lengths is valid, many teams prefer stricter limits (e.g., header ≤50 chars, body ≤72 chars for readability in terminals). Consider adjusting these values to align with your team's workflow.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8580ed and 6be849b.

📒 Files selected for processing (1)
  • .commitlintrc.json (1 hunks)
🔇 Additional comments (4)
.commitlintrc.json (4)

2-2: Baseline commitlint preset extended
Extending @commitlint/config-conventional provides a solid foundation of conventional commit rules.


14-15: Enforce non-empty subjects and no trailing periods
Good: commits cannot have empty subjects or end with a period, aligning with conventional commits best practices.


16-17: Require lowercase, non-empty commit types
Requiring lowercase and non-empty type fields ensures standardized commit prefixes.


18-34: Validate allowed commit types
The type-enum covers the most common categories: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, and test. Confirm these meet your project’s needs; if you require additional categories (e.g., security), add them here.

@rohan-019
Copy link
Author

hi, @drtechie
commit-Lint funcationality works properly
Screenshot 2025-04-19 085208

Commitizen working properly with npx cz command
Screenshot 2025-04-19 085722

@rohan-019
Copy link
Author

Hi @drtechie,
I hope you're doing well! I wanted to kindly follow up on my first contribution. It’s been a few days and I haven’t received any feedback yet. I'd really appreciate it if you could take a moment to review it — your guidance would mean a lot as I’m eager to learn and grow under your mentorship.

Thank you in advance.

@rohan-019 rohan-019 closed this by deleting the head repository Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C4GT Community]: Implement Commit Message Linting and Automation for BeneficiaryID-Generation-API

2 participants