Skip to content

Commit 72aaaad

Browse files
authored
chore: setup commitlint and pre commit formatting hooks (#619)
1 parent 0f7fd83 commit 72aaaad

File tree

28 files changed

+798
-318
lines changed

28 files changed

+798
-318
lines changed

.github/workflows/format.yaml

Lines changed: 0 additions & 158 deletions
This file was deleted.

.husky/commit-msg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
echo "Validating commit message..."
2+
cd view
3+
if ! npx --no -- commitlint --edit "$(git rev-parse --show-toplevel)/${1}"; then
4+
echo "ERROR: Commit message validation failed"
5+
exit 1
6+
fi
7+
echo "Commit message validation passed"

.husky/pre-commit

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Get list of staged files
2+
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)
3+
STAGED_VIEW_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|jsx|ts|tsx|css|md|json)$' | grep '^view/' || true)
4+
5+
# Format Go files
6+
if [ -n "$STAGED_GO_FILES" ]; then
7+
echo "Formatting Go files..."
8+
cd api
9+
for file in $STAGED_GO_FILES; do
10+
# Remove 'api/' prefix since we're already in api directory
11+
rel_file="${file#api/}"
12+
if [ -f "$rel_file" ]; then
13+
if ! go fmt "$rel_file"; then
14+
echo "ERROR: Go formatting failed for $file"
15+
exit 1
16+
fi
17+
if command -v goimports >/dev/null 2>&1; then
18+
if ! goimports -w "$rel_file"; then
19+
echo "ERROR: goimports failed for $file"
20+
exit 1
21+
fi
22+
fi
23+
fi
24+
done
25+
if ! command -v goimports >/dev/null 2>&1; then
26+
echo "WARNING: goimports not found. Install with: go install golang.org/x/tools/cmd/goimports@latest"
27+
fi
28+
cd ..
29+
# Re-stage formatted files (only non-ignored files)
30+
echo "$STAGED_GO_FILES" | while read -r file; do
31+
if git check-ignore -q "$file"; then
32+
echo "WARNING: Skipping ignored file: $file"
33+
else
34+
git add "$file" 2>/dev/null || true
35+
fi
36+
done
37+
fi
38+
39+
# Format view files (TypeScript/JavaScript/CSS/Markdown/JSON)
40+
if [ -n "$STAGED_VIEW_FILES" ]; then
41+
echo "Formatting view files..."
42+
cd view
43+
if [ -f yarn.lock ] || [ -f package-lock.json ]; then
44+
# Format only staged files to avoid formatting ignored files
45+
FORMAT_FILES=""
46+
for file in $STAGED_VIEW_FILES; do
47+
# Remove 'view/' prefix since we're already in view directory
48+
rel_file="${file#view/}"
49+
if [ -f "$rel_file" ] && ! git -C .. check-ignore -q "$file" 2>/dev/null; then
50+
FORMAT_FILES="$FORMAT_FILES $rel_file"
51+
fi
52+
done
53+
if [ -n "$FORMAT_FILES" ]; then
54+
if ! (yarn prettier --write --config .prettierrc $FORMAT_FILES 2>/dev/null || npx prettier --write --config .prettierrc $FORMAT_FILES 2>/dev/null); then
55+
echo "ERROR: Prettier formatting failed"
56+
exit 1
57+
fi
58+
fi
59+
else
60+
echo "WARNING: No package manager lockfile found in view directory"
61+
fi
62+
cd ..
63+
# Re-stage formatted files (only non-ignored files)
64+
echo "$STAGED_VIEW_FILES" | while read -r file; do
65+
if git check-ignore -q "$file" 2>/dev/null; then
66+
echo "WARNING: Skipping ignored file: $file"
67+
else
68+
git add "$file" 2>/dev/null || true
69+
fi
70+
done
71+
fi
72+
73+
echo "Pre-commit checks passed"

.husky/pre-push

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
echo "Building API..."
4+
cd api
5+
if ! go build -o /tmp/nixopus-api-test .; then
6+
echo "ERROR: API build failed"
7+
exit 1
8+
fi
9+
rm -f /tmp/nixopus-api-test
10+
cd ..
11+
12+
echo "Building view..."
13+
(
14+
cd view || { echo "ERROR: Cannot enter view directory"; exit 1; }
15+
if [ -f yarn.lock ]; then
16+
yarn build || { echo "ERROR: View build failed"; exit 1; }
17+
elif [ -f package-lock.json ]; then
18+
npm run build || { echo "ERROR: View build failed"; exit 1; }
19+
else
20+
echo "WARNING: No package manager lockfile found in view directory"
21+
fi
22+
) || exit 1
23+
24+
echo "Build verification passed"

api/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ test-all:
1414
test-routes:
1515
@go test -p 1 ./internal/tests/routes/... -v -count=1
1616

17-
.PHONY: fixtures-load fixtures-recreate fixtures-clean fixtures-help
17+
format:
18+
@echo "Formatting Go files..."
19+
@go fmt ./...
20+
@if command -v goimports >/dev/null 2>&1; then \
21+
goimports -w .; \
22+
else \
23+
echo "goimports not found. Install with: go install golang.org/x/tools/cmd/goimports@latest"; \
24+
fi
25+
26+
.PHONY: fixtures-load fixtures-recreate fixtures-clean fixtures-help format
1827

1928
fixtures-help:
2029
@echo "Nixopus API Fixtures Commands:"

api/api/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"version": "v1",
55
"status": "active",
6-
"release_date": "2025-11-02T13:45:06.273828+05:30",
6+
"release_date": "2025-12-06T16:23:50.657646+05:30",
77
"end_of_life": "0001-01-01T00:00:00Z",
88
"changes": [
99
"Initial API version"

api/internal/types/extension.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import (
1111
type ExtensionCategory string
1212

1313
const (
14-
ExtensionCategorySecurity ExtensionCategory = "Security"
15-
ExtensionCategoryContainers ExtensionCategory = "Containers"
16-
ExtensionCategoryDatabase ExtensionCategory = "Database"
17-
ExtensionCategoryWebServer ExtensionCategory = "Web Server"
18-
ExtensionCategoryMaintenance ExtensionCategory = "Maintenance"
19-
ExtensionCategoryMonitoring ExtensionCategory = "Monitoring"
20-
ExtensionCategoryStorage ExtensionCategory = "Storage"
21-
ExtensionCategoryNetwork ExtensionCategory = "Network"
22-
ExtensionCategoryDevelopment ExtensionCategory = "Development"
23-
ExtensionCategoryMedia ExtensionCategory = "Media"
24-
ExtensionCategoryGame ExtensionCategory = "Game"
25-
ExtensionCategoryUtility ExtensionCategory = "Utility"
26-
ExtensionCategoryOther ExtensionCategory = "Other"
14+
ExtensionCategorySecurity ExtensionCategory = "Security"
15+
ExtensionCategoryContainers ExtensionCategory = "Containers"
16+
ExtensionCategoryDatabase ExtensionCategory = "Database"
17+
ExtensionCategoryWebServer ExtensionCategory = "Web Server"
18+
ExtensionCategoryMaintenance ExtensionCategory = "Maintenance"
19+
ExtensionCategoryMonitoring ExtensionCategory = "Monitoring"
20+
ExtensionCategoryStorage ExtensionCategory = "Storage"
21+
ExtensionCategoryNetwork ExtensionCategory = "Network"
22+
ExtensionCategoryDevelopment ExtensionCategory = "Development"
23+
ExtensionCategoryMedia ExtensionCategory = "Media"
24+
ExtensionCategoryGame ExtensionCategory = "Game"
25+
ExtensionCategoryUtility ExtensionCategory = "Utility"
26+
ExtensionCategoryOther ExtensionCategory = "Other"
2727
ExtensionCategoryProductivity ExtensionCategory = "Productivity"
2828
ExtensionCategorySocial ExtensionCategory = "Social"
2929
)

commitlint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};
4+

docs/contributing/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ yarn install
171171
This guide uses `yarn`, but `npm` or `pnpm` will work as well. Use whichever you prefer.
172172
:::
173173

174+
::: info Automatic Git Hooks Setup
175+
When you run `yarn install` (or `npm install`) in the `view` directory, Husky will automatically set up git hooks for commit message validation. This ensures all commits follow the [Conventional Commits](https://www.conventionalcommits.org/) format.
176+
177+
**Commit message format**: `type(scope): description`
178+
179+
**Valid types**: `build`, `chore`, `ci`, `docs`, `feat`, `fix`, `perf`, `refactor`, `revert`, `style`, `test`
180+
181+
**Examples**:
182+
-`feat: add user authentication`
183+
-`fix(api): resolve database connection issue`
184+
-`docs: update contributing guide`
185+
-`update code` (missing type)
186+
-`fix bug` (missing colon)
187+
188+
If your commit message doesn't follow the format, the commit will be rejected with helpful error messages.
189+
:::
190+
174191
## Run
175192

176193
You'll need **two terminal windows** to run both the backend and frontend simultaneously.

view/.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm test

0 commit comments

Comments
 (0)