fix(wiki): 依頁面類型解析 wiki repo 並統一 hash

This commit is contained in:
2026-08-21 16:53:17 +00:00
parent 51be91ce9d
commit 11082f648e
8 changed files with 148 additions and 24 deletions
+27 -10
View File
@@ -5,9 +5,10 @@
# gitea.sh repos <owner> # 列出 owner 底下可讀取的 repo(全名)
# gitea.sh default-branch <owner>/<repo> # 印出預設分支
# gitea.sh clone-url <owner>/<repo> # 印出 clone URL
# gitea.sh hash-id <text> # 產生 8 碼大寫 SHA-1 hash;首碼為 0-9/A/B/C 時改成 Hxxxxxxx
# gitea.sh wiki-repo <TYPE> # 解析頁面類型的 wiki 位置:
# TYPE = QUESTION|PLAN|ANALYZE|MAINTAIN|REPO|LOG(即頁名前綴)
# 依序取 JSC_WIKI_REPO_{TYPE} > JSC_WIKI_REPO;都未設定 exit 3(呼叫端須詢問使用者)
# TYPE = QUESTION|PLAN|ANALYZE|MAINTAIN|REPO|LOG|ERROR(即頁名前綴)
# 依序取 JSC_WIKI_REPO_{TYPE} > JSC_WIKI_REPO;不得跨類型代用;都未設定 exit 3
# gitea.sh wiki-list <owner>/<repo> # 列出 wiki 頁名
# gitea.sh wiki-get <owner>/<repo> <page> # 印出 wiki 頁 markdown;不存在時 exit 4
# gitea.sh wiki-put <owner>/<repo> <page> <file> # 建立或更新 wiki 頁(內容取自檔案)
@@ -21,6 +22,30 @@
# (~/.config/tea/config.yml,優先取 default: true 的登入);兩者皆無才失敗。
set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
resolve_wiki_repo() { # TYPE -> JSC_WIKI_REPO_{TYPE} -> JSC_WIKI_REPO
type=$(printf '%s' "${1:?TYPE required}" | tr a-z A-Z)
case "$type" in
QUESTION|PLAN|ANALYZE|MAINTAIN|REPO|LOG|ERROR) ;;
*) echo "unknown wiki type: $type" >&2; exit 2 ;;
esac
eval "v=\${JSC_WIKI_REPO_${type}:-}"
[ -n "$v" ] || v="${JSC_WIKI_REPO:-}"
if [ -n "$v" ]; then printf '%s\n' "$v"; else
echo "no wiki repo configured for $type (set JSC_WIKI_REPO_$type or JSC_WIKI_REPO)" >&2; exit 3
fi
}
cmd="${1:?usage: gitea.sh <command> ...}"; shift
case "$cmd" in
hash-id)
exec "$script_dir/hash-id" "$@" ;;
wiki-repo)
resolve_wiki_repo "${1-}"
exit 0 ;;
esac
tea_token() { # 取 tea CLI 設定檔的 token(優先 default: true 的登入,否則第一個)
cfg="${HOME}/.config/tea/config.yml"
[ -f "$cfg" ] || return 1
@@ -78,7 +103,6 @@ for i in items:
' "$1"
}
cmd="${1:?usage: gitea.sh <command> ...}"; shift
case "$cmd" in
owners)
{ req GET "/user" | json_field login
@@ -101,13 +125,6 @@ case "$cmd" in
clone-url)
or="${1:?owner/repo required}"
req GET "/repos/$or" | json_field clone_url ;;
wiki-repo)
type=$(printf '%s' "${1:?TYPE required}" | tr a-z A-Z)
eval "v=\${JSC_WIKI_REPO_$type:-}"
[ -n "$v" ] || v="${JSC_WIKI_REPO:-}"
if [ -n "$v" ]; then printf '%s\n' "$v"; else
echo "no wiki repo configured for $type (set JSC_WIKI_REPO_$type or JSC_WIKI_REPO)" >&2; exit 3
fi ;;
wiki-list)
or="${1:?owner/repo required}"
req GET "/repos/$or/wiki/pages?limit=200" | json_field title ;;