Skip to content

Commit dc84bd9

Browse files
abhijeetw035Abhijeet
andauthored
feat: added commit message linting (#95)
* feat: added commit message linting * fix: updated package.json * feat: implement commit message linting and automation --------- Co-authored-by: Abhijeet <abhijeetw035@email.com>
1 parent cf9f71c commit dc84bd9

File tree

7 files changed

+3577
-0
lines changed

7 files changed

+3577
-0
lines changed

.github/workflows/commit-lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Commit Compliance
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
commitlint:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code with submodule
13+
uses: actions/checkout@v4
14+
with:
15+
ref: ${{ github.event.pull_request.head.ref }}
16+
repository: ${{ github.event.pull_request.head.repo.full_name }}
17+
submodules: true
18+
fetch-depth: 0
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 18
24+
25+
- name: Install dependencies
26+
run: npm ci --legacy-peer-deps
27+
28+
- name: Run commitlint on PR
29+
run: |
30+
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no -- commitlint --edit "$1"

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,49 @@ To build the TM module from source, follow these steps:
5252
```
5353
- Open your browser and navigate to http://localhost:8080/swagger-ui.html#!/
5454

55+
## Setting Up Commit Hooks
56+
57+
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:
58+
59+
### Prerequisites
60+
- Node.js (v14 or later)
61+
- npm (comes with Node.js)
62+
63+
### Setup Steps
64+
65+
1. **Install Node.js and npm**
66+
- Download and install from [nodejs.org](https://nodejs.org/)
67+
- Verify installation with:
68+
```
69+
node --version
70+
npm --version
71+
```
72+
2. **Install dependencies**
73+
- From the project root directory, run:
74+
```
75+
npm ci
76+
```
77+
- This will install all required dependencies including Husky and commitlint
78+
3. **Verify hooks installation**
79+
- The hooks should be automatically installed by Husky
80+
- You can verify by checking if the `.husky` directory contains executable hooks
81+
### Commit Message Convention
82+
This project follows a specific commit message format:
83+
- Format: `type(scope): subject`
84+
- Example: `feat(login): add remember me functionality`
85+
Types include:
86+
- `feat`: A new feature
87+
- `fix`: A bug fix
88+
- `docs`: Documentation changes
89+
- `style`: Code style changes (formatting, etc.)
90+
- `refactor`: Code changes that neither fix bugs nor add features
91+
- `perf`: Performance improvements
92+
- `test`: Adding or fixing tests
93+
- `build`: Changes to build process or tools
94+
- `ci`: Changes to CI configuration
95+
- `chore`: Other changes (e.g., maintenance tasks, dependencies)
96+
Your commit messages will be automatically validated when you commit, ensuring project consistency.
97+
5598
## Usage
5699
57100
All the features of the TM module have been exposed as REST endpoints. For detailed information on how to use the service, refer to the SWAGGER API specification.

commitlint.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
'body-leading-blank': [1, 'always'],
5+
'body-max-line-length': [2, 'always', 100],
6+
'footer-leading-blank': [1, 'always'],
7+
'footer-max-line-length': [2, 'always', 100],
8+
'header-max-length': [2, 'always', 100],
9+
'subject-case': [
10+
2,
11+
'never',
12+
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
13+
],
14+
'subject-empty': [2, 'never'],
15+
'subject-full-stop': [2, 'never', '.'],
16+
'type-case': [2, 'always', 'lower-case'],
17+
'type-empty': [2, 'never'],
18+
'type-enum': [
19+
2,
20+
'always',
21+
[
22+
'build',
23+
'chore',
24+
'ci',
25+
'docs',
26+
'feat',
27+
'fix',
28+
'perf',
29+
'refactor',
30+
'revert',
31+
'style',
32+
'test',
33+
],
34+
],
35+
}
36+
};

0 commit comments

Comments
 (0)