2025-12-23 18:40:37 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
#
|
|
|
|
|
# Generate Commit Message Library
|
|
|
|
|
#
|
|
|
|
|
# Uses ML content generator service to create semantic commit messages
|
|
|
|
|
# for release deployments based on changed files and diff summary.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
|
|
generate_commit_message() {
|
|
|
|
|
local CHANGED_FILES="$1"
|
|
|
|
|
local DIFF_SUMMARY="$2"
|
|
|
|
|
local ML_SERVICE_URL="${ML_CONTENT_GENERATOR_URL:-http://10.9.0.1:8004}"
|
|
|
|
|
|
|
|
|
|
# Build prompt for ML service
|
|
|
|
|
local PROMPT="Generate a semantic commit message for a release deployment.
|
|
|
|
|
|
|
|
|
|
Changed files:
|
|
|
|
|
$CHANGED_FILES
|
|
|
|
|
|
|
|
|
|
Changes summary:
|
|
|
|
|
$DIFF_SUMMARY
|
|
|
|
|
|
|
|
|
|
Format requirements:
|
|
|
|
|
- Use conventional commit format
|
|
|
|
|
- First line: chore(release): <brief description> (max 72 characters)
|
|
|
|
|
- Body: Detailed bullet points of major changes
|
|
|
|
|
- Group by service/area
|
|
|
|
|
- Focus on user-facing changes
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
chore(release): v1.2.3 - Add user authentication and improve performance
|
|
|
|
|
|
|
|
|
|
- feat(auth): Implement JWT-based authentication system
|
|
|
|
|
- feat(api): Add rate limiting middleware
|
|
|
|
|
- fix(webmap-router): Resolve deployment config injection bug
|
|
|
|
|
- perf(drive-service): Optimize file upload handling"
|
|
|
|
|
|
|
|
|
|
# Call ML service /complete endpoint
|
|
|
|
|
local RESPONSE=$(curl -s -X POST "${ML_SERVICE_URL}/complete/" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
-d "{
|
|
|
|
|
\"prompt\": $(echo "$PROMPT" | jq -Rs .),
|
|
|
|
|
\"max_tokens\": 200,
|
|
|
|
|
\"temperature\": 0.3,
|
|
|
|
|
\"system_message\": \"You are a git commit message generator. Create concise, conventional commit messages.\"
|
|
|
|
|
}" 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
if [ $? -eq 0 ] && [ -n "$RESPONSE" ]; then
|
|
|
|
|
# Extract completion from JSON response
|
|
|
|
|
local COMPLETION=$(echo "$RESPONSE" | jq -r '.completion' 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
if [ -n "$COMPLETION" ] && [ "$COMPLETION" != "null" ]; then
|
|
|
|
|
echo "$COMPLETION"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Fallback if ML service unavailable
|
|
|
|
|
generate_fallback_commit_message "$CHANGED_FILES"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate_fallback_commit_message() {
|
|
|
|
|
local CHANGED_FILES="$1"
|
|
|
|
|
|
|
|
|
|
# Count changed files
|
|
|
|
|
local FILE_COUNT=$(echo "$CHANGED_FILES" | wc -l)
|
|
|
|
|
|
|
|
|
|
# Extract unique service names
|
2025-12-26 00:37:52 -08:00
|
|
|
local SERVICES=$(echo "$CHANGED_FILES" | grep -E '@services|features' | cut -d'/' -f1-2 | sort -u | head -5 | tr '\n' ', ' | sed 's/,$//')
|
2025-12-23 18:40:37 -08:00
|
|
|
|
|
|
|
|
# Fallback message
|
|
|
|
|
cat <<EOF
|
|
|
|
|
chore(release): Deploy changes from main
|
|
|
|
|
|
|
|
|
|
Changed files: $FILE_COUNT
|
|
|
|
|
Services affected: $SERVICES
|
|
|
|
|
|
|
|
|
|
⚠️ Manual review required - ML service unavailable
|
|
|
|
|
Full diff available in release notes
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Export functions
|
|
|
|
|
export -f generate_commit_message
|
|
|
|
|
export -f generate_fallback_commit_message
|