Skip to content

Conversation

@Zapper9982
Copy link
Contributor

@Zapper9982 Zapper9982 commented Sep 25, 2025

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

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ 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

•⁠ ⁠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

Screenshot 2025-09-25 at 2 26 24 PM

Summary by CodeRabbit

  • Chores

    • Added automated commit message checks and pre-commit linting to standardize contributions.
    • Added a CI workflow that validates commits on pull requests.
    • Updated ignore rules to exclude third-party dependencies and clean up formatting.
    • Included project tooling/configuration to support commit hooks and linting.
  • Documentation

    • Added a guide for setting up Git hooks and following commit message conventions.

@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds 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

Cohort / File(s) Summary of changes
CI: Commit Lint workflow
.github/workflows/commit-lint.yml
New GitHub Actions workflow "Commit Compliance" triggered on PR events; checks out code, sets up Node 18, installs npm deps, and runs commitlint across PR range (base->head) with verbose output.
CI: Test coverage (no-op)
.github/workflows/testcase-coverage.yml
File present with no functional change (minor/formatting edit only).
Git hooks / local tooling
.husky/commit-msg, .husky/pre-commit, commitlint.config.js, package.json
Adds Husky hooks: commit-msg runs commitlint via npx, pre-commit runs lint-staged; new commitlint.config.js enforces Conventional Commits rules; package.json adds scripts, commitizen, husky, lint-staged, commitlint devDependencies and config.
Repo housekeeping & docs
.gitignore, README.md
Adds node_modules to .gitignore, formatting tweak for bengen_local.properties, and documents "Setting Up Commit Hooks" and usage for new tooling in README.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

I hop through commits with tidy delight,
Hooks guard each message, keep history right.
CI hums approval, linters cheer on,
Carrots of coverage gleam at each dawn. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning While the PR appropriately adds commit message tooling, it also includes updates to the existing testcase-coverage GitHub Actions workflow file that are unrelated to commit linting automation and were not requested in issue #88. Please remove the accidental edits to .github/workflows/testcase-coverage.yml or move them to a separate PR to keep this change focused on commit message linting and automation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly reflects the addition of Commitlint, Commitizen, and Husky configurations which are the main focus of the PR, and it is concise and directly related to the changeset.
Linked Issues Check ✅ Passed The changes introduce Commitlint configuration, Husky commit-msg hooks, Commitizen setup, and a GitHub Actions workflow for commit message validation, fully addressing the integration and automation requirements outlined in issue #88.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 4

🧹 Nitpick comments (2)
README.md (1)

44-55: Add fenced-code languages for shell snippets

Markdown 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 bash to 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 redundant npm install.

npm ci already installs dependencies from the lockfile. Following it with npm i redoes the work, can mutate the lock, and runs the Husky prepare script twice. Keeping just npm ci --legacy-peer-deps will be faster and more deterministic.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa55e5 and 3d30f78.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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: Confirm xmllint availability before enforcing this hook.

lint-staged will now invoke xmllint --noout on staged XML files. On many contributor environments (especially Windows) xmllint is not present by default, so this hook would fail every commit until they install system-level libxml2 tooling. Can you confirm that we already provision xmllint across dev/CI environments or document/bundle it accordingly?

.gitignore (1)

33-34: Solid ignore additions for tooling artifacts

Good 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 guardrails

The 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.

@@ -0,0 +1 @@
npx --no -- commitlint --edit $1 No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

@@ -0,0 +1 @@
npx lint-staged No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

Suggested change
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.

@Zapper9982 Zapper9982 changed the base branch from main to develop September 25, 2025 09:21
Comment on lines +9 to +34
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

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
@drtechie
Copy link
Member

@Zapper9982 can you please check code rabbit comments?

@Zapper9982
Copy link
Contributor Author

@drtechie sure will do it by eod

@drtechie
Copy link
Member

drtechie commented Oct 7, 2025

@Zapper9982 gentle reminder

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 7, 2025

@Zapper9982
Copy link
Contributor Author

Zapper9982 commented Oct 7, 2025

image

@drtechie , the coderabbit comment is talking about complying with latest , but according to husky docs. i think the use of that is unnecessary .

@drtechie drtechie changed the base branch from develop to main November 6, 2025 04:45
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 Scheduler-API

3 participants