Merge pull request '發佈 jsc-gitea 0.0.9' (#15) from develop into master

Reviewed-on: #15
Reviewed-by: 系統管理員 <1+admin@noreply.localhost>
This commit was merged in pull request #15.
This commit is contained in:
2026-08-25 03:34:40 +00:00
4 changed files with 33 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jsc-gitea", "name": "jsc-gitea",
"version": "0.0.8", "version": "0.0.9",
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
"skills": "./skills", "skills": "./skills",
"author": { "author": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jsc-gitea", "name": "jsc-gitea",
"version": "0.0.8", "version": "0.0.9",
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
"skills": "./skills" "skills": "./skills"
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jsc-gitea", "name": "jsc-gitea",
"version": "0.0.8", "version": "0.0.9",
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
"skills": "./skills/" "skills": "./skills/"
} }
+30 -7
View File
@@ -46,22 +46,45 @@ case "$cmd" in
exit 0 ;; exit 0 ;;
esac esac
tea_token() { # 取 tea CLI 設定檔的 token(優先 default: true 的登入,否則第一個) tea_token() { # 取 tea CLI 設定檔的 token。$1=host-only 時,只回傳主機相符的登入
# 優先序:url 與 $GITEA_HOST 同主機的登入 > default: true 的登入 > 第一個登入。
# 主機比對必須排最前面:tea 可以同時登入多個站台,只看 default 會把 A 站的
# token 送去 B 站——那是憑證外洩,不是單純的取錯值。
cfg="${HOME}/.config/tea/config.yml" cfg="${HOME}/.config/tea/config.yml"
[ -f "$cfg" ] || return 1 [ -f "$cfg" ] || return 1
t=$(awk ' only_host="${1:-}"
/^ *- / { if (def && tok != "") { print tok; found=1; exit } tok=""; def=0 } want=$(printf '%s' "${GITEA_HOST:-}" | sed 's#^https\{0,1\}://##; s#/.*##')
/^ *token: */ { line=$0; sub(/^ *token: */,"",line); gsub(/"/,"",line) t=$(awk -v want="$want" -v only_host="$only_host" '
tok=line; if (first=="") first=line } function flush() {
if (tok == "") return
if (first == "") first = tok
if (want != "" && host == want) { match_tok = tok }
if (def) def_tok = tok
}
/^ *- / { flush(); tok=""; host=""; def=0 }
/^ *token: */ { line=$0; sub(/^ *token: */,"",line); gsub(/"/,"",line); tok=line }
/^ *url: */ { line=$0; sub(/^ *url: */,"",line); gsub(/"/,"",line)
sub(/^https?:\/\//,"",line); sub(/\/.*$/,"",line); host=line }
/^ *default: *true/ { def=1 } /^ *default: *true/ { def=1 }
END { if (!found) { if (def && tok != "") print tok; else print first } } END {
flush()
if (match_tok != "") { print match_tok; exit }
if (only_host == "host-only") exit
if (def_tok != "") print def_tok
else print first
}
' "$cfg") ' "$cfg")
[ -n "$t" ] && printf '%s\n' "$t" [ -n "$t" ] && printf '%s\n' "$t"
} }
: "${GITEA_HOST:?GITEA_HOST is required}" : "${GITEA_HOST:?GITEA_HOST is required}"
TEA_TOKEN=$(tea_token 2>/dev/null || true) TEA_TOKEN=$(tea_token 2>/dev/null || true)
if [ -z "${GITEA_TOKEN:-}" ]; then TEA_HOST_TOKEN=$(tea_token host-only 2>/dev/null || true)
if [ -n "$TEA_HOST_TOKEN" ]; then
# tea 有這個主機的專用登入就優先用它。$GITEA_TOKEN 是通用變數,未必屬於
# 這次要連的主機;把它送去別的站等於憑證外洩,比取錯值嚴重得多。
GITEA_TOKEN="$TEA_HOST_TOKEN"
elif [ -z "${GITEA_TOKEN:-}" ]; then
if [ -n "$TEA_TOKEN" ]; then GITEA_TOKEN="$TEA_TOKEN"; else if [ -n "$TEA_TOKEN" ]; then GITEA_TOKEN="$TEA_TOKEN"; else
: "${GITEA_TOKEN:?GITEA_TOKEN is required}" : "${GITEA_TOKEN:?GITEA_TOKEN is required}"
fi fi