Merge pull request 'feat/tea-token-fallback-and-chart-first-wiki' (#3) from feat/tea-token-fallback-and-chart-first-wiki into develop
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
|
||||
"skills": "./skills",
|
||||
"author": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
|
||||
"skills": "./skills"
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ gitea.sh api <METHOD> <path> [json-file]
|
||||
|
||||
### `wiki`
|
||||
|
||||
Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG)解析 wiki 所在的 `{owner}/{repo}`,未設定環境變數時以決策樹詢問。
|
||||
Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG)解析 wiki 所在的 `{owner}/{repo}`,未設定環境變數時以決策樹詢問。頁面內容以圖表優先(mermaid 圖、markdown 表格),純文字為最後手段。
|
||||
|
||||
### `repo-sync`
|
||||
|
||||
@@ -54,7 +54,7 @@ Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZ
|
||||
| 變數 | 用途 | 未設定時 |
|
||||
| --- | --- | --- |
|
||||
| `GITEA_HOST` | Gitea 站台(可省略 scheme,預設 https) | 詢問使用者 |
|
||||
| `GITEA_TOKEN` | Gitea API token | 詢問使用者 |
|
||||
| `GITEA_TOKEN` | Gitea API token;缺少或遇 401/403 時自動退回 tea CLI 登入 token | 詢問使用者 |
|
||||
| `JSC_WIKI_REPO_{TYPE}` | 各類型 wiki 頁的 `{owner}/{repo}`;TYPE = QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG | 退回 `JSC_WIKI_REPO` |
|
||||
| `JSC_WIKI_REPO` | 共用預設的 wiki `{owner}/{repo}` | 詢問使用者 |
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步",
|
||||
"skills": "./skills/"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: wiki
|
||||
description: Read or write a Gitea wiki page through tools/gitea.sh with GITEA_TOKEN. Resolve the wiki repo per page type (QUESTION/PLAN/ANALYZE/MAINTAIN/REPO/LOG) via gitea.sh wiki-repo, falling back to JSC_WIKI_REPO or a decision-tree question. Used by jsc-ask, jsc-sdlc, and jsc-log for all wiki pages; not for repo code files.
|
||||
description: Read or write a Gitea wiki page through tools/gitea.sh with GITEA_TOKEN. Resolve the wiki repo per page type (QUESTION/PLAN/ANALYZE/MAINTAIN/REPO/LOG) via gitea.sh wiki-repo, falling back to JSC_WIKI_REPO or a decision-tree question. Page content is chart-first - prefer mermaid diagrams and markdown tables over plain prose. Used by jsc-ask, jsc-sdlc, and jsc-log for all wiki pages; not for repo code files.
|
||||
---
|
||||
|
||||
# wiki — read and write Gitea wiki pages
|
||||
@@ -27,3 +27,5 @@ Different page types can live in different `{owner}/{repo}` repos, classified by
|
||||
1. Page names must follow the wiki naming table in the skill guidelines (see `jsc-meta/references/guidelines.md`).
|
||||
2. To update a contents page (`*_CONTENTS`): `wiki-get` it first, apply the template to append or modify, then `wiki-put` the whole page back. Never overwrite entries owned by others.
|
||||
3. Write all wiki content in UTF-8 Traditional Chinese, per the STE100 output rule.
|
||||
4. Prefer visual forms for page content: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Plain running text is the last resort, kept short.
|
||||
5. Authentication fallback is built into `tools/gitea.sh`: on a missing GITEA_TOKEN or a 401/403 response it retries with the tea CLI login token automatically, so only report an auth failure when both paths fail.
|
||||
|
||||
+39
-11
@@ -17,24 +17,52 @@
|
||||
# gitea.sh repo-set <owner>/<repo> <description> [website] # 設定 repo 描述與網頁
|
||||
# gitea.sh api <METHOD> <path> [json-file] # 原始 API 呼叫(path 以 /repos/... 起始)
|
||||
# 環境變數: GITEA_HOST(例 https://gitea.jsc.idv.tw)、GITEA_TOKEN
|
||||
# GITEA_TOKEN 未設定,或請求遇 401/403 時,自動退回 tea CLI 的登入 token
|
||||
# (~/.config/tea/config.yml,優先取 default: true 的登入);兩者皆無才失敗。
|
||||
set -eu
|
||||
|
||||
tea_token() { # 取 tea CLI 設定檔的 token(優先 default: true 的登入,否則第一個)
|
||||
cfg="${HOME}/.config/tea/config.yml"
|
||||
[ -f "$cfg" ] || return 1
|
||||
t=$(awk '
|
||||
/^ *- / { if (def && tok != "") { print tok; found=1; exit } tok=""; def=0 }
|
||||
/^ *token: */ { line=$0; sub(/^ *token: */,"",line); gsub(/"/,"",line)
|
||||
tok=line; if (first=="") first=line }
|
||||
/^ *default: *true/ { def=1 }
|
||||
END { if (!found) { if (def && tok != "") print tok; else print first } }
|
||||
' "$cfg")
|
||||
[ -n "$t" ] && printf '%s\n' "$t"
|
||||
}
|
||||
|
||||
: "${GITEA_HOST:?GITEA_HOST is required}"
|
||||
: "${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
||||
TEA_TOKEN=$(tea_token 2>/dev/null || true)
|
||||
if [ -z "${GITEA_TOKEN:-}" ]; then
|
||||
if [ -n "$TEA_TOKEN" ]; then GITEA_TOKEN="$TEA_TOKEN"; else
|
||||
: "${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
||||
fi
|
||||
fi
|
||||
case "$GITEA_HOST" in http://*|https://*) HOST="$GITEA_HOST" ;; *) HOST="https://$GITEA_HOST" ;; esac
|
||||
API="${HOST%/}/api/v1"
|
||||
|
||||
req() { # METHOD path [json-file] -> body(HTTP >= 400 時 exit 4)
|
||||
req() { # METHOD path [json-file] -> body(HTTP >= 400 時 exit 4;401/403 以 tea token 重試一次)
|
||||
method="$1"; path="$2"; body_file="${3:-}"
|
||||
if [ -n "$body_file" ]; then
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary "@$body_file" "$API$path")
|
||||
else
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $GITEA_TOKEN" "$API$path")
|
||||
fi
|
||||
code=$(printf '%s' "$out" | tail -n1)
|
||||
retried=0
|
||||
while :; do
|
||||
if [ -n "$body_file" ]; then
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary "@$body_file" "$API$path")
|
||||
else
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $GITEA_TOKEN" "$API$path")
|
||||
fi
|
||||
code=$(printf '%s' "$out" | tail -n1)
|
||||
if [ "$retried" -eq 0 ] && { [ "$code" = 401 ] || [ "$code" = 403 ]; } \
|
||||
&& [ -n "$TEA_TOKEN" ] && [ "$TEA_TOKEN" != "$GITEA_TOKEN" ]; then
|
||||
GITEA_TOKEN="$TEA_TOKEN"; retried=1; continue
|
||||
fi
|
||||
break
|
||||
done
|
||||
printf '%s\n' "$out" | sed '$d'
|
||||
[ "$code" -lt 400 ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user