maestro/scripts/help-changelog-reminder.sh
oss-sync 29ccaf1e92
Some checks failed
CI / build-and-test (push) Has been cancelled
sync: update from private repo (dfadcd5f)
2026-06-23 06:38:48 +00:00

74 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Stop hook — ヘルプ/更新履歴の更新もれを知らせる(警告のみ・非ブロック)。
#
# フィーチャーブランチに「ユーザー向けのコード変更」が commit 済みなのに、
# ヘルプ (ui/src/content/help/) と更新履歴 (00-changelog.md) が未更新のとき、
# 目に見える警告を 1 つ出すだけ。作業はブロックしない(更新するかは開発者が判断)。
#
# 設計メモ:
# - main/master では何もしない(トランク自体には enforce しない)
# - 判定は base ブランチとの "commit 済み差分" のみ。編集途中(未コミット)では黙る
# - ヒューリスティックなので、内部リファクタ等で誤検知したら無視してよい
# `set -e` は使わない([ ... ] && exit の評価で意図せず抜けるのを避けるため)。
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd)"
[ -n "$ROOT" ] || exit 0
cd "$ROOT" 2>/dev/null || exit 0
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
case "$BRANCH" in
main|master|HEAD|"") exit 0 ;;
esac
# 差分の基準ブランチを決める。
BASE=""
for ref in origin/main main origin/master master; do
if git rev-parse --verify --quiet "$ref" >/dev/null 2>&1; then
BASE="$ref"
break
fi
done
[ -n "$BASE" ] || exit 0
# このブランチが base に対して触ったファイルcommit 済みのみ)。
CHANGED="$(git diff --name-only "$BASE"...HEAD 2>/dev/null)"
[ -n "$CHANGED" ] || exit 0
CHANGELOG="ui/src/content/help/00-changelog.md"
changelog_touched=0
user_facing=0
while IFS= read -r f; do
[ -n "$f" ] || continue
case "$f" in
"$CHANGELOG") changelog_touched=1 ;;
esac
case "$f" in
*.test.ts|*.test.tsx|*.spec.ts) ;; # テストは対象外
ui/src/content/help/*) ;; # ヘルプ本文そのものは対象外
ui/src/i18n/*) ;; # 文言だけの変更は対象外
ui/src/*|src/*|pieces/*) user_facing=1 ;; # ユーザーに影響しうるコード
esac
done <<< "$CHANGED"
# ユーザー向け変更が無い、または更新履歴を既に更新済みなら何も言わない。
[ "$user_facing" -eq 1 ] || exit 0
[ "$changelog_touched" -eq 0 ] || exit 0
MSG="📝 ヘルプ未更新のお知らせ: ブランチ '${BRANCH}' に機能コードの変更がありますが、更新履歴 (${CHANGELOG}) は未更新です。ユーザー向けの変更なら、該当するヘルプ (ui/src/content/help/*.md) と更新履歴に追記してください。内部リファクタ等で不要なら無視して構いません。"
# 可視の警告として出すだけdecision を設定しないので stop はブロックしない)。
# Stop フックは stdout の JSON `systemMessage` のみを画面に出すstderr は出ない)ため、
# 必ず stdout に JSON を書く。
if command -v python3 >/dev/null 2>&1; then
printf '{"systemMessage": %s}\n' "$(MSG="$MSG" python3 -c 'import json,os; print(json.dumps(os.environ["MSG"]))')"
else
# python3 が無い環境向けフォールバック。" と \ を手でエスケープして stdout に出す。
esc="$(printf '%s' "$MSG" | sed 's/\\/\\\\/g; s/"/\\"/g')"
printf '{"systemMessage": "%s"}\n' "$esc"
fi
exit 0