Skip to content

Commit 678d234

Browse files
Use @digitoimistodude/code-quality-checks npm package for husky hooks, Ref: DEV-177
1 parent 653202b commit 678d234

File tree

5 files changed

+21
-597
lines changed

5 files changed

+21
-597
lines changed

.husky/commit-msg

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1 @@
1-
#!/bin/sh
2-
# Commit message validation hook for Dude projects
3-
4-
# Colors for output
5-
RED='\033[1;31m'
6-
GREEN='\033[0;32m'
7-
YELLOW='\033[1;33m'
8-
BLUE='\033[1;34m'
9-
PURPLE='\033[0;35m'
10-
NC='\033[0m' # No Color
11-
12-
# Emojis for better visual feedback
13-
CHECK=""
14-
CROSS=""
15-
ARROW=""
16-
SEARCH="🔍"
17-
18-
echo ""
19-
echo "${SEARCH} Checking commit message format..."
20-
21-
# Get the commit message from the file passed as argument
22-
commit_msg_file="$1"
23-
if [ -f "$commit_msg_file" ]; then
24-
commit_msg=$(cat "$commit_msg_file")
25-
printf " ${ARROW} Validating commit message... "
26-
27-
# Check for task ID pattern (e.g., DEV-123, TASK-456, etc.)
28-
task_id_pattern="[A-Z]+-[0-9]+"
29-
30-
# Check for magic words (closing)
31-
closing_words="close|closes|closed|closing|fix|fixes|fixed|fixing|resolve|resolves|resolved|resolving|complete|completes|completed|completing"
32-
33-
# Check for magic words (non-closing)
34-
non_closing_words="ref|refs|references|part of|related to|contributes to|toward|towards"
35-
36-
# Check if commit message contains task ID
37-
if ! echo "$commit_msg" | grep -iE "$task_id_pattern" >/dev/null 2>&1; then
38-
echo "${RED}${CROSS} FAILED${NC}"
39-
echo " ${RED}Commit message missing task ID${NC}"
40-
echo " ${YELLOW}Your commit message:${NC}"
41-
echo " ${BLUE}\"$commit_msg\"${BLUE}"
42-
echo ""
43-
echo " ${YELLOW}Expected format: [MAGIC_WORD]: [TASK-ID]${NC}"
44-
echo " ${YELLOW}Correct example: ${BLUE}\"$commit_msg, Ref: DEV-123\"${NC}"
45-
echo " ${YELLOW}See: ${NC}${BLUE}https://linear.app/docs/github?tabs=206cad22125a#link-through-pull-requests${NC}"
46-
exit 1
47-
fi
48-
49-
# Check if commit message contains magic words
50-
if ! echo "$commit_msg" | grep -iE "($closing_words|$non_closing_words)" >/dev/null 2>&1; then
51-
echo "${RED}${CROSS} FAILED${NC}"
52-
echo " ${RED}Commit message missing magic words${NC}"
53-
echo " ${YELLOW}Your commit message:${NC}"
54-
echo " ${PURPLE}\"$commit_msg\"${NC}"
55-
echo " ${YELLOW}Closing magic words: ${NC}${PURPLE}close, closes, closed, closing, fix, fixes, fixed, fixing, resolve, resolves, resolved, resolving, complete, completes, completed, completing${NC}"
56-
echo " ${YELLOW}Non-closing magic words: ${NC}${PURPLE}ref, refs, references, part of, related to, contributes to, toward, towards${NC}"
57-
# Extract task ID from commit message if present for dynamic example
58-
extracted_task_id=$(echo "$commit_msg" | grep -ioE "$task_id_pattern" | head -1 || echo "DEV-123")
59-
echo " ${YELLOW}Correct examples:${NC}"
60-
echo " ${PURPLE}\"$commit_msg, Closes $extracted_task_id\"${NC}"
61-
echo " ${PURPLE}\"$commit_msg, Ref: $extracted_task_id\"${NC}"
62-
echo " ${YELLOW}See: ${NC}${PURPLE}https://linear.app/docs/github?tabs=206cad22125a#link-through-pull-requests${NC}"
63-
exit 1
64-
fi
65-
66-
echo "${GREEN}${CHECK} OK${NC}"
67-
68-
# If we reach this point, ALL hooks have passed - show success box
69-
echo ""
70-
71-
# Create ASCII box with reminders
72-
print_success_box() {
73-
local box_width=60
74-
local border="${GREEN}$(printf '═%.0s' $(seq 1 $((box_width-2))))${NC}"
75-
local bottom="${GREEN}$(printf '═%.0s' $(seq 1 $((box_width-2))))${NC}"
76-
77-
echo "$border"
78-
echo "${GREEN}${NC} ${GREEN}✅ All checks passed! Ready to push!${NC}$(printf '%*s' 21 '')${GREEN}${NC}"
79-
echo "${GREEN}${NC}$(printf '%*s' 58 '')${GREEN}${NC}"
80-
echo "${GREEN}${NC} ${GREEN}💡 Reminders before pushing:${NC}$(printf '%*s' 29 '')${GREEN}${NC}"
81-
echo "${GREEN}${NC}$(printf '%*s' 58 '')${GREEN}${NC}"
82-
83-
# Check CHANGELOG.md age
84-
if [ -f "CHANGELOG.md" ]; then
85-
changelog_age_minutes=$(find CHANGELOG.md -mmin +0 -printf '%Tm\n' 2>/dev/null || echo "0")
86-
if [ "$changelog_age_minutes" -gt 10 ]; then
87-
echo "${GREEN}${NC} ${GREEN}• Update CHANGELOG.md with recent changes${NC}$(printf '%*s' 20 '')${GREEN}${NC}"
88-
fi
89-
90-
# Check if CHANGELOG.md has today's date
91-
changelog_first_line=$(head -n 1 CHANGELOG.md)
92-
current_date=$(date +%Y-%m-%d)
93-
if ! echo "$changelog_first_line" | grep -q "$current_date"; then
94-
echo "${GREEN}${NC} ${GREEN}• Consider updating changelog date to $current_date${NC}$(printf '%*s' 9 '')${GREEN}${NC}"
95-
fi
96-
fi
97-
98-
# Check for uncommitted files
99-
uncommitted_files=$(git status --porcelain | wc -l | tr -d ' ')
100-
if [ "$uncommitted_files" -gt 0 ]; then
101-
if [ "$uncommitted_files" -ge 10 ]; then
102-
echo "${GREEN}${NC} ${GREEN}• You have $uncommitted_files uncommitted files${NC}$(printf '%*s' 26 '')${GREEN}${NC}"
103-
else
104-
echo "${GREEN}${NC} ${GREEN}• You have $uncommitted_files uncommitted files${NC}$(printf '%*s' 27 '')${GREEN}${NC}"
105-
fi
106-
fi
107-
108-
# Check current branch
109-
current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
110-
if [ "$current_branch" = "master" ] || [ "$current_branch" = "main" ]; then
111-
echo "${GREEN}${NC} ${GREEN}• You're on '$current_branch' - use task ID branches, if possible ${NC}$(printf '%*s' 0 '')${GREEN}${NC}"
112-
fi
113-
114-
# General reminders
115-
echo "${GREEN}${NC} ${GREEN}• Test changes locally before pushing${NC}$(printf '%*s' 20 '')${GREEN}${NC}"
116-
echo "${GREEN}${NC} ${GREEN}• When in doubt, huddle calls and docs are your friends${NC}$(printf '%*s' 2 '')${GREEN}${NC}"
117-
118-
# Check if this is Friday afternoon
119-
day_of_week=$(date +%u) # 1=Monday, 7=Sunday
120-
hour_of_day=$(date +%H)
121-
if [ "$day_of_week" -eq 5 ] && [ "$hour_of_day" -ge 15 ]; then
122-
echo "${GREEN}${NC} ${GREEN}⚠️ Friday afternoon - defer non-critical deploys${NC}$(printf '%*s' 8 '')${GREEN}${NC}"
123-
fi
124-
125-
echo "$bottom"
126-
}
127-
128-
print_success_box
129-
else
130-
echo "${YELLOW}⚠️ SKIPPED (no commit message file)${NC}"
131-
fi
1+
node_modules/@digitoimistodude/code-quality-checks/.husky/commit-msg "$1"

0 commit comments

Comments
 (0)