Adds the git-workflow skill (Conventional Commits, auto-commit/push policy, changelog process), CHANGELOG.md seeded from history, and scripts/generate-changelog.sh to group commits by type. PRs remain manual by design.
75 lines
2.3 KiB
Bash
75 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Groups commits since the last tag (or full history if no tag exists) into
|
|
# Keep-a-Changelog sections by Conventional Commit type. Prints Markdown to
|
|
# stdout for review before pasting into CHANGELOG.md under [Unreleased].
|
|
#
|
|
# Usage: scripts/generate-changelog.sh [range]
|
|
# range git revision range, e.g. "v0.1.0..HEAD". Defaults to
|
|
# "<last-tag>..HEAD", or full history if no tag exists yet.
|
|
#
|
|
# Optional: set GITEA_TOKEN to also list merged PRs since the last tag
|
|
# (requires curl + jq; silently skipped if either is unavailable).
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_OWNER="devil"
|
|
REPO_NAME="youtube-studio-flow"
|
|
GITEA_HOST="https://git.devils.zone"
|
|
|
|
RANGE="${1:-}"
|
|
if [ -z "$RANGE" ]; then
|
|
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
|
if [ -n "$LAST_TAG" ]; then
|
|
RANGE="${LAST_TAG}..HEAD"
|
|
else
|
|
RANGE="HEAD"
|
|
fi
|
|
fi
|
|
|
|
section_for_type() {
|
|
case "$1" in
|
|
feat) echo "Added" ;;
|
|
fix) echo "Fixed" ;;
|
|
refactor|perf|style) echo "Changed" ;;
|
|
docs) echo "Docs" ;;
|
|
chore|build|ci) echo "Chore" ;;
|
|
revert) echo "Removed" ;;
|
|
*) echo "Other" ;;
|
|
esac
|
|
}
|
|
|
|
TMP_DIR=$(mktemp -d)
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
while IFS='|' read -r hash subject; do
|
|
[ -z "$hash" ] && continue
|
|
type=$(echo "$subject" | sed -nE 's/^([a-z]+)(\([^)]*\))?!?:.*/\1/p')
|
|
[ -z "$type" ] && type="other"
|
|
breaking=""
|
|
if echo "$subject" | grep -qE '^[a-z]+(\([^)]*\))?!:'; then
|
|
breaking=" **BREAKING**"
|
|
fi
|
|
section=$(section_for_type "$type")
|
|
echo "- ${subject}${breaking} (${hash})" >> "$TMP_DIR/$section"
|
|
done < <(git log "$RANGE" --pretty=format:'%h|%s' --no-merges; echo)
|
|
|
|
for section in Added Changed Fixed Removed Docs Chore Other; do
|
|
if [ -f "$TMP_DIR/$section" ]; then
|
|
echo "### $section"
|
|
cat "$TMP_DIR/$section"
|
|
echo ""
|
|
fi
|
|
done
|
|
|
|
if [ -n "${GITEA_TOKEN:-}" ] && command -v curl >/dev/null && command -v jq >/dev/null; then
|
|
SINCE_DATE=$(git log -1 --format=%aI $(echo "$RANGE" | sed 's/\.\.HEAD//') 2>/dev/null || echo "1970-01-01T00:00:00Z")
|
|
PRS=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_HOST}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls?state=closed&limit=50" \
|
|
| jq -r --arg since "$SINCE_DATE" '[.[] | select(.merged == true and .merged_at > $since)] | .[] | "- #\(.number) \(.title)"')
|
|
if [ -n "$PRS" ]; then
|
|
echo "### Pull Requests"
|
|
echo "$PRS"
|
|
echo ""
|
|
fi
|
|
fi
|