From 7371373ad19a46c4cdaf7872523c349fffd3b86a Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Fri, 6 Mar 2026 13:37:28 +0530 Subject: [PATCH 1/2] chore(commitlint): add commit-msg hook and workflow validation --- .git-hooks/commit-msg | 4 ++++ .github/workflows/commit-lint.yml | 29 +++++++++++++++++++++++++ README.md | 5 ++++- commitlint.config.js | 35 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 .git-hooks/commit-msg create mode 100644 .github/workflows/commit-lint.yml create mode 100644 commitlint.config.js diff --git a/.git-hooks/commit-msg b/.git-hooks/commit-msg new file mode 100644 index 00000000..d29127d2 --- /dev/null +++ b/.git-hooks/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +npx --yes @commitlint/cli@20.4.3 --edit "$1" \ No newline at end of file diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml new file mode 100644 index 00000000..aaad8add --- /dev/null +++ b/.github/workflows/commit-lint.yml @@ -0,0 +1,29 @@ +name: Commit Message Check + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + commit-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Validate commit messages + run: | + set -eo pipefail + commits=$(git log --no-merges --pretty=format:"%H" "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}") + for sha in $commits; do + tmp=$(mktemp) + git log -1 --pretty=format:"%B" "$sha" > "$tmp" + npx --yes @commitlint/cli@20.4.3 --edit "$tmp" + rm "$tmp" + done diff --git a/README.md b/README.md index 75a0708f..6baf2062 100644 --- a/README.md +++ b/README.md @@ -58,4 +58,7 @@ This microservice is built on Java, Spring boot framework and MySQL DB. * Spring Tool Suite 3 / Eclipse(2023-03) * Maven (if not pre-installed with the editor) * Redis-x64-3.0.504 -* MySQL Workbench 8.0 \ No newline at end of file +* MySQL Workbench 8.0 +## Setting Up Commit Hooks +Enable git hooks (run once after cloning): + - Run the command `git config core.hooksPath .git-hooks`. \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..abc565a9 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,35 @@ +module.exports = { + rules: { + 'body-leading-blank': [1, 'always'], + 'body-max-line-length': [2, 'always', 100], + 'footer-leading-blank': [1, 'always'], + 'footer-max-line-length': [2, 'always', 100], + 'header-max-length': [2, 'always', 100], + 'subject-case': [ + 2, + 'never', + ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], + ], + 'subject-empty': [2, 'never'], + 'subject-full-stop': [2, 'never', '.'], + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + 'type-enum': [ + 2, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'style', + 'test', + ], + ], + }, +}; \ No newline at end of file From 0aa829e5906a434ebaee6599a95d3a6af9d11d70 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Fri, 6 Mar 2026 13:51:02 +0530 Subject: [PATCH 2/2] docs(readme): update the readme with githook command --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6baf2062..733d156c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ This microservice is built on Java, Spring boot framework and MySQL DB. * Maven (if not pre-installed with the editor) * Redis-x64-3.0.504 * MySQL Workbench 8.0 +* Node.js and npm (required for git hooks via npx/commitlint) + ## Setting Up Commit Hooks Enable git hooks (run once after cloning): - Run the command `git config core.hooksPath .git-hooks`. \ No newline at end of file