#!/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): (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 local SERVICES=$(echo "$CHANGED_FILES" | grep -E '@services|@apps' | cut -d'/' -f1-2 | sort -u | head -5 | tr '\n' ', ' | sed 's/,$//') # Fallback message cat <