Skip to content

Commit 5d6d012

Browse files
author
Abhijeet
committed
feat: added commit message linting to Admin-API
1 parent 73ea731 commit 5d6d012

8 files changed

Lines changed: 3579 additions & 0 deletions

File tree

.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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ mvnw.cmd
3939

4040
# Properties
4141
src/main/environment/admin_local.properties
42+
43+
node_modules

.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
@@ -26,6 +26,49 @@ Prerequisites
2626
## Installation
2727
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.
2828

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

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)