127 lines
4.0 KiB
Bash
Executable File
127 lines
4.0 KiB
Bash
Executable File
#!/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 <path> Source repository for commit history (default: cwd)
|
|
--legacy-repo <path> Legacy repo for long-term milestones (default: /home/michele/netgescon/netgescon-laravel)
|
|
--output <path> Output markdown file (default: docs/NETGESCON-GIT-AUTOCHANGELOG.md)
|
|
--limit <n> 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
|
|
|
|
git_repo_ok() {
|
|
local repo_dir="$1"
|
|
|
|
[[ -d "$repo_dir" ]] || return 1
|
|
git -c "safe.directory=$repo_dir" -C "$repo_dir" rev-parse --git-dir >/dev/null 2>&1
|
|
}
|
|
|
|
git_repo_ok "$REPO_DIR" || { 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 git_repo_ok "$LEGACY_REPO_DIR"; then
|
|
first_line="$(git -c "safe.directory=$LEGACY_REPO_DIR" -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 "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" cat-file -e 1448a3d^{commit} 2>/dev/null; then
|
|
cdate="$(git -c "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" show -s --date=format:'%d/%m/%Y' --pretty=format:'%ad' 1448a3d)"
|
|
cmsg="$(git -c "safe.directory=$LEGACY_REPO_DIR" -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 "safe.directory=$REPO_DIR" -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 \"<Area>\" --desc \"<Descrizione>\" --type U"
|
|
echo "\`\`\`"
|
|
} > "$OUTPUT_FILE"
|
|
|
|
echo "OK"
|
|
echo "GENERATED: $OUTPUT_FILE"
|