Files
git/tools/slugify.sh
T
jiantw83andClaude Opus 5 4c9c9421c6 fix(git): 補齊稽核缺失並修掉護欄失效
What:依 jsc-meta:skill-check 的稽核結果修正技能與工具——補上每個步驟的可檢核完成條件、
把留在內文的標準輸入輸出流程下放 tools/、修正查表與退碼路由造成的誤判。

Why:稽核發現這些缺失會讓技能在實際執行時走錯分支或靜默通過。
完成條件缺漏是最常被違反的一項;退碼誤判與查表錯誤則會讓良性狀況被當成失敗。

How:逐項對照 references/guidelines.md 的審核檢查清單修正,新增的工具都有
documented exit codes,並以真實執行驗證每條路徑。

Who:jsc-meta:skill-check 例行稽核(2026-08-25)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 14:58:54 +08:00

32 lines
1.1 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 sh
# slugify.sh — 把分支類型與描述轉成 ASCII 分支名 slug。
# 用法: slugify.sh {type} {phrase}
# 規則: 全部轉小寫,非 a-z0-9 的字元換成連字號,
# 連續連字號合併成一個,並去除開頭與結尾的連字號。
# 輸出: {type}/{slug}(例如: slugify.sh feat "export report" → feat/export-report)
# 護欄: 輸入含非 ASCII 字元回傳 2;slug 化後為空回傳 3。兩者都印繁中錯誤到 stderr。
set -u
if [ "$#" -lt 2 ]; then
echo "用法: slugify.sh {type} {phrase}" >&2
exit 1
fi
TYPE="$1"
shift
PHRASE="$*"
slug=$(printf '%s' "$PHRASE" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9]/-/g' -e 's/-\{2,\}/-/g' -e 's/^-//' -e 's/-$//')
if printf '%s%s' "$TYPE" "$PHRASE" | LC_ALL=C grep -q '[^ -~]'; then
echo "錯誤: 分支名只允許 ASCII。請先把標題翻譯成英文短語,再交給 slugify.sh。" >&2
exit 2
fi
if [ -z "$slug" ]; then
echo "錯誤: 標題 slug 化後是空字串,組不出分支名。請先把標題翻譯成英文短語,再交給 slugify.sh。" >&2
exit 3
fi
printf '%s/%s\n' "$TYPE" "$slug"