#!/usr/bin/env bash set -euo pipefail # Generate an automatic Git-based changelog used by Filament support page. REPO_DIR="$(pwd)" LEGACY_REPO_DIR="/home/michele/netgescon/netgescon-laravel" OUTPUT_FILE="docs/NETGESCON-GIT-AUTOCHANGELOG.md" LIMIT="180" usage() { cat <<'EOF' Usage: bash scripts/ops/netgescon-sync-git-changelog.sh [options] Options: --repo Source repository for commit history (default: cwd) --legacy-repo Legacy repo for long-term milestones (default: /home/michele/netgescon/netgescon-laravel) --output Output markdown file (default: docs/NETGESCON-GIT-AUTOCHANGELOG.md) --limit Number of commits to include (default: 180) Example: bash scripts/ops/netgescon-sync-git-changelog.sh --repo /home/michele/netgescon/netgescon-day0 EOF } while [[ $# -gt 0 ]]; do case "$1" in --repo) REPO_DIR="$2"; shift 2 ;; --legacy-repo) LEGACY_REPO_DIR="$2"; shift 2 ;; --output) OUTPUT_FILE="$2"; shift 2 ;; --limit) LIMIT="$2"; shift 2 ;; -h|--help) usage; exit 0 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac done [[ -d "$REPO_DIR/.git" ]] || { echo "Repo not found: $REPO_DIR" >&2; exit 1; } classify() { local msg="$1" local m m="$(printf '%s' "$msg" | tr '[:upper:]' '[:lower:]')" if [[ "$m" =~ ^feat(\(.+\))?: ]]; then echo "Aggiunto" elif [[ "$m" =~ ^fix(\(.+\))?: ]]; then echo "Risolto" elif [[ "$m" =~ ^perf(\(.+\))?:|^refactor(\(.+\))?: ]]; then echo "Migliorato" elif [[ "$m" =~ ^docs(\(.+\))?: ]]; then echo "Documentazione" elif [[ "$m" =~ ^chore(\(.+\))?:|^ops(\(.+\))?: ]]; then echo "Operativo" else echo "Aggiornato" fi } mkdir -p "$(dirname "$OUTPUT_FILE")" { echo "# NetGescon Git Auto Changelog" echo echo "Generato automaticamente da Git il $(date '+%d/%m/%Y %H:%M')." echo echo "Repository sorgente: \ \`$REPO_DIR\`" echo echo "## Milestone Storico" if [[ -d "$LEGACY_REPO_DIR/.git" ]]; then first_line="$(git -C "$LEGACY_REPO_DIR" log --reverse --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' | head -n 1 || true)" if [[ -n "$first_line" ]]; then IFS='|' read -r fh fd fs <<< "$first_line" echo "- Prima registrazione Git disponibile: **$fd** - \`$fh\` - $fs" fi if git -C "$LEGACY_REPO_DIR" cat-file -e 1448a3d^{commit} 2>/dev/null; then cdate="$(git -C "$LEGACY_REPO_DIR" show -s --date=format:'%d/%m/%Y' --pretty=format:'%ad' 1448a3d)" cmsg="$(git -C "$LEGACY_REPO_DIR" show -s --pretty=format:'%s' 1448a3d)" echo "- Commit storico dichiarato trovato: **$cdate** - \`1448a3d\` - $cmsg" else echo "- Commit storico dichiarato \`1448a3d\`: non presente nel repository locale corrente (possibile storico esterno)." fi else echo "- Repository legacy non disponibile in: \`$LEGACY_REPO_DIR\`." fi echo echo "## Ultimi Commit Classificati" echo echo "| Data | Commit | Tipo | Messaggio |" echo "| --- | --- | --- | --- |" git -C "$REPO_DIR" log --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' -n "$LIMIT" | while IFS='|' read -r hash date msg; do kind="$(classify "$msg")" clean_msg="$(printf '%s' "$msg" | sed 's/|/-/g')" echo "| $date | \`$hash\` | $kind | $clean_msg |" done echo echo "## Uso Operativo" echo echo "1. Aggiorna il changelog automatico:" echo echo "\`\`\`bash" echo "bash scripts/ops/netgescon-sync-git-changelog.sh" echo "\`\`\`" echo echo "2. Aggiorna changelog funzionale manuale (supporto/modifiche):" echo echo "\`\`\`bash" echo "bash scripts/ops/netgescon-add-modifica.sh --area \"\" --desc \"\" --type U" echo "\`\`\`" } > "$OUTPUT_FILE" echo "OK" echo "GENERATED: $OUTPUT_FILE"