Skip to content

Commit a0eedd8

Browse files
chore(commitlint): add commit-msg hook and workflow validation
1 parent 0683b41 commit a0eedd8

8 files changed

Lines changed: 25 additions & 3532 deletions

File tree

.git-hooks/commit-msg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
npx --yes @commitlint/cli --edit "$1"

.github/workflows/commit-lint.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
name: Commit Compliance
1+
name: Commit Message Check
22

33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
66

77
jobs:
8-
commitlint:
8+
commit-check:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- name: Checkout code with submodule
13-
uses: actions/checkout@v4
12+
- uses: actions/checkout@v4
1413
with:
15-
ref: ${{ github.event.pull_request.head.ref }}
16-
repository: ${{ github.event.pull_request.head.repo.full_name }}
17-
submodules: true
1814
fetch-depth: 0
1915

20-
- name: Setup Node.js
21-
uses: actions/setup-node@v4
16+
- uses: actions/setup-node@v4
2217
with:
23-
node-version: 18
18+
node-version: '20'
2419

25-
- name: Install dependencies
26-
run: npm ci --legacy-peer-deps
27-
28-
- name: Run commitlint on PR
20+
- name: Validate commit messages
2921
run: |
30-
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
22+
git log \
23+
--no-merges \
24+
--pretty=format:"%H" \
25+
"${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" \
26+
| while IFS= read -r sha; do
27+
tmp=$(mktemp)
28+
git log -1 --pretty=format:"%B" "$sha" > "$tmp"
29+
npx --yes @commitlint/cli@20.4.3 --edit "$tmp" || exit 1
30+
rm "$tmp"
31+
done

.husky/commit-msg

Lines changed: 0 additions & 1 deletion
This file was deleted.

.husky/pre-commit

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,15 @@ Prerequisites
1919
* MySQL
2020

2121
## Environment and setup
22-
23-
1. Install dependencies `mvn clean install`
24-
2. You can copy `admin_example.properties` to `admin_local.properties` and edit the file accordingly. The file is under `src/main/environment` folder.
25-
3. Run the spring server with local configuration `mvn spring-boot:run -DENV_VAR=local`
22+
1. Enable git hooks (run once after cloning):
23+
- Run the command `git config core.hooksPath .git-hooks`.
24+
2. Install dependencies `mvn clean install`
25+
3. You can copy `admin_example.properties` to `admin_local.properties` and edit the file accordingly. The file is under `src/main/environment` folder.
26+
4. Run the spring server with local configuration `mvn spring-boot:run -DENV_VAR=local`
2627

2728
## Installation
2829
This service has been tested on Wildfly as the application server. To install the admin module, kindly refer to Installation Guide for [API Repository](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup/installation-instructions/for-api-repositories) for guidance.
2930

30-
## Setting Up Commit Hooks
31-
32-
This project uses Git hooks to enforce consistent code quality and commit message standards. Even though this is a Java project, the hooks are powered by Node.js. Follow these steps to set up the hooks locally:
33-
34-
### Prerequisites
35-
- Node.js (v18 or later)
36-
- npm (comes with Node.js)
37-
38-
### Setup Steps
39-
40-
1. **Install Node.js and npm**
41-
- Download and install from [nodejs.org](https://nodejs.org/)
42-
- Verify installation with:
43-
```
44-
node --version
45-
npm --version
46-
```
47-
2. **Install dependencies**
48-
- From the project root directory, run:
49-
```
50-
npm ci
51-
```
52-
- This will install all required dependencies including Husky and commitlint
53-
3. **Verify hooks installation**
54-
- The hooks should be automatically installed by Husky
55-
- You can verify by checking if the `.husky` directory contains executable hooks
56-
### Commit Message Convention
57-
This project follows a specific commit message format:
58-
- Format: `type(scope): subject`
59-
- Example: `feat(login): add remember me functionality`
60-
Types include:
61-
- `feat`: A new feature
62-
- `fix`: A bug fix
63-
- `docs`: Documentation changes
64-
- `style`: Code style changes (formatting, etc.)
65-
- `refactor`: Code changes that neither fix bugs nor add features
66-
- `perf`: Performance improvements
67-
- `test`: Adding or fixing tests
68-
- `build`: Changes to build process or tools
69-
- `ci`: Changes to CI configuration
70-
- `chore`: Other changes (e.g., maintenance tasks, dependencies)
71-
Your commit messages will be automatically validated when you commit, ensuring project consistency.
72-
7331
## Usage
7432
All the features have been exposed as REST endpoints.
7533
Refer to the SWAGGER API specification for details.

commitlint.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional'],
32
rules: {
43
'body-leading-blank': [1, 'always'],
54
'body-max-line-length': [2, 'always', 100],
@@ -32,5 +31,5 @@ module.exports = {
3231
'test',
3332
],
3433
],
35-
}
34+
},
3635
};

0 commit comments

Comments
 (0)