Implemented post-commit hooks to automatically send coordination messages to dev-alerts channel when feature specs are created or builds occur. HOOKS: - .git/hooks/post-commit (main repo) - .git/modules/projects/msp-tools/guru-connect/hooks/post-commit (GC submodule) TRIGGERS: - Feature spec creation (SPEC-NNN files) - Build events (spec/feat/fix/build commits on main) ACTIONS: - Extract spec metadata (priority, effort, overview) - Send coordination message to dev-alerts channel - Include commit hash, author, files changed DOCUMENTATION: - .claude/HOOKS.md - Full hook documentation - .claude/hooks/post-commit.template - Reusable hook template BENEFITS: - Automatic notifications for new features - Build tracking on main branch - Team awareness of spec changes - No manual message sending required Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
75 lines
3.4 KiB
Bash
Executable File
75 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Post-commit hook: Send dev-alerts for feature specs and significant changes
|
|
|
|
# Get commit info
|
|
COMMIT_HASH=$(git rev-parse --short HEAD)
|
|
COMMIT_MSG=$(git log -1 --pretty=%B)
|
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
AUTHOR=$(git log -1 --pretty=%an)
|
|
|
|
# Determine project from submodule path
|
|
if git rev-parse --show-toplevel | grep -q "guru-connect"; then
|
|
PROJECT="guruconnect"
|
|
PROJECT_NAME="GuruConnect"
|
|
elif git rev-parse --show-toplevel | grep -q "guru-rmm"; then
|
|
PROJECT="gururmm"
|
|
PROJECT_NAME="GuruRMM"
|
|
else
|
|
PROJECT="claudetools"
|
|
PROJECT_NAME="ClaudeTools"
|
|
fi
|
|
|
|
# Check if this is a spec commit (new SPEC-NNN file or updated roadmap)
|
|
SPEC_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | grep -E 'docs/specs/SPEC-[0-9]+-.*\.md$')
|
|
ROADMAP_UPDATED=$(git diff-tree --no-commit-id --name-only -r HEAD | grep -E 'FEATURE_ROADMAP\.md$')
|
|
|
|
if [[ -n "$SPEC_FILES" ]]; then
|
|
# Extract SPEC number and name from first spec file
|
|
SPEC_FILE=$(echo "$SPEC_FILES" | head -1)
|
|
SPEC_NUM=$(echo "$SPEC_FILE" | grep -oE 'SPEC-[0-9]+')
|
|
SPEC_NAME=$(echo "$SPEC_FILE" | sed -E 's/.*SPEC-[0-9]+-(.*)\.md$/\1/' | tr '-' ' ' | sed 's/.*/\u&/')
|
|
|
|
# Read spec file to extract key info
|
|
SPEC_PATH=$(git rev-parse --show-toplevel)/"$SPEC_FILE"
|
|
PRIORITY=$(grep -m1 "^\*\*Priority:\*\*" "$SPEC_PATH" | sed 's/.*Priority:\*\* //' | tr -d '\n')
|
|
EFFORT=$(grep -m1 "^\*\*Estimated Effort:\*\*" "$SPEC_PATH" | sed 's/.*Estimated Effort:\*\* //' | tr -d '\n')
|
|
OVERVIEW=$(sed -n '/^## Overview/,/^##/p' "$SPEC_PATH" | grep -v "^##" | head -5 | tr '\n' ' ')
|
|
|
|
# Send dev-alerts message
|
|
SESSION_ID=$(hostname)/claude-main
|
|
|
|
curl -s -X POST http://172.16.3.30:8001/api/coord/messages \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"from_session\": \"$SESSION_ID\",
|
|
\"to_session\": \"dev-alerts\",
|
|
\"project_key\": \"$PROJECT\",
|
|
\"subject\": \"$PROJECT_NAME Feature Spec: $SPEC_NUM $SPEC_NAME\",
|
|
\"body\": \"New $PROJECT_NAME feature specification created.\\n\\n$SPEC_NUM: $SPEC_NAME\\nPriority: $PRIORITY | Effort: $EFFORT\\n\\nOVERVIEW:\\n$OVERVIEW\\n\\nCommit: $COMMIT_HASH on $BRANCH\\nAuthor: $AUTHOR\\n\\n🤖 Auto-generated via post-commit hook\"
|
|
}" > /dev/null 2>&1
|
|
fi
|
|
|
|
# Detect build/push events (commit message contains 'spec:', 'feat:', 'fix:', etc.)
|
|
if echo "$COMMIT_MSG" | grep -qE '^(spec|feat|fix|chore|docs|build):'; then
|
|
COMMIT_TYPE=$(echo "$COMMIT_MSG" | grep -oE '^[a-z]+:' | tr -d ':')
|
|
|
|
# Only send build alerts for significant commits on main branch
|
|
if [[ "$BRANCH" == "main" ]] && [[ "$COMMIT_TYPE" =~ ^(spec|feat|fix|build)$ ]]; then
|
|
FILES_CHANGED=$(git diff-tree --no-commit-id --name-only -r HEAD | wc -l | tr -d ' ')
|
|
|
|
SESSION_ID=$(hostname)/claude-main
|
|
|
|
curl -s -X POST http://172.16.3.30:8001/api/coord/messages \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"from_session\": \"$SESSION_ID\",
|
|
\"to_session\": \"dev-alerts\",
|
|
\"project_key\": \"$PROJECT\",
|
|
\"subject\": \"$PROJECT_NAME Build: $COMMIT_TYPE on main\",
|
|
\"body\": \"$PROJECT_NAME main branch updated.\\n\\nCOMMIT: $COMMIT_HASH\\nTYPE: $COMMIT_TYPE\\nFILES CHANGED: $FILES_CHANGED\\nBRANCH: $BRANCH\\nAUTHOR: $AUTHOR\\n\\nMESSAGE:\\n$COMMIT_MSG\\n\\n🔨 Auto-generated via post-commit hook\"
|
|
}" > /dev/null 2>&1
|
|
fi
|
|
fi
|
|
|
|
exit 0
|