Merge pull request 'chore(release): 放行技能組稽核修正到預設分支' (#33) from develop into master
Reviewed-on: #33 Reviewed-by: 系統管理員 <1+admin@noreply.localhost>
This commit was merged in pull request #33.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步",
|
||||
"skills": "./skills",
|
||||
"author": {
|
||||
@@ -13,5 +13,12 @@
|
||||
"gitea",
|
||||
"skills",
|
||||
"cross-tool"
|
||||
]
|
||||
],
|
||||
"jsc": {
|
||||
"requires": {
|
||||
"jsc-ask": ">=0.0.6",
|
||||
"jsc-git": ">=0.0.9",
|
||||
"jsc-meta": ">=0.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步",
|
||||
"skills": "./skills"
|
||||
"skills": "./skills",
|
||||
"jsc": {
|
||||
"requires": {
|
||||
"jsc-ask": ">=0.0.6",
|
||||
"jsc-git": ">=0.0.9",
|
||||
"jsc-meta": ">=0.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# jsc-gitea — 給 AI 助理的指引
|
||||
|
||||
本 repo 是 jsc 技能組的 `gitea` domain(Gitea API 工具、Wiki 讀寫與存取庫批次同步),可同時被 Claude Code / Codex / Copilot / Antigravity / Kiro 使用。
|
||||
本 repo 是 jsc 技能組的 `gitea` domain(Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步),可同時被 Claude Code / Codex / Copilot / Antigravity / Kiro 使用。
|
||||
|
||||
## 規則
|
||||
|
||||
|
||||
@@ -28,25 +28,34 @@ gitea.sh repos <owner> # 列出 owner 的 repo 全名
|
||||
gitea.sh default-branch <owner>/<repo>
|
||||
gitea.sh clone-url <owner>/<repo>
|
||||
gitea.sh hash-id <text> # 產生 8 碼大寫 SHA-1;首碼 0-9/A/B/C 時改成 Hxxxxxxx
|
||||
gitea.sh wiki-repo <TYPE> # 解析頁面類型的 wiki 位置(TYPE = QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT / SKILLSET)
|
||||
gitea.sh wiki-repo <TYPE> # 解析頁面類型的 wiki 位置(TYPE = QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT / SKILLSET / TOOLING)
|
||||
gitea.sh wiki-list <owner>/<repo>
|
||||
gitea.sh wiki-get <owner>/<repo> <page> # 不存在 exit 4
|
||||
gitea.sh wiki-put <owner>/<repo> <page> <file> # 自動判斷新建或更新
|
||||
gitea.sh wiki-put <owner>/<repo> <page> <file> # 自動判斷新建或更新;會先要求確認
|
||||
gitea.sh wiki-url <owner>/<repo> <page> # 印出 wiki 頁絕對網址(取自 API 的 html_url);跨存取庫連結用
|
||||
gitea.sh pr-create <owner>/<repo> <head> <base> <title> <body-file>
|
||||
gitea.sh pr-create <owner>/<repo> <head> <base> <title> <body-file> # 會先要求確認
|
||||
gitea.sh pr-status <owner>/<repo> <pr-index> # 印出 {state} {merged} {mergeable}
|
||||
gitea.sh pr-get <owner>/<repo> <pr-index> # 印出 PR 的標題、base 分支與描述,供呼叫端比對有沒有差
|
||||
# 前三行固定 title、base、body 三個標記,第 4 行起是描述原文
|
||||
gitea.sh pr-edit <owner>/<repo> <pr-index> <title> <body-file>
|
||||
gitea.sh pr-of-branch <owner>/<repo> <branch> # 印出該分支目前開啟中的 PR(比對 head.ref)
|
||||
# 第 1 行 number,接著 title、base、body 三個標記,第 5 行起是描述原文
|
||||
# 結束碼 0=找到、2=用法錯誤、3=該分支沒有開啟中的 PR、4=API 失敗
|
||||
# 「沒有 PR」用 3 不用 4:混用會把金鑰失效讀成沒開過 PR,接著開出重複的 PR
|
||||
gitea.sh pr-edit <owner>/<repo> <pr-index> <title> <body-file> # 會先要求確認
|
||||
# 更新 PR 的標題與描述;描述從檔案讀,裝得下多行
|
||||
gitea.sh pr-comments <owner>/<repo> <pr-index> # 印出所有留言(issue 留言、審查評語、行內留言),第三欄帶 #id,依時間排序
|
||||
gitea.sh comment-reply <owner>/<repo> <pr-index> <issue|review|inline> <comment-id> <body-file>
|
||||
gitea.sh comment-reply <owner>/<repo> <pr-index> <issue|review|inline> <comment-id> <body-file> # 會先要求確認
|
||||
# 回覆本輪處理過的 PR 留言;inline 走 review comment reply,其餘補一則 PR 留言
|
||||
gitea.sh pr-depend <owner>/<repo> <pr-index> <dep-owner>/<dep-repo> <dep-index>
|
||||
gitea.sh pr-depend <owner>/<repo> <pr-index> <dep-owner>/<dep-repo> <dep-index> # 會先要求確認
|
||||
# 把 PR 掛上前置 PR 依賴;依賴未關閉前 Gitea 會阻擋合併
|
||||
gitea.sh repo-set <owner>/<repo> <description> [website] # 設定 repo 描述與網頁
|
||||
gitea.sh repo-set <owner>/<repo> <description> [website] # 會先要求確認
|
||||
gitea.sh markdown <file> # markdown 檔渲染成 HTML 片段(走 /markdown/raw)
|
||||
gitea.sh api <METHOD> <path> [json-file]
|
||||
# 全腳本共用結束碼: 0=成功、1=api 子命令請求失敗、2=用法錯誤
|
||||
# 3=wiki-repo 沒設定或 pr-of-branch 查無 PR、4=找不到(404)與 PR 系列 API 失敗
|
||||
# 5=wiki 頁沒有 html_url、7=金鑰失效或權限不足(401/403)、8=其他 API 失敗
|
||||
# 7 與 8 一定要跟 4 分開:認證失敗若被讀成「頁面不存在」,
|
||||
# 附加寫入就會變成整頁覆蓋,舊紀錄直接消失
|
||||
hash-id <text> # 與 gitea.sh hash-id 相同
|
||||
repo-sync.sh <owner>/<repo> [target-dir] # 同步單一存取庫;印出 cloned、updated、dirty {分支} 或 failed {原因}
|
||||
# 基準分支的優先序只在這支腳本裡;dirty 會把解析好的分支帶出來當 PR 的 base
|
||||
@@ -65,8 +74,14 @@ pr-watch.sh <owner>/<repo> <pr-index> [state-file]
|
||||
gitea-link.sh parse <url> # 解析 wiki 或議題連結;不是這兩種就 exit 3(呼叫端據此中止)
|
||||
issue.sh labels|label-ids|projects <owner>/<repo>
|
||||
issue.sh title|body|labels-of <owner>/<repo> <index>
|
||||
issue.sh create <owner>/<repo> <title> <body-file> [--labels <ids>] [--milestone <id>]
|
||||
issue.sh show <owner>/<repo> <index> # 一次拿齊標題、標籤與正文,只打一次 API
|
||||
# 四段固定格式:title、labels、body 標記,第 4 行起是正文
|
||||
issue.sh create <owner>/<repo> <title> <body-file> [--labels <ids>] [--milestone <id>] # 會先要求確認
|
||||
html-style.sh get|set|unset|list|layouts|styles # 種類對版型與風格的設定
|
||||
html-style.sh key wiki <頁名> # 推導種類:取第一個底線前的字首
|
||||
html-style.sh key issue <owner>/<repo> <編號> [--labels <名稱>[,<名稱>]]
|
||||
# 推導種類:依序試每個標籤,第一個設定過的勝出,都沒有就回 ISSUE:DEFAULT
|
||||
# 輸出一行「{種類}<TAB>{依據}」;結束碼 1=取不到標籤
|
||||
html-render.sh --markdown <檔案> --title <標題> --out <輸出檔> [--layout] [--style] [--subtitle] [--source-url]
|
||||
```
|
||||
|
||||
@@ -107,11 +122,11 @@ html-render.sh --markdown <檔案> --title <標題> --out <輸出檔> [--layout]
|
||||
|
||||
### `wiki`
|
||||
|
||||
Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR)解析 wiki 所在的 `{owner}/{repo}`,先讀對應的 `JSC_WIKI_REPO_{TYPE}`,再退回 `JSC_WIKI_REPO`,不同類型不可互相代用。頁面內容以圖表優先(mermaid 圖、markdown 表格),純文字每節最多三句。
|
||||
Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT / SKILLSET / TOOLING)解析 wiki 所在的 `{owner}/{repo}`,先讀對應的 `JSC_WIKI_REPO_{TYPE}`,再退回 `JSC_WIKI_REPO`,不同類型不可互相代用。頁面內容以圖表優先(mermaid 圖、markdown 表格),純文字每節最多三句。
|
||||
|
||||
### `repo-sync`
|
||||
|
||||
存取庫批次同步:列出 owner → 使用者選擇 → 逐 repo(sub agent)呼叫 `tools/repo-sync.sh` clone 或更新;回報 `dirty {分支}` 的存取庫交給 `jsc-git:pr`,base 直接用腳本帶出來的那個分支;PR 依 `jsc-meta/references/pr-report.md` 集中成表。
|
||||
存取庫批次同步:列出 owner → 使用者選擇 → 各存取庫併行(一個 repo 一個 sub agent)呼叫 `tools/repo-sync.sh` clone 或更新;回報 `dirty {分支}` 的存取庫交給 `jsc-git:pr`,base 直接用腳本帶出來的那個分支;PR 依 `jsc-meta/references/pr-report.md` 集中成表。
|
||||
|
||||
### `html-export`
|
||||
|
||||
@@ -134,14 +149,15 @@ Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZ
|
||||
| `GITEA_HOST` | Gitea 站台(可省略 scheme,預設 https) | 詢問使用者 |
|
||||
| `GITEA_TOKEN` | Gitea API token;缺少或遇 401/403 時自動退回 tea CLI 登入 token | 詢問使用者 |
|
||||
| `JSC_WIKI_REPO_{TYPE}` | 各類型 wiki 頁的 `{owner}/{repo}`;TYPE = QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT | 退回 `JSC_WIKI_REPO`,不做跨類型代用 |
|
||||
| `JSC_WIKI_REPO_SKILLSET` | `SKILLSET_CONTENTS`、`SKILLSET_{HASH}`(技能組異動報告)的 `{owner}/{repo}`;雜湊來源為 `{owner}/{repo}` | 退回 `JSC_WIKI_REPO`,不做跨類型代用 |
|
||||
| `JSC_WIKI_REPO_SKILLSET` | `SKILLSET_CONTENTS`、`SKILLSET_{HASH}`(技能組異動報告)的 `{owner}/{repo}` | 退回 `JSC_WIKI_REPO`,不做跨類型代用 |
|
||||
| `JSC_WIKI_REPO_TOOLING` | `TOOLING_CONTENTS`、`TOOLING_{HASH}`(技能盤點)的 `{owner}/{repo}` | 退回 `JSC_WIKI_REPO`,不做跨類型代用 |
|
||||
| `JSC_WIKI_REPO` | 共用預設的 wiki `{owner}/{repo}` | 詢問使用者 |
|
||||
| `JSC_HOME` | `pr-watch.sh` 狀態檔的根目錄 | 預設 `~/.jsc` |
|
||||
| `JSC_PR_WATCH_INTERVAL` | `pr-watch.sh` 的輪詢間隔秒數(正整數) | 預設 60 |
|
||||
|
||||
## Hash 規則
|
||||
|
||||
`{HASH}` 由 `tools/hash-id` 產生。先算 `SHA-1` 前 8 碼並轉大寫。若首碼是數字或 `A`、`B`、`C`,就改成 `H` 加上原本的前 7 碼,維持 8 碼長度。
|
||||
`{HASH}` 一律由 `tools/hash-id` 產生。長度、大小寫、`H` 前綴與各頁型的雜湊來源,唯一來源是 `jsc-meta` 的 [`references/guidelines.md`](https://gitea.jsc.idv.tw/plugins/meta/src/branch/master/references/guidelines.md)「Wiki 頁命名總表」,這裡不再複述一份。
|
||||
|
||||
## 相關 domain
|
||||
|
||||
|
||||
+9
-2
@@ -1,6 +1,13 @@
|
||||
{
|
||||
"name": "jsc-gitea",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步",
|
||||
"skills": "./skills/"
|
||||
"skills": "./skills/",
|
||||
"jsc": {
|
||||
"requires": {
|
||||
"jsc-ask": ">=0.0.6",
|
||||
"jsc-git": ">=0.0.9",
|
||||
"jsc-meta": ">=0.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,16 @@ The link is the only input. The output is one file that opens anywhere, with no
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Link gate.** Run `tools/gitea-link.sh parse {url}`. Exit 3 or no link in the request: **stop and report it**. Never fall back to the working directory's remote or to a page name the user mentioned in passing. Completion condition: `kind` is `wiki` or `issue`, and `repo` plus `page` or `index` are known.
|
||||
2. **Work out the kind key** — it decides which template applies:
|
||||
- wiki page → `WIKI:{prefix}`, where the prefix is the page name up to the first underscore (`ANALYZE_D3F1A2B0` → `WIKI:ANALYZE`; a page with no underscore uses the whole name).
|
||||
- issue → run `tools/issue.sh labels-of {repo} {index}` and try `ISSUE:{label}` for each label in order; the first one `tools/html-style.sh get` answers with source `project` or `global` wins. No label matches: use `ISSUE:DEFAULT`.
|
||||
1. **Link gate.** Run `tools/gitea-link.sh parse {url}`. Exit 3, or no link in the request: **stop and report it**. Exit 2 is a usage error — fix the arguments and call again. Never fall back to the working directory's remote or to a page name the user mentioned in passing. This gate runs first because it stops the whole skill more often than any other check, and it costs no API call. Completion condition: `kind` is `wiki` or `issue`, and `repo` plus `page` or `index` are known.
|
||||
2. **Host gate.** Confirm `GITEA_HOST` holds a value in the current shell; ask for it per the `jsc-ask:ask` rules when it does not. `GITEA_TOKEN` needs no inventory — `tools/gitea.sh` resolves it, retries once with the tea CLI login token, and exits 7 when neither works. Completion condition: `GITEA_HOST` holds a value.
|
||||
3. **Run these three tracks at the same time.** They are independent, so start them in one batch rather than one after another; only the issue branch of track B waits, and only for track A's `labels` line.
|
||||
- **Track A — content.** Wiki page: `jsc-gitea:wiki` `wiki-get {repo} {page}` for the markdown, plus `wiki-url {repo} {page}` for the source URL; route its exit codes by that skill's table (4 = no such page, 7 = the key is invalid, 8 = other API failure), and every one of them stops this skill with the page name in the report. Issue: `tools/issue.sh show {repo} {index}`, which returns title, labels and body from **one** API call — never call `title`, `body` and `labels-of` separately on the same issue. Exit 1 means the issue could not be read: stop and report the issue number; exit 2 is a usage error, so fix the arguments and call again.
|
||||
- **Track B — template.** Wiki page: `tools/html-style.sh key wiki {page}`. Issue: `tools/html-style.sh key issue {repo} {index} --labels {the names from track A's labels line}`, which spends no extra API call; the labels line arrives before the body, so this track starts well before track A finishes. The script owns both derivation rules — the page-name prefix, and trying each label in order until one is configured. It prints `{key}<TAB>{reason}`; keep the reason, it is how the report says which prefix or label produced the key. Exit 1 means the labels could not be read: **report that first**, then continue with `ISSUE:DEFAULT` and say in the report that the template was picked without labels. Exit 2 is a usage error — fix the arguments and call again. Then run `tools/html-style.sh get {key}`, which always prints `layout<TAB>style<TAB>source`. **Read the third column and report it**: `project` or `global` means the user configured this kind; `default` means it fell back to the DEFAULT row; `builtin` means nothing is configured at all and `report`/`minimal` was used. For `default` and `builtin`, tell the user in one line that `jsc-gitea:html-style` can set this kind's own template.
|
||||
- **Track C — destination.** Ask per the `jsc-ask:ask` rules where the file goes, proposing `./.jsc/html/{page-or-issue}.html`. State the impact scope: a path inside a repository gets committed unless it is ignored.
|
||||
|
||||
Completion condition: exactly one kind key is chosen, and you can say which label or prefix produced it.
|
||||
3. Run `tools/html-style.sh get {key}`. It always prints `layout<TAB>style<TAB>source`. **Read the third column and report it**: `project` or `global` means the user configured this kind; `default` means it fell back to the DEFAULT row; `builtin` means nothing is configured at all and `report`/`minimal` was used. For `default` and `builtin`, tell the user in one line that `jsc-gitea:html-style` can set this kind's own template. Completion condition: layout, style and source are reported before anything is rendered.
|
||||
4. Fetch the content: `jsc-gitea:wiki` `wiki-get` for a page, or `tools/issue.sh title` plus `tools/issue.sh body` for an issue. Exit 4 (page missing) or an API failure stops the skill with the page name or issue number in the report. Completion condition: the markdown and the document title are in hand.
|
||||
5. **Prepare the markdown — this step MUST run as a sub agent.** Convert `[[display|page]]` wiki links to absolute URLs from `wiki-url`; the renderer does not resolve them, so they would ship as literal brackets. Strip personal data — an exported file travels further than the page it came from. Leave everything else exactly as written; this step never rewrites the content. Completion condition: no `[[...]]` remains, and the diff against the source is limited to link conversion and personal-data removal.
|
||||
6. Ask per `jsc-ask:ask` rules where the file goes, proposing `./.jsc/html/{page-or-issue}.html`. State the impact scope: a path inside a repository gets committed unless it is ignored. Completion condition: the user has confirmed one output path.
|
||||
7. Render: `tools/html-render.sh --markdown {file} --title {title} --layout {layout} --style {style} --source-url {absolute URL} --out {path}`. Exit 1 means Gitea's renderer failed — report it and stop, with no half-rendered file left behind. Completion condition: the file exists, and the report names its path, the layout, the style and where that pair came from.
|
||||
Completion condition: the markdown and the document title are in hand, exactly one kind key is chosen with the reason that produced it, the layout, style and source are reported, and the user has confirmed one output path.
|
||||
4. **Prepare the markdown — this step MUST run as a sub agent.** Convert `[[display|page]]` wiki links to absolute URLs from `wiki-url`; the renderer does not resolve them, so they would ship as literal brackets. Strip personal data — an exported file travels further than the page it came from. Leave everything else exactly as written; this step never rewrites the content. Completion condition: no `[[...]]` remains, and the diff against the source is limited to link conversion and personal-data removal.
|
||||
5. Render: `tools/html-render.sh --markdown {file} --title {title} --layout {layout} --style {style} --source-url {absolute URL} --out {path}`. Route every exit code: 0 → the path it printed is the finished file; 1 → Gitea's renderer or the write failed, so report it and stop, with no half-rendered file left behind; 2 → a usage error or a missing markdown file, so fix the arguments and call again; 4 → the layout or style template file is gone, so report which pair was asked for and send the user to `jsc-gitea:html-style` rather than editing the configuration by hand. Completion condition: the file exists, and the report names its path, the layout, the style and where that pair came from.
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ One kind of page, one layout, one style. `jsc-gitea:html-export` reads what this
|
||||
## Steps
|
||||
|
||||
1. **Settle the kind key.** Show the current configuration with `tools/html-style.sh list` first, then ask per `jsc-ask:ask` rules which kind this run sets. The three shapes are fixed: `WIKI:{page-name prefix}` (`WIKI:PLAN`, `WIKI:ANALYZE`, `WIKI:LOG` …), `ISSUE:{label name}` (`ISSUE:bug`), and `DEFAULT` for everything that matches nothing else. Every option states its impact scope — `DEFAULT` changes every kind that has no row of its own. Completion condition: exactly one key is agreed, and its current value from `tools/html-style.sh get {key}` has been read back with its source column.
|
||||
2. **Pick the layout — offer all six.** Run `tools/html-style.sh layouts`; it prints each name with its Traditional Chinese description, taken from the template file itself. Present all six as options per `jsc-ask:ask` rules, each with what it does to the content (`report` builds a table of contents beside the text, `slide` turns every `##` into a keyboard-flipped page, `dashboard` turns them into cards, `spec` freezes table headers, `timeline` strings them along a line, `onepager` narrows everything into one printable page). Completion condition: the user has picked one layout name that the script listed.
|
||||
2. **Pick the layout — offer all six.** Run `tools/html-style.sh layouts`; it prints each name with its Traditional Chinese description, taken from the template file itself. `list`, `get`, `layouts` and `styles` exit 2 on a usage error — fix the arguments and call again. An empty listing means the template directory is missing, which stops this skill: report the path rather than offering a name the export cannot use. Present all six as options per `jsc-ask:ask` rules, each with what it does to the content (`report` builds a table of contents beside the text, `slide` turns every `##` into a keyboard-flipped page, `dashboard` turns them into cards, `spec` freezes table headers, `timeline` strings them along a line, `onepager` narrows everything into one printable page). Completion condition: the user has picked one layout name that the script listed.
|
||||
3. **Pick the style — offer all five.** Run `tools/html-style.sh styles` and present every one it prints (`minimal`, `corporate`, `dark`, `print`, `vivid`) with its description. Never trim the list to a shortlist: the point of this skill is that the user sees the whole set. Completion condition: the user has picked one style name that the script listed.
|
||||
4. **Pick the scope.** Ask per `jsc-ask:ask` rules: `--project` writes `./.jsc/html-styles`, which only applies inside this working directory and is committed with the repository; `--global` writes `$JSC_HOME/html-styles.conf`, which follows the user across every project on this machine. State that the project file wins whenever both hold the same key. Completion condition: the user has picked one scope.
|
||||
5. Write it: `tools/html-style.sh set {key} {layout} {style} [--project|--global]`. Exit 4 means the name is not one of the listed templates — go back to step 2 or 3 rather than editing the file by hand. Completion condition: the script exits 0 and prints the file it wrote.
|
||||
5. Write it: `tools/html-style.sh set {key} {layout} {style} [--project|--global]`. Route every exit code: 0 → the file it printed now holds the pair; 1 → the settings file's directory could not be created, so report the path and stop, since nothing was written; 2 → a usage error, such as a missing name or a scope flag that is neither `--project` nor `--global`, so fix the arguments and call again; 4 → the layout or style name has no template file, so go back to step 2 or step 3 rather than editing the settings file by hand. Completion condition: the script exits 0 and prints the file it wrote.
|
||||
6. Read it back with `tools/html-style.sh get {key}` and report the resolved layout, style and source. Completion condition: the source column shows `project` or `global`, matching the scope chosen in step 4.
|
||||
|
||||
## Rules
|
||||
|
||||
@@ -7,11 +7,12 @@ description: Batch-sync all readable repos of a chosen Gitea owner into the work
|
||||
|
||||
## Steps
|
||||
|
||||
1. Before calling `tools/gitea.sh`, resolve `GITEA_HOST` and `GITEA_TOKEN` from the current shell environment (also check `tea login list` for a usable login token when `GITEA_TOKEN` is unset). If `GITEA_HOST` is unresolvable, or `GITEA_TOKEN` is unset and no tea login token exists either, ask the user for the missing value per the `jsc-ask:ask` rules before proceeding to any `tools/gitea.sh` call. Done when `GITEA_HOST` holds a value and either `GITEA_TOKEN` or a tea login token is available.
|
||||
2. Run `tools/gitea.sh owners` to list every `{owner}` the user can read. Done when the command has printed at least one `{owner}`.
|
||||
3. Ask the user which `{owner}` to sync, per the `jsc-ask:ask` rules. Every option states the owner's repo count and impact scope. Done when the user has named exactly one `{owner}` from that list.
|
||||
4. Run `tools/gitea.sh repos {owner}` to list every readable `{repo}` under that owner. Done when the command has printed the full `{owner}/{repo}` list for the chosen owner.
|
||||
5. Sync each `{repo}` one by one. This step **MUST run as a sub agent** (one sub agent per repo):
|
||||
1. Run `tools/repo-sync.sh {owner}/{repo}`. The script owns the clone-versus-pull decision and the base-branch precedence, so run no `git clone`, `git checkout` or `git pull` by hand, and derive no branch name yourself. Route on its single line of output: `cloned` or `updated` → this repo is done; `dirty {branch}` → go to substep 2; `failed {reason}` → record that reason and stop this repo. Done when exactly one of those four outcomes is recorded for this repo.
|
||||
1. Run `tools/gitea.sh owners` to list every `{owner}` the user can read. The script reads `GITEA_HOST` and `GITEA_TOKEN` from the inherited environment and retries once with the tea CLI login token, so take no separate inventory first — a missing value surfaces here, before any work is done. Route on the result: at least one `{owner}` printed → next step; the script stops with `GITEA_HOST is required` or `GITEA_TOKEN is required` → ask the user for that one value per the `jsc-ask:ask` rules and run the command again, guessing no host; exit 7 → report that the key is invalid or lacks permission, and stop; exit 8 → report the HTTP status in the message, and stop; exit 0 with no output → report that this key can read no owner, and stop. Done when at least one `{owner}` is printed, or the run stopped with one of those reasons.
|
||||
2. Ask the user which `{owner}` to sync, per the `jsc-ask:ask` rules. Every option states the owner's repo count and impact scope. Done when the user has named exactly one `{owner}` from that list.
|
||||
3. Run `tools/gitea.sh repos {owner}` to list every readable `{repo}` under that owner. Exit 7 and exit 8 stop the run with the same report as step 1; an empty list means this owner has no readable repo and there is nothing to sync. Done when the command has printed the full `{owner}/{repo}` list for the chosen owner, or the run stopped.
|
||||
4. Sync every `{repo}` from step 3 **in parallel — one sub agent per repo, all launched in the same batch**, never one after another. Each repo has its own directory and its own remote, so nothing makes them wait for each other, and a hundred-repo owner otherwise costs a hundred sequential clones. Each sub agent does this:
|
||||
1. Run `tools/repo-sync.sh {owner}/{repo}`. The script owns the clone-versus-pull decision and the base-branch precedence, so run no `git clone`, `git checkout` or `git pull` by hand, and derive no branch name yourself. Route on its single line of output: `cloned` or `updated` (exit 0) → this repo is done; `dirty {branch}` (exit 0) → go to substep 2; `failed {reason}` (exit 1) → record that reason and stop this repo. Done when exactly one of those four outcomes is recorded for this repo.
|
||||
2. `dirty {branch}` → call `jsc-git:pr` with `{branch}` from that same output line as the base, passed through verbatim. It commits, branches, pushes and opens the PR itself, so add none of those steps. Done when `jsc-git:pr` returns the PR URL and reports it with the table format in `jsc-meta/references/pr-report.md`.
|
||||
6. Report the sync result for every repo: cloned, updated, PR table row, or the failure reason. Done when every `{repo}` from step 4 carries one of those four results, and all PR rows share one table when more than one PR exists.
|
||||
|
||||
Done when every repo's sub agent has returned one of those outcomes; one repo failing never cancels the others.
|
||||
5. Report the sync result for every repo: cloned, updated, PR table row, or the failure reason. Done when every `{repo}` from step 3 carries one of those four results, and all PR rows share one table when more than one PR exists.
|
||||
|
||||
@@ -9,12 +9,20 @@ The wiki link is the only input. Everything else — repository, page name, host
|
||||
|
||||
## Steps
|
||||
|
||||
1. **Link gate.** Run `tools/gitea-link.sh parse {url}` on the link the user gave. Exit 3, no link in the request, or `kind=issue` (this skill reads wiki pages, not issues) all mean the same thing: **stop and report which one it was**. Never ask for a repository name instead, and never fall back to the working directory's remote — a page written into the wrong repository's issue tracker is public and hard to take back. Completion condition: `kind=wiki`, and `repo`, `page` and `host` are known.
|
||||
2. Read the page with `jsc-gitea:wiki` (`wiki-get {repo} {page}`). Exit 4 means the page does not exist — stop and report the page name. Take the page's absolute URL from `wiki-url` in the same pass; it goes into the issue body. Completion condition: the page's markdown and its absolute URL are both in hand.
|
||||
3. **Draft the issue — this step MUST run as a sub agent.** Title: the page's first heading, or the page name when it has none. Body: the page content in Traditional Chinese, opening with a 「來源:{絕對網址}」 line so the issue points back at the wiki. Convert `[[display|page]]` links to absolute URLs (`wiki-url`), because `[[...]]` resolves only inside a wiki. Drop personal data — an issue is read by more people than a wiki page. Completion condition: title and body file exist, the body carries the source line, and no `[[...]]` link is left in it.
|
||||
4. **Labels come from what the repository already has.** Run `tools/issue.sh labels {repo}`, propose the fitting ones with a reason each, and confirm per `jsc-ask:ask` rules — every option states its impact scope (a label drives filters and board rules, so a wrong one routes the work to the wrong queue). Turn the confirmed names into ids with `tools/issue.sh label-ids`. An empty label list, or nothing fitting: ask whether to create the issue with no label, and record that answer. **Never invent a label that the repository does not have.** Completion condition: the user has confirmed a label set — possibly empty — and its ids are resolved.
|
||||
5. **Project board.** Run `tools/issue.sh projects {repo}`. Exit 3 means this Gitea has no board API: say so plainly, and hand the user the board URL the script printed so they can drag the issue in themselves. A board list comes back: let the user pick one per `jsc-ask:ask` rules, attach it, and report the failure verbatim if the attach call is refused. Completion condition: the issue is either attached to a board, or the report states in one line that the board link is still outstanding and who has to do it.
|
||||
6. Create the issue: `tools/issue.sh create {repo} {title} {body-file} [--labels {ids}]`. Report the `index=` and `url=` it prints. Completion condition: the issue URL is reported to the user, together with the labels applied and the board status from step 5.
|
||||
1. **Input gate — the link and the host, checked in the same batch.** Neither depends on the other, so run both before anything else and report every failure found, not just the first.
|
||||
- **The link.** Run `tools/gitea-link.sh parse {url}` on the link the user gave. Exit 3, no link in the request, or `kind=issue` (this skill reads wiki pages, not issues) all mean the same thing: **stop and report which one it was**. Exit 2 is a usage error — fix the arguments and call again. Never ask for a repository name instead, and never fall back to the working directory's remote — a page written into the wrong repository's issue tracker is public and hard to take back.
|
||||
- **The host.** Confirm `GITEA_HOST` holds a value in the current shell; ask for it per the `jsc-ask:ask` rules when it does not. `GITEA_TOKEN` needs no inventory — `tools/gitea.sh` resolves it, retries once with the tea CLI login token, and exits 7 when neither works.
|
||||
|
||||
Completion condition: the parse printed `kind=wiki` with `repo`, `page` and `host` known, **and** `GITEA_HOST` holds a value — both, or the run has stopped with the reason named.
|
||||
2. **Run these three tracks at the same time.** The label list and the board list depend on the repository only, not on the page, so they start in the same batch as the read rather than queueing behind the draft.
|
||||
- **Track A — read and draft.** Read the page with `jsc-gitea:wiki` (`wiki-get {repo} {page}`) and take its absolute URL from `wiki-url` in the same pass. Route the exit codes by that skill's table: 4 means the page does not exist, 7 means the key is invalid or lacks permission, 8 is any other API failure — all three stop this skill with the page name in the report. **Drafting MUST run as a sub agent.** Title: the page's first heading, or the page name when it has none. Body: the page content in Traditional Chinese, opening with a 「來源:{絕對網址}」 line so the issue points back at the wiki. Convert `[[display|page]]` links to absolute URLs (`wiki-url`), because `[[...]]` resolves only inside a wiki. Drop personal data — an issue is read by more people than a wiki page.
|
||||
- **Track B — label list.** Run `tools/issue.sh labels {repo}`. Exit 1 means the label list could not be read: stop and report it, because the alternative is inventing labels. Exit 2 is a usage error — fix the arguments and call again.
|
||||
- **Track C — board list.** Run `tools/issue.sh projects {repo}`. Exit 3 means this Gitea has no board API — keep the board URL the script printed for step 4. Exit 1 means the call failed for another reason: report it and treat the board link as outstanding. Exit 2 is a usage error — fix the arguments and call again.
|
||||
|
||||
Completion condition: the title and body file exist with the source line and no `[[...]]` left in the body, the repository's label list is in hand or the run has stopped, and the board list is either in hand or recorded as unavailable.
|
||||
3. **Labels come from what the repository already has.** Propose the fitting ones from track B's list with a reason each, and confirm per `jsc-ask:ask` rules — every option states its impact scope (a label drives filters and board rules, so a wrong one routes the work to the wrong queue). Turn the confirmed names into ids with `tools/issue.sh label-ids {repo} {names}`. Exit 4 means a name is not in the repository: go back to the list and pick again, never create the label to make the command pass. Exit 1 means the call failed — report it and stop. An empty label list, or nothing fitting: ask whether to create the issue with no label, and record that answer. **Never invent a label that the repository does not have.** Completion condition: the user has confirmed a label set — possibly empty — and its ids are resolved.
|
||||
4. **Project board.** Track C returned a board list: let the user pick one per `jsc-ask:ask` rules, attach it, and report the failure verbatim if the attach call is refused. Track C exited 3: say plainly that this Gitea has no board API, and hand the user the board URL the script printed so they can drag the issue in themselves. Completion condition: the issue is either attached to a board, or the report states in one line that the board link is still outstanding and who has to do it.
|
||||
5. Create the issue: `tools/issue.sh create {repo} {title} {body-file} [--labels {ids}]`. The script asks for confirmation before it writes, so expect that prompt and hand the user the title, the labels and the board it is about to apply. Exit 0: report the `index=` and `url=` it prints. Exit 1 means no issue was created — report that plainly, and hand back the path of the drafted body file so the draft is not lost. Exit 2 is a usage error, usually a body file that is not there — fix the arguments and call again. Completion condition: the issue URL is reported to the user together with the labels applied and the board status from step 4, or the report states that no issue was created and where the draft is.
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
+30
-12
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: wiki
|
||||
description: Read or write a Gitea wiki page through tools/gitea.sh and tools/hash-id. Resolve the wiki repo per page type with JSC_WIKI_REPO_{TYPE} first, then JSC_WIKI_REPO, and ask only when neither is set. Page content is chart-first - prefer mermaid diagrams and markdown tables over plain prose. Callers are jsc-ask, jsc-sdlc, jsc-log, jsc-hooks for its ERROR pages, jsc-cli for its CHECK pages, and jsc-meta for its SKILLSET pages. Use for any wiki page in the skill set; not for repo code files.
|
||||
description: Read or write a Gitea wiki page through tools/gitea.sh and tools/hash-id. Resolve the wiki repo per page type with JSC_WIKI_REPO_{TYPE} first, then JSC_WIKI_REPO, and ask only when neither is set. Page content is chart-first - prefer mermaid diagrams and markdown tables over plain prose. Callers are jsc-ask, jsc-sdlc, jsc-log, jsc-hooks for its ERROR pages, jsc-cli for its CHECK pages, and jsc-meta for its SKILLSET and TOOLING pages. Use for any wiki page in the skill set; not for repo code files.
|
||||
---
|
||||
|
||||
# wiki — read and write Gitea wiki pages
|
||||
@@ -11,26 +11,44 @@ Every wiki operation in the jsc skill set goes through this skill. One entry poi
|
||||
|
||||
Different page types can live in different `{owner}/{repo}` repos, classified by the page-name prefix.
|
||||
|
||||
1. Before asking the user, inspect the current shell environment for the needed repo variables and Gitea connection variables: `JSC_WIKI_REPO_{TYPE}`, `JSC_WIKI_REPO`, `GITEA_HOST`, and `GITEA_TOKEN` (also check `tea login list` for a usable login token when `GITEA_TOKEN` is unset). Use inherited shell values first; only ask when the needed repo or connection value cannot be resolved after that check. Done when every one of those variables is either resolved from the environment or listed as missing.
|
||||
2. Run `tools/gitea.sh wiki-repo {TYPE}` (TYPE = the page-name prefix). Allowed types are `QUESTION`, `PLAN`, `ANALYZE`, `DELIVER`, `MAINTAIN`, `REPO`, `LOG`, `LEARN`, `ERROR`, `CHECK`, `REPORT`, and `SKILLSET`. Resolution order is `JSC_WIKI_REPO_{TYPE}` first, then `JSC_WIKI_REPO`. Never borrow another type's repo. Done when the command has printed exactly one `{owner}/{repo}`, or exited 3 and sent this page type to step 3.
|
||||
3. On exit 3 (neither is set after env inspection), ask the user for that page type's `{owner}/{repo}` per the `jsc-ask:ask` rules, and suggest setting `JSC_WIKI_REPO_{TYPE}` (can differ per type) or `JSC_WIKI_REPO` (shared default). Done when the user has supplied one `{owner}/{repo}` for that page type.
|
||||
1. **Host gate.** Confirm `GITEA_HOST` holds a value in the current shell. When it is missing, ask for it per the `jsc-ask:ask` rules before any `tools/gitea.sh` call that reaches the API; otherwise the first thing the user sees is the script's `GITEA_HOST is required` line instead of a decision-tree question. `GITEA_TOKEN` needs no inventory here — the script resolves it, retries once with the tea CLI login token, and exits 7 when neither works. Done when `GITEA_HOST` holds a value.
|
||||
2. Run `tools/gitea.sh wiki-repo {TYPE}` (TYPE = the page-name prefix). Allowed types are `QUESTION`, `PLAN`, `ANALYZE`, `DELIVER`, `MAINTAIN`, `REPO`, `LOG`, `LEARN`, `ERROR`, `CHECK`, `REPORT`, `SKILLSET`, and `TOOLING`. The script reads `JSC_WIKI_REPO_{TYPE}` first and `JSC_WIKI_REPO` second, straight from the inherited environment, so take no separate inventory of those two variables. Never borrow another type's repo. Done when the command has printed exactly one `{owner}/{repo}`, or exited 3 and sent this page type to step 3, or exited 2 on a type outside the list above and stopped the run.
|
||||
3. On exit 3 (neither variable is set), ask the user for that page type's `{owner}/{repo}` per the `jsc-ask:ask` rules, and suggest setting `JSC_WIKI_REPO_{TYPE}` (can differ per type) or `JSC_WIKI_REPO` (shared default). Done when the user has supplied one `{owner}/{repo}` for that page type.
|
||||
|
||||
## Operations
|
||||
|
||||
| Action | Command |
|
||||
| --- | --- |
|
||||
| list pages | `tools/gitea.sh wiki-list {owner}/{repo}` |
|
||||
| read page | `tools/gitea.sh wiki-get {owner}/{repo} {page}` (exit 4 when missing) |
|
||||
| write page | write the content to a temp file first, then `tools/gitea.sh wiki-put {owner}/{repo} {page} {file}` (creates or updates automatically) |
|
||||
| page URL | `tools/gitea.sh wiki-url {owner}/{repo} {page}` — the page's absolute URL, taken from the API's `html_url` (exit 4 when the page is missing) |
|
||||
| read page | `tools/gitea.sh wiki-get {owner}/{repo} {page}` |
|
||||
| write page | write the content to a temp file first, then `tools/gitea.sh wiki-put {owner}/{repo} {page} {file}` (asks for confirmation first, then creates or updates) |
|
||||
| page URL | `tools/gitea.sh wiki-url {owner}/{repo} {page}` — the page's absolute URL, taken from the API's `html_url` |
|
||||
|
||||
When writing a page, link same-type pages with the `[[display|page]]` form (display text on the LEFT) and cross-type pages with the absolute URL from `wiki-url`, because `[[...]]` resolves only inside one wiki. Full rules and the direction trap: `references/wiki-links.md`.
|
||||
|
||||
## Exit codes
|
||||
|
||||
Route every `tools/gitea.sh` call in this skill on its exit code. A code with no branch below stops the run and gets reported as it is.
|
||||
|
||||
| Code | Meaning | What this skill does |
|
||||
| --- | --- | --- |
|
||||
| 0 | success | use the output |
|
||||
| 2 | usage error, or a page type outside the allowed list | fix the arguments, then call again; never repeat the same call unchanged |
|
||||
| 3 | `wiki-repo`: neither `JSC_WIKI_REPO_{TYPE}` nor `JSC_WIKI_REPO` is set | go to step 3 and ask |
|
||||
| 4 | HTTP 404: `wiki-get` and `wiki-url` found no such page | for a read the caller expects to succeed, stop and report the page name; this is the **only** code that opens the create path of rule 4 — write the page from the template instead of appending |
|
||||
| 5 | `wiki-url`: the page exists but the API returned no `html_url` | stop and report it. Link inside the same wiki with `[[display\|page]]`; a cross-repo link has no absolute URL to point at, so do not fabricate one |
|
||||
| 7 | HTTP 401 or 403 after the tea-token retry: the key is invalid or lacks permission | **stop the whole operation and report the key problem.** Never read this as an empty or missing page, and never take the create path of rule 4: writing a fresh page over one you could not read destroys the record that is still there |
|
||||
| 8 | any other API failure, HTTP status in the message | stop and report that status; call again only after the cause is fixed |
|
||||
|
||||
## Rules
|
||||
|
||||
1. Page names must follow the wiki naming table in the skill guidelines (see `jsc-meta/references/guidelines.md`).
|
||||
2. Use `tools/hash-id` for `{HASH}` values. It returns the first 8 uppercase SHA-1 hex chars, or `H` plus the first 7 chars when the raw hash starts with `0-9`, `A`, `B`, or `C`.
|
||||
3. 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.
|
||||
4. Write all wiki content in UTF-8 Traditional Chinese, per the STE100 output rule.
|
||||
5. Prefer visual forms for page content: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Prose is capped at 3 sentences per section, and a sentence stays only when neither a mermaid diagram nor a markdown table can carry the same information.
|
||||
6. `tools/gitea.sh` retries once with the tea CLI login token when `GITEA_TOKEN` is missing or the response is 401/403. Report a failure only after that retry also fails.
|
||||
2. Use `tools/hash-id` for `{HASH}` values. It returns the first 8 uppercase SHA-1 hex chars, or `H` plus the first 7 chars when the raw hash starts with `0-9`, `A`, `B`, or `C`. Exit 1 means this machine has neither `sha1sum` nor `shasum`: stop, report that one of them has to be installed, and compute no hash by hand — a hand-made page name lands the content on a page nobody else reads.
|
||||
3. To update a contents page (`*_CONTENTS`): `wiki-get` it first, apply the template to append or modify, then `wiki-put` the whole page back — the write asks for confirmation before it goes out. Never overwrite entries owned by others. Whether the page may be created from the template instead is decided by rule 4, and by nothing else.
|
||||
4. **Only exit 4 means the page is not there yet — this rule binds every "create it if it does not exist" path, without exception.** It is not limited to contents pages: a content page (`*_{HASH}`), a work log, an error page, a report, any page at all, follows the same branch.
|
||||
- **Correct branch.** Read the page with `wiki-get`. Exit 0 means the page exists, so append or modify the content that came back and `wiki-put` the whole page. Exit 4 (HTTP 404) is the one and only code that permits creating a new page from the template.
|
||||
- **Exit 7 and exit 8 abort.** Exit 7 (HTTP 401 or 403) and exit 8 (any other API failure) both mean the old content is unknown, never that the page is missing. Stop the operation and report the exit code with its cause. Create no page, write nothing, and do not retry the same call unchanged.
|
||||
- **Why.** Wiki writes in this skill set are append-not-overwrite, and that semantics rests entirely on reading the old page back first. Reading a 401 as a 404 makes the caller believe it holds a brand-new page and `wiki-put` a fresh template over a live one, and the whole earlier record is gone — the write carries no merge and no backup.
|
||||
5. Write all wiki content in UTF-8 Traditional Chinese, per the STE100 output rule.
|
||||
6. Prefer visual forms for page content: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Prose is capped at 3 sentences per section, and a sentence stays only when neither a mermaid diagram nor a markdown table can carry the same information.
|
||||
7. `tools/gitea.sh` retries once with the tea CLI login token when `GITEA_TOKEN` is missing or the response is 401/403. Report a failure only after that retry also fails.
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
# check-wiki-rules — 驗證 wiki repo 解析與 hash-id 規則。
|
||||
# 涵蓋 TYPES 列的每一種頁面類型,每種三項:專用變數優先、退回共用變數、不得跨類型代用。
|
||||
# 全部通過印 OK 並 exit 0;任一項不符印出差異並 exit 1。
|
||||
# 結束碼: 0=全部通過,stdout 印 OK
|
||||
# 1=有一項不符,stderr 印出 {項目}: want=… got=… 之後立刻停住,不續跑其餘項目。
|
||||
# 只有 0 與 1 兩種;這支不吃參數,也沒有用法錯誤那條路。
|
||||
set -eu
|
||||
|
||||
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
gitea="$dir/gitea.sh"
|
||||
hash_id="$dir/hash-id"
|
||||
|
||||
TYPES='QUESTION PLAN ANALYZE DELIVER MAINTAIN REPO LOG LEARN ERROR CHECK REPORT SKILLSET'
|
||||
TYPES='QUESTION PLAN ANALYZE DELIVER MAINTAIN REPO LOG LEARN ERROR CHECK REPORT SKILLSET TOOLING'
|
||||
|
||||
fail() {
|
||||
printf '%s\n' "$1" >&2
|
||||
|
||||
+186
-31
@@ -7,7 +7,7 @@
|
||||
# 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|DELIVER|MAINTAIN|REPO|LOG|LEARN|ERROR|CHECK|REPORT|SKILLSET(即頁名前綴)
|
||||
# TYPE = QUESTION|PLAN|ANALYZE|DELIVER|MAINTAIN|REPO|LOG|LEARN|ERROR|CHECK|REPORT|SKILLSET|TOOLING(即頁名前綴)
|
||||
# 依序取 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
|
||||
@@ -16,6 +16,18 @@
|
||||
# gitea.sh pr-create <owner>/<repo> <head> <base> <title> <body-file> # 建立 PR,印出 PR URL
|
||||
# gitea.sh pr-status <owner>/<repo> <pr-index> # 印出「{state} {merged} {mergeable}」
|
||||
# gitea.sh pr-get <owner>/<repo> <pr-index> # 印出 PR 的標題、base 分支與描述,供比對用
|
||||
# gitea.sh pr-of-branch <owner>/<repo> <branch> # 印出該分支目前開啟中的 PR(比對 head.ref)
|
||||
# 輸出格式固定四段,描述放最後,因為只有它會多行:
|
||||
# 第 1 行 number<TAB>{PR 編號}
|
||||
# 第 2 行 title<TAB>{標題}
|
||||
# 第 3 行 base<TAB>{base 分支}
|
||||
# 第 4 行 body (單獨一個字,當描述的起始標記)
|
||||
# 第 5 行起 描述原文,一直到檔尾
|
||||
# 後三段與 pr-get 完全一致,只在最前面多一行 number。呼叫端取編號用 head -n1 | cut -f2-,
|
||||
# 取描述用 tail -n +5,全程不必解析 JSON,也不必再打一次 pr-get。
|
||||
# 結束碼: 0=找到 2=用法錯誤 3=該分支沒有開啟中的 PR 4=API 失敗
|
||||
# 「沒有 PR」必須是 3,不能借用通用的 API 失敗碼:兩者混用會把金鑰失效讀成
|
||||
# 「這個分支還沒開 PR」,呼叫端接著就開出第二支重複的 PR。
|
||||
# gitea.sh pr-edit <owner>/<repo> <pr-index> <title> <body-file> # 更新 PR 的標題與描述
|
||||
# gitea.sh pr-comments <owner>/<repo> <pr-index> # 印出所有留言(issue 留言、審查評語、行內留言),第三欄帶 #id
|
||||
# gitea.sh comment-reply <owner>/<repo> <pr-index> <issue|review|inline> <comment-id> <body-file>
|
||||
@@ -28,14 +40,26 @@
|
||||
# 環境變數: GITEA_HOST(例 https://gitea.jsc.idv.tw)、GITEA_TOKEN
|
||||
# GITEA_TOKEN 未設定,或請求遇 401/403 時,自動退回 tea CLI 的登入 token
|
||||
# (~/.config/tea/config.yml,優先取 url 與 GITEA_HOST 同主機的登入,其次 default: true);兩者皆無才失敗。
|
||||
# 結束碼: 0=成功 1=api 子命令的請求失敗 2=用法錯誤或不認得的指令
|
||||
# 3=wiki-repo 的該類型沒有設定存取庫、pr-of-branch 的該分支沒有開啟中的 PR
|
||||
# 4=找不到(HTTP 404,含 wiki 頁不存在)、PR 系列子命令的 API 失敗,
|
||||
# 以及 pr-of-branch 翻過 50 頁上限仍沒結束(分頁沒有前進)
|
||||
# 5=wiki 頁沒有 html_url
|
||||
# 7=Gitea 金鑰失效或權限不足(HTTP 401/403)
|
||||
# 8=其他 API 失敗,訊息帶 HTTP 狀態
|
||||
# 7 與 8 是 2026-08 實測補上的:原本認證失敗、伺服器錯誤全部被歸成「頁面不存在」,
|
||||
# 而 wiki 寫入的「附加不覆蓋」判斷就靠讀得到舊頁,誤判會直接蓋掉舊紀錄。
|
||||
set -eu
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
confirm_write() {
|
||||
sh "$script_dir/write-confirm.sh" "$1" "$2"
|
||||
}
|
||||
|
||||
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|DELIVER|MAINTAIN|REPO|LOG|LEARN|ERROR|CHECK|REPORT|SKILLSET) ;;
|
||||
QUESTION|PLAN|ANALYZE|DELIVER|MAINTAIN|REPO|LOG|LEARN|ERROR|CHECK|REPORT|SKILLSET|TOOLING) ;;
|
||||
*) echo "unknown wiki type: $type" >&2; exit 2 ;;
|
||||
esac
|
||||
eval "v=\${JSC_WIKI_REPO_${type}:-}"
|
||||
@@ -100,7 +124,31 @@ fi
|
||||
case "$GITEA_HOST" in http://*|https://*) HOST="$GITEA_HOST" ;; *) HOST="https://$GITEA_HOST" ;; esac
|
||||
API="${HOST%/}/api/v1"
|
||||
|
||||
req() { # METHOD path [body-file] -> body(HTTP >= 400 時 exit 4;401/403 以 tea token 重試一次)
|
||||
# 最後一次請求的 HTTP 狀態碼寫進檔案,不是變數:req 幾乎都在 $(...) 裡跑,
|
||||
# 子行程設的變數回不到主行程,狀態碼會在回來的路上不見。
|
||||
REQ_CODE_FILE=$(mktemp)
|
||||
trap 'rm -f "$REQ_CODE_FILE"' EXIT
|
||||
|
||||
req_code() { cat "$REQ_CODE_FILE" 2>/dev/null || true; }
|
||||
|
||||
api_fail() { # $1=情境說明 -> 依最後一次的 HTTP 狀態分流退出
|
||||
# 失敗成因一定要分開回報。全部歸成「找不到」是最危險的一種簡化:
|
||||
# 認證失敗看起來就會像頁面不存在,呼叫端接著就用新頁的邏輯往上蓋。
|
||||
_c=$(req_code)
|
||||
case "$_c" in
|
||||
401|403)
|
||||
echo "[jsc][gitea][ERR]:$1 —— Gitea 金鑰失效或權限不足(HTTP $_c)。請換一支有效的 GITEA_TOKEN,或重新 tea login 之後再跑一次。" >&2
|
||||
exit 7 ;;
|
||||
404)
|
||||
echo "[jsc][gitea][ERR]:$1 —— 找不到(HTTP 404)。" >&2
|
||||
exit 4 ;;
|
||||
*)
|
||||
echo "[jsc][gitea][ERR]:$1 —— API 失敗(HTTP ${_c:-無回應})。" >&2
|
||||
exit 8 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
req() { # METHOD path [body-file] -> body(HTTP >= 400 時回非 0;401/403 以 tea token 重試一次)
|
||||
# 送出的 Content-Type 由 REQ_CONTENT_TYPE 決定,預設 application/json;
|
||||
# /markdown/raw 這種吃純文字的端點要先改成 text/plain 再呼叫。
|
||||
method="$1"; path="$2"; body_file="${3:-}"
|
||||
@@ -122,6 +170,7 @@ req() { # METHOD path [body-file] -> body(HTTP >= 400 時 exit 4;401/403 以
|
||||
fi
|
||||
break
|
||||
done
|
||||
printf '%s' "$code" > "$REQ_CODE_FILE"
|
||||
printf '%s\n' "$out" | sed '$d'
|
||||
[ "$code" -lt 400 ]
|
||||
}
|
||||
@@ -139,15 +188,21 @@ for i in items:
|
||||
|
||||
case "$cmd" in
|
||||
owners)
|
||||
{ req GET "/user" | json_field login
|
||||
req GET "/user/orgs?limit=50" | json_field username; } | sort -u ;;
|
||||
# req 不直接接管線:管線的結束狀態取自 json_field,會把 req 的失敗整個吃掉,
|
||||
# 金鑰失效看起來就變成「查詢成功,一個 owner 都沒有」。
|
||||
me=$(req GET "/user") || api_fail "讀不到目前登入的使用者"
|
||||
orgs=$(req GET "/user/orgs?limit=50") || api_fail "讀不到組織清單"
|
||||
{ printf '%s' "$me" | json_field login
|
||||
printf '%s' "$orgs" | json_field username; } | sort -u ;;
|
||||
repos)
|
||||
owner="${1:?owner required}"
|
||||
# 分頁抓 owner 的 repo(org 與 user 端點擇一成功)
|
||||
page=1
|
||||
while :; do
|
||||
out=$(req GET "/orgs/$owner/repos?limit=50&page=$page" 2>/dev/null) \
|
||||
|| out=$(req GET "/users/$owner/repos?limit=50&page=$page")
|
||||
if ! out=$(req GET "/orgs/$owner/repos?limit=50&page=$page" 2>/dev/null); then
|
||||
out=$(req GET "/users/$owner/repos?limit=50&page=$page") \
|
||||
|| api_fail "列不出 $owner 的存取庫"
|
||||
fi
|
||||
names=$(printf '%s' "$out" | json_field full_name)
|
||||
[ -n "$names" ] || break
|
||||
printf '%s\n' "$names"
|
||||
@@ -155,17 +210,30 @@ case "$cmd" in
|
||||
done ;;
|
||||
default-branch)
|
||||
or="${1:?owner/repo required}"
|
||||
req GET "/repos/$or" | json_field default_branch ;;
|
||||
out=$(req GET "/repos/$or") || api_fail "讀不到存取庫 $or"
|
||||
printf '%s' "$out" | json_field default_branch ;;
|
||||
clone-url)
|
||||
or="${1:?owner/repo required}"
|
||||
req GET "/repos/$or" | json_field clone_url ;;
|
||||
out=$(req GET "/repos/$or") || api_fail "讀不到存取庫 $or"
|
||||
printf '%s' "$out" | json_field clone_url ;;
|
||||
wiki-list)
|
||||
or="${1:?owner/repo required}"
|
||||
req GET "/repos/$or/wiki/pages?limit=200" | json_field title ;;
|
||||
# 先接變數、先看 req 自己的結束碼,再餵給 json_field。直接接管線的話,
|
||||
# 結束狀態會變成 json_field 的:金鑰失效回 401 時,這裡看起來像「列出成功,
|
||||
# 一頁都沒有」,呼叫端就把整個 wiki 判成空的。
|
||||
out=$(req GET "/repos/$or/wiki/pages?limit=200") || api_fail "列不出 $or 的 wiki 頁"
|
||||
printf '%s' "$out" | json_field title ;;
|
||||
wiki-get)
|
||||
# 失敗成因一定要分開:技能組寫 wiki 的語意是「附加一節、不覆蓋舊紀錄」,
|
||||
# 判斷依據就是先把舊內容讀回來。金鑰失效回 401 若被翻譯成「頁面不存在」,
|
||||
# 呼叫端會把它當成一張新頁整份蓋上去,舊紀錄就沒了。
|
||||
# 只有真的 404 才回 4;401/403 回 7,其他失敗回 8 並帶 HTTP 狀態。
|
||||
or="${1:?owner/repo required}"; page="${2:?page required}"
|
||||
if ! out=$(req GET "/repos/$or/wiki/page/$page" 2>/dev/null); then
|
||||
echo "wiki page not found: $page" >&2; exit 4
|
||||
case "$(req_code)" in
|
||||
404) echo "wiki page not found: $page" >&2; exit 4 ;;
|
||||
*) api_fail "讀不到 wiki 頁 $or/$page" ;;
|
||||
esac
|
||||
fi
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys,base64
|
||||
@@ -178,7 +246,10 @@ sys.stdout.write(base64.b64decode(d.get("content_base64","")).decode("utf-8"))
|
||||
# 只有絕對網址會通:[[頁名]] 與 markdown 相對連結都只在同一個 wiki 內解析。
|
||||
or="${1:?owner/repo required}"; page="${2:?page required}"
|
||||
if ! out=$(req GET "/repos/$or/wiki/page/$page" 2>/dev/null); then
|
||||
echo "wiki page not found: $page" >&2; exit 4
|
||||
case "$(req_code)" in
|
||||
404) echo "wiki page not found: $page" >&2; exit 4 ;;
|
||||
*) api_fail "讀不到 wiki 頁 $or/$page" ;;
|
||||
esac
|
||||
fi
|
||||
url=$(printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
@@ -190,6 +261,7 @@ sys.stdout.write(json.load(sys.stdin).get("html_url") or "")
|
||||
printf '%s\n' "$url" ;;
|
||||
wiki-put)
|
||||
or="${1:?owner/repo required}"; page="${2:?page required}"; file="${3:?content file required}"
|
||||
confirm_write "寫入 wiki 頁" "$page"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys,base64
|
||||
@@ -197,28 +269,48 @@ title,path=sys.argv[1],sys.argv[2]
|
||||
content=open(path,"rb").read()
|
||||
print(json.dumps({"title":title,"content_base64":base64.b64encode(content).decode()}))
|
||||
' "$page" "$file" > "$tmp"
|
||||
# 先探路只為了決定新建或更新。探路失敗的成因若是認證問題,接下來的 POST 也會失敗,
|
||||
# 由 api_fail 照實回報,不會靜靜蓋掉既有頁面。
|
||||
if req GET "/repos/$or/wiki/page/$page" >/dev/null 2>&1; then
|
||||
req PATCH "/repos/$or/wiki/page/$page" "$tmp" >/dev/null
|
||||
req PATCH "/repos/$or/wiki/page/$page" "$tmp" >/dev/null \
|
||||
|| { rm -f "$tmp"; api_fail "更新 wiki 頁 $or/$page 失敗"; }
|
||||
else
|
||||
req POST "/repos/$or/wiki/new" "$tmp" >/dev/null
|
||||
req POST "/repos/$or/wiki/new" "$tmp" >/dev/null \
|
||||
|| { rm -f "$tmp"; api_fail "建立 wiki 頁 $or/$page 失敗"; }
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
echo "OK $page" ;;
|
||||
pr-create)
|
||||
or="${1:?owner/repo required}"; head="${2:?head required}"; base="${3:?base required}"
|
||||
title="${4:?title required}"; body_file="${5:?body file required}"
|
||||
# 描述檔缺席要回 2「用法錯誤」,跟 pr-edit、comment-reply 一致。少了這道檢查,
|
||||
# 缺檔會變成 python3 的 open() 例外加 exit 1,呼叫端讀成「API 失敗」而去重試。
|
||||
# 這道檢查排在確認之前:先擋掉自己打錯的參數,才不會問完使用者又失敗。
|
||||
[ -f "$body_file" ] || { echo "找不到描述檔: $body_file" >&2; exit 2; }
|
||||
confirm_write "建立 PR" "$or#$title"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys
|
||||
print(json.dumps({"head":sys.argv[1],"base":sys.argv[2],"title":sys.argv[3],
|
||||
"body":open(sys.argv[4],encoding="utf-8").read()}))
|
||||
' "$head" "$base" "$title" "$body_file" > "$tmp"
|
||||
req POST "/repos/$or/pulls" "$tmp" | json_field html_url
|
||||
rm -f "$tmp" ;;
|
||||
if ! out=$(req POST "/repos/$or/pulls" "$tmp"); then
|
||||
rm -f "$tmp"; printf '%s\n' "$out" >&2; exit 4
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
printf '%s' "$out" | json_field html_url ;;
|
||||
pr-status)
|
||||
# 印出「{state} {merged} {mergeable}」,供呼叫端判斷 PR 是否已合併。
|
||||
# 查不到 PR(404)維持印「? none none」並 exit 0:pr-watch.sh 的白名單靠這個字串
|
||||
# 判成 exit 3「查不到該 PR」。認證或連線失敗改回非 0,不再混進同一個字串裡。
|
||||
or="${1:?owner/repo required}"; idx="${2:?pr index required}"
|
||||
req GET "/repos/$or/pulls/$idx" | python3 -c '
|
||||
if ! out=$(req GET "/repos/$or/pulls/$idx" 2>/dev/null); then
|
||||
case "$(req_code)" in
|
||||
404) echo '? none none'; exit 0 ;;
|
||||
*) api_fail "讀不到 PR $or#$idx" ;;
|
||||
esac
|
||||
fi
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
p=json.load(sys.stdin)
|
||||
print("%s %s %s" % (p.get("state","?"), str(p.get("merged")).lower(), str(p.get("mergeable")).lower()))
|
||||
@@ -244,11 +336,58 @@ print("base\t%s" % ((p.get("base") or {}).get("ref") or ""))
|
||||
print("body")
|
||||
sys.stdout.write(p.get("body") or "")
|
||||
' ;;
|
||||
pr-of-branch)
|
||||
# 找出某條分支目前開啟中的 PR。比對的是 head.ref,不是分支名的字串包含:
|
||||
# feat/報表 與 feat/報表/main 只差一段,用包含比對會回錯的那一支。
|
||||
# 輸出格式與 pr-get 對齊並多帶 index 與 url,呼叫端(jsc-git:commit、jsc-git:pr)
|
||||
# 拿到就能直接比對標題與描述,不必再打一次 pr-get。
|
||||
or="${1:?owner/repo required}"; branch="${2:?branch required}"
|
||||
# 頁數上限。只靠「回空陣列」收尾的迴圈,遇上忽略 page 參數的站台或代理會一直
|
||||
# 拿到同一頁而永遠停不下來——沒有輸出、也沒有結束碼,呼叫端只看得到卡住。
|
||||
page=1
|
||||
max_page=50
|
||||
while :; do
|
||||
if [ "$page" -gt "$max_page" ]; then
|
||||
echo "[jsc][gitea][ERR]:列 $or 的開啟中 PR 超過 $max_page 頁仍沒有結束,分頁沒有前進(站台或代理可能忽略 page 參數)。" >&2
|
||||
exit 4
|
||||
fi
|
||||
# req 的輸出先接進變數再解析。寫成 req ... | python3 的話,管線的結束狀態
|
||||
# 取自 python,401 會變成「解不到相符的 PR」而回 3,正好踩中重複開 PR 那個坑。
|
||||
if ! out=$(req GET "/repos/$or/pulls?state=open&limit=50&page=$page"); then
|
||||
echo "[jsc][gitea][ERR]:列不出 $or 的開啟中 PR(HTTP $(req_code))。" >&2
|
||||
exit 4
|
||||
fi
|
||||
res=$(printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
want=sys.argv[1]
|
||||
d=json.load(sys.stdin)
|
||||
if not isinstance(d,list) or not d:
|
||||
print("__EMPTY__"); raise SystemExit
|
||||
for p in d:
|
||||
if ((p.get("head") or {}).get("ref") or "") == want:
|
||||
print("number\t%s" % (p.get("number") or p.get("index") or ""))
|
||||
print("title\t%s" % (p.get("title") or ""))
|
||||
print("base\t%s" % ((p.get("base") or {}).get("ref") or ""))
|
||||
print("body")
|
||||
sys.stdout.write(p.get("body") or "")
|
||||
raise SystemExit
|
||||
print("__NONE__")
|
||||
' "$branch") || { echo "[jsc][gitea][ERR]:$or 的 PR 清單解不開。" >&2; exit 4; }
|
||||
case "$res" in
|
||||
__NONE__) page=$((page+1)); continue ;;
|
||||
__EMPTY__) break ;;
|
||||
esac
|
||||
printf '%s\n' "$res"
|
||||
exit 0
|
||||
done
|
||||
echo "[jsc][gitea][ERR]:分支 $branch 沒有開啟中的 PR。" >&2
|
||||
exit 3 ;;
|
||||
pr-edit)
|
||||
# 更新 PR 的標題與描述。描述從檔案讀,才裝得下多行內容與全形標點。
|
||||
or="${1:?owner/repo required}"; idx="${2:?pr index required}"
|
||||
title="${3:?title required}"; body_file="${4:?body file required}"
|
||||
[ -f "$body_file" ] || { echo "找不到描述檔: $body_file" >&2; exit 2; }
|
||||
confirm_write "更新 PR" "$or#$idx"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys
|
||||
@@ -264,14 +403,28 @@ print(json.dumps({"title":sys.argv[1],"body":open(sys.argv[2],encoding="utf-8").
|
||||
# 三個來源都要讀:issue 留言、review 本體的評語、review 內逐行的程式碼留言。
|
||||
# 只讀 issue 留言會漏掉真正的審查意見,那正是需要修正的部分。
|
||||
# 類型欄保留在第三欄,僅追加 id;呼叫端用第一欄做 since 比對時不受影響。
|
||||
# req 一律先接進變數、先看它自己的結束碼,再餵給 python3。寫成 req … | python3
|
||||
# 的話,管線的結束狀態取自 python:金鑰失效回 401 時,這裡會印出一份空的留言清單
|
||||
# 並回 0,呼叫端(jsc-git:pr)就判成「這支 PR 沒有任何審查意見」,整輪留言修正被跳過。
|
||||
or="${1:?owner/repo required}"; idx="${2:?pr index required}"
|
||||
{ req GET "/repos/$or/issues/$idx/comments?limit=100" | python3 -c '
|
||||
issues=$(req GET "/repos/$or/issues/$idx/comments?limit=100") \
|
||||
|| api_fail "讀不到 PR $or#$idx 的留言"
|
||||
reviews=$(req GET "/repos/$or/pulls/$idx/reviews?limit=100") \
|
||||
|| api_fail "讀不到 PR $or#$idx 的審查清單"
|
||||
rids=$(printf '%s' "$reviews" | python3 -c '
|
||||
import json,sys
|
||||
for r in json.load(sys.stdin):
|
||||
if r.get("comments_count", 0) or r.get("id"): print(r["id"])
|
||||
')
|
||||
# 行內留言逐則抓,抓失敗一樣要當成失敗。收集在 $lines 裡最後才排序:
|
||||
# 把 api_fail 放進管線的話,它只結束子行程,主流程照樣往下印出殘缺清單。
|
||||
lines=$(mktemp)
|
||||
{ printf '%s' "$issues" | python3 -c '
|
||||
import json,sys
|
||||
for c in json.load(sys.stdin):
|
||||
body=" ".join((c.get("body") or "").split())
|
||||
if body: print("%s\t%s\t留言#%s\t%s" % (c.get("created_at",""), (c.get("user") or {}).get("login","?"), c.get("id","?"), body))
|
||||
'
|
||||
reviews=$(req GET "/repos/$or/pulls/$idx/reviews?limit=100")
|
||||
printf '%s' "$reviews" | python3 -c '
|
||||
import json,sys
|
||||
for r in json.load(sys.stdin):
|
||||
@@ -281,26 +434,26 @@ for r in json.load(sys.stdin):
|
||||
# 兩者都是呼叫端要據以決策的事實,過濾掉會看不見 PR 真正的狀態。
|
||||
print("%s\t%s\t審查#%s(%s)\t%s" % (r.get("submitted_at",""), (r.get("user") or {}).get("login","?"), r.get("id","?"), st, body or "(無評語)"))
|
||||
'
|
||||
for rid in $(printf '%s' "$reviews" | python3 -c '
|
||||
} > "$lines"
|
||||
for rid in $rids; do
|
||||
rc=$(req GET "/repos/$or/pulls/$idx/reviews/$rid/comments") \
|
||||
|| { rm -f "$lines"; api_fail "讀不到 PR $or#$idx 審查 $rid 的行內留言"; }
|
||||
printf '%s' "$rc" | python3 -c '
|
||||
import json,sys
|
||||
for r in json.load(sys.stdin):
|
||||
if r.get("comments_count", 0) or r.get("id"): print(r["id"])
|
||||
'); do
|
||||
req GET "/repos/$or/pulls/$idx/reviews/$rid/comments" 2>/dev/null | python3 -c '
|
||||
import json,sys
|
||||
try: d=json.load(sys.stdin)
|
||||
except Exception: raise SystemExit
|
||||
d=json.load(sys.stdin)
|
||||
for c in d:
|
||||
body=" ".join((c.get("body") or "").split())
|
||||
if body: print("%s\t%s\t行內#%s(%s:%s)\t%s" % (c.get("created_at",""), (c.get("user") or {}).get("login","?"), c.get("id","?"), c.get("path",""), c.get("original_position") or c.get("position") or "", body))
|
||||
' || true
|
||||
done
|
||||
} | sort ;;
|
||||
' >> "$lines"
|
||||
done
|
||||
sort "$lines"
|
||||
rm -f "$lines" ;;
|
||||
comment-reply)
|
||||
or="${1:?owner/repo required}"; idx="${2:?pr index required}"
|
||||
kind="${3:?kind required}"; cid="${4:?comment id required}"; body_file="${5:?body file required}"
|
||||
[ -f "$body_file" ] || { echo "找不到回覆檔: $body_file" >&2; exit 2; }
|
||||
case "$kind" in issue|review|inline) ;; *) echo "kind must be issue, review, or inline" >&2; exit 2 ;; esac
|
||||
confirm_write "回覆留言" "$or#$idx/$kind#$cid"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys
|
||||
@@ -320,6 +473,7 @@ print(json.dumps({"body":open(sys.argv[1],encoding="utf-8").read()}))
|
||||
pr-depend)
|
||||
or="${1:?owner/repo required}"; idx="${2:?pr index required}"
|
||||
dep_or="${3:?dep owner/repo required}"; dep_idx="${4:?dep index required}"
|
||||
confirm_write "設定 PR 依賴" "$or#$idx -> $dep_or#$dep_idx"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys
|
||||
@@ -333,6 +487,7 @@ print(json.dumps({"owner":o,"repo":r,"index":int(sys.argv[2])}))
|
||||
echo "OK $or#$idx depends on $dep_or#$dep_idx" ;;
|
||||
repo-set)
|
||||
or="${1:?owner/repo required}"; desc="${2:?description required}"; site="${3:-}"
|
||||
confirm_write "更新 repo 資訊" "$or"
|
||||
tmp=$(mktemp)
|
||||
python3 -c '
|
||||
import json,sys
|
||||
@@ -353,7 +508,7 @@ print(json.dumps(b))
|
||||
file="${1:?markdown file}"
|
||||
[ -f "$file" ] || { echo "找不到 markdown 檔: $file" >&2; exit 2; }
|
||||
REQ_CONTENT_TYPE='text/plain'
|
||||
req POST "/markdown/raw" "$file" ;;
|
||||
req POST "/markdown/raw" "$file" || api_fail "markdown 渲染失敗($file)" ;;
|
||||
api)
|
||||
method="${1:?METHOD}"; path="${2:?path}"; body="${3:-}"
|
||||
req "$method" "$path" $body ;;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
# 規則:
|
||||
# 先取 SHA-1 前 8 碼大寫。
|
||||
# 若首碼為 0-9、A、B、C,改成 H 加上原 SHA-1 前 7 碼。
|
||||
# 結束碼: 0=成功 1=這台機器沒有 sha1sum 也沒有 shasum,算不出雜湊
|
||||
set -eu
|
||||
|
||||
input=''
|
||||
|
||||
+60
-2
@@ -16,12 +16,20 @@
|
||||
# html-style.sh list 印出合併後的所有設定:種類<TAB>版型<TAB>風格<TAB>來源
|
||||
# html-style.sh layouts 列出可用版型:名稱<TAB>繁中說明
|
||||
# html-style.sh styles 列出可用風格:名稱<TAB>繁中說明
|
||||
# html-style.sh key wiki <頁名> 推導 wiki 頁的種類:取第一個底線前的字首
|
||||
# html-style.sh key issue <owner>/<repo> <編號> [--labels <名稱>[,<名稱>]]
|
||||
# 推導議題的種類:依序試每個標籤,第一個讓 get 回 project 或 global 的標籤勝出;
|
||||
# 都對不到就回 ISSUE:DEFAULT。已經有標籤名單時用 --labels 帶進來,省掉一次 API 呼叫。
|
||||
# key 的輸出固定一行:{種類}<TAB>{依據}
|
||||
# 依據 = prefix:{字首}、label:{標籤名}、fallback:no-labels、fallback:no-configured-label
|
||||
#
|
||||
# 結束碼: 0=成功 2=用法錯誤 4=版型或風格沒有對應範本檔
|
||||
# 結束碼: 0=成功 1=取不到議題標籤,或設定檔的目錄建不出來 2=用法錯誤 4=版型或風格沒有對應範本檔
|
||||
#
|
||||
# 陷阱:
|
||||
# - get 永遠印得出一組值:對不到就退 DEFAULT,再對不到就退內建預設。呼叫端不必自己準備退路,
|
||||
# 但要看第三欄,才知道這組值是使用者設的還是撿來的。
|
||||
# - key 的推導規則放在腳本裡,不放技能內文:字首怎麼切、標籤怎麼試,是固定的輸入輸出,
|
||||
# 每次由模型重推就會有人切錯底線或跳過標籤順序。
|
||||
# - set 會先確認範本檔真的存在,擋掉打錯字的版型或風格;設定寫得進去、出圖卻失敗最難查。
|
||||
set -u
|
||||
|
||||
@@ -41,8 +49,10 @@ usage() {
|
||||
html-style.sh set <種類> <版型> <風格> [--project|--global]
|
||||
html-style.sh unset <種類> [--project|--global]
|
||||
html-style.sh list | layouts | styles
|
||||
html-style.sh key wiki <頁名>
|
||||
html-style.sh key issue <owner>/<repo> <編號> [--labels <名稱>[,<名稱>]]
|
||||
種類: WIKI:{頁名前綴}、ISSUE:{標籤名}、DEFAULT
|
||||
結束碼: 0=成功 2=用法錯誤 4=版型或風格沒有對應範本檔
|
||||
結束碼: 0=成功 1=取不到議題標籤或建不出目錄 2=用法錯誤 4=版型或風格沒有對應範本檔
|
||||
EOF
|
||||
exit 2
|
||||
}
|
||||
@@ -135,6 +145,54 @@ case "$cmd" in
|
||||
key="${1:-}"; [ -n "$key" ] || usage
|
||||
resolve "$key"
|
||||
exit 0 ;;
|
||||
key)
|
||||
kind="${1:-}"; [ -n "$kind" ] || usage
|
||||
shift
|
||||
case "$kind" in
|
||||
wiki)
|
||||
page="${1:-}"; [ -n "$page" ] || usage
|
||||
# 頁名前綴 = 第一個底線之前那一段;沒有底線就是整個頁名。
|
||||
prefix=${page%%_*}
|
||||
printf 'WIKI:%s\tprefix:%s\n' "$prefix" "$prefix"
|
||||
exit 0 ;;
|
||||
issue)
|
||||
repo="${1:-}"; idx="${2:-}"
|
||||
[ -n "$repo" ] && [ -n "$idx" ] || usage
|
||||
shift 2
|
||||
labels=''
|
||||
have_labels=0
|
||||
case "${1:-}" in
|
||||
--labels) [ "$#" -ge 2 ] || usage; labels="$2"; have_labels=1 ;;
|
||||
'') ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
if [ "$have_labels" = 0 ]; then
|
||||
raw=$("$script_dir/issue.sh" labels-of "$repo" "$idx") || {
|
||||
echo "[jsc][HTML 設定][ERR]:取不到議題 $repo#$idx 的標籤。" >&2; exit 1; }
|
||||
labels=$(printf '%s' "$raw" | tr '\n' ',')
|
||||
fi
|
||||
matched=''
|
||||
old_ifs=$IFS
|
||||
IFS=','
|
||||
for l in $labels; do
|
||||
[ -n "$l" ] || continue
|
||||
# 標籤順序就是優先序:第一個使用者真的設過的標籤勝出,
|
||||
# 撿來的 DEFAULT 不算數,否則第一個標籤永遠贏,後面的設定形同虛設。
|
||||
case "$(resolve "ISSUE:$l" | cut -f3)" in
|
||||
project|global) matched="$l"; break ;;
|
||||
esac
|
||||
done
|
||||
IFS=$old_ifs
|
||||
if [ -n "$matched" ]; then
|
||||
printf 'ISSUE:%s\tlabel:%s\n' "$matched" "$matched"
|
||||
elif [ -z "$(printf '%s' "$labels" | tr -d ',')" ]; then
|
||||
printf 'ISSUE:DEFAULT\tfallback:no-labels\n'
|
||||
else
|
||||
printf 'ISSUE:DEFAULT\tfallback:no-configured-label\n'
|
||||
fi
|
||||
exit 0 ;;
|
||||
*) usage ;;
|
||||
esac ;;
|
||||
set)
|
||||
key="${1:-}"; layout="${2:-}"; style="${3:-}"
|
||||
[ -n "$key" ] && [ -n "$layout" ] && [ -n "$style" ] || usage
|
||||
|
||||
+74
-12
@@ -11,6 +11,14 @@
|
||||
# issue.sh title <owner>/<repo> <index> 印出議題標題
|
||||
# issue.sh body <owner>/<repo> <index> 印出議題正文(markdown)
|
||||
# issue.sh labels-of <owner>/<repo> <index> 印出議題目前的標籤名,一行一個
|
||||
# issue.sh show <owner>/<repo> <index> 一次印出標題、標籤與正文(只打一次 API)
|
||||
# 輸出格式固定四段,正文放最後,因為只有它會多行:
|
||||
# 第 1 行 title<TAB>{標題}
|
||||
# 第 2 行 labels<TAB>{標籤名,逗號分隔;沒有標籤時這一欄留空}
|
||||
# 第 3 行 body (單獨一個字,當正文的起始標記)
|
||||
# 第 4 行起 正文原文,一直到檔尾
|
||||
# 呼叫端取標題用 head -n1 | cut -f2-,取標籤用 sed -n 2p | cut -f2-,取正文用 tail -n +4。
|
||||
# 同一筆議題要標題、正文又要標籤時一律用 show,不要連打 title、body、labels-of 三次。
|
||||
# issue.sh create <owner>/<repo> <title> <body-file> [--labels <id>[,<id>]] [--milestone <id>]
|
||||
# 建立議題。輸出兩行: index=<編號>、url=<議題網址>
|
||||
#
|
||||
@@ -21,6 +29,7 @@
|
||||
# - 正文一律用檔案傳進來,內容維持 UTF-8 與真實換行;不要在參數裡塞 \n。
|
||||
# - Gitea 1.27 沒有公開的專案看板 API,projects 會 exit 3。呼叫端要據實回報「請手動把議題拖到看板」,
|
||||
# 不要假裝已經關聯好——關聯不上跟關聯成功看起來一樣,是最容易被當成完成的一種失敗。
|
||||
# exit 3 的兩條路徑(端點回錯、端點回了但不是清單)都會印出看板網址,呼叫端一定拿得到那條連結。
|
||||
set -eu
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
@@ -32,7 +41,7 @@ usage() {
|
||||
issue.sh labels <owner>/<repo> 列出既有標籤:id<TAB>name
|
||||
issue.sh label-ids <owner>/<repo> <name>[,<name>] 標籤名換成 id
|
||||
issue.sh projects <owner>/<repo> 列出專案看板;站台不支援就 exit 3
|
||||
issue.sh title|body|labels-of <owner>/<repo> <index>
|
||||
issue.sh title|body|labels-of|show <owner>/<repo> <index>
|
||||
issue.sh create <owner>/<repo> <title> <body-file> [--labels <id>[,<id>]] [--milestone <id>]
|
||||
結束碼: 0=成功 1=API 失敗 2=用法錯誤 3=站台不支援 4=名稱對不到 id
|
||||
EOF
|
||||
@@ -49,15 +58,30 @@ valid_repo() {
|
||||
esac
|
||||
}
|
||||
|
||||
board_url() { # 看板頁的人工網址。站台沒有看板 API 時,呼叫端要靠這條連結手動處理
|
||||
_host="${GITEA_HOST:-}"
|
||||
case "$_host" in http://*|https://*) : ;; *) _host="https://$_host" ;; esac
|
||||
printf '%s/%s/projects\n' "${_host%/}" "$repo"
|
||||
}
|
||||
|
||||
cmd="${1:-}"; [ -n "$cmd" ] || usage
|
||||
shift || true
|
||||
repo="${1:-}"
|
||||
valid_repo "$repo" || { echo "[jsc][議題][ERR]:存取庫須為 {owner}/{repo},收到「${repo:-空值}」。" >&2; exit 2; }
|
||||
shift
|
||||
|
||||
# gitea.sh 的輸出一律先接進變數再解析,不要寫成 "$GITEA" api ... | python3。
|
||||
# 管線的結束狀態取自 python,會把 gitea.sh 的失敗整個吃掉:金鑰失效時,回應是一份
|
||||
# 錯誤 JSON,python 從裡面挑不到 labels 就印出空清單並回 0,看起來像「這個議題沒有標籤」。
|
||||
api_get() { # $1=API 路徑 -> 回應內容;失敗回 1
|
||||
"$GITEA" api GET "$1"
|
||||
}
|
||||
|
||||
case "$cmd" in
|
||||
labels)
|
||||
"$GITEA" api GET "/repos/$repo/labels?limit=100" | python3 -c '
|
||||
out=$(api_get "/repos/$repo/labels?limit=100") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到 $repo 的標籤清單。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
for l in json.load(sys.stdin):
|
||||
print("%s\t%s" % (l["id"], l["name"]))
|
||||
@@ -65,7 +89,9 @@ for l in json.load(sys.stdin):
|
||||
|
||||
label-ids)
|
||||
names="${1:-}"; [ -n "$names" ] || usage
|
||||
"$GITEA" api GET "/repos/$repo/labels?limit=100" | python3 -c '
|
||||
out=$(api_get "/repos/$repo/labels?limit=100") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到 $repo 的標籤清單。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
want=[n.strip() for n in sys.argv[1].split(",") if n.strip()]
|
||||
have={l["name"]: l["id"] for l in json.load(sys.stdin)}
|
||||
@@ -77,7 +103,8 @@ print(",".join(str(have[n]) for n in want))
|
||||
' "$names" ;;
|
||||
|
||||
projects)
|
||||
if out=$("$GITEA" api GET "/repos/$repo/projects" 2>/dev/null); then
|
||||
manual=0
|
||||
if out=$(api_get "/repos/$repo/projects" 2>/dev/null); then
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
try:
|
||||
@@ -88,36 +115,65 @@ if not isinstance(d, list):
|
||||
sys.exit(3)
|
||||
for p in d:
|
||||
print("%s\t%s" % (p.get("id",""), p.get("title") or p.get("name","")))
|
||||
' || exit 3
|
||||
' || manual=1
|
||||
else
|
||||
host="${GITEA_HOST:-}"
|
||||
case "$host" in http://*|https://*) : ;; *) host="https://$host" ;; esac
|
||||
echo "[jsc][議題][WARN]:這個 Gitea 站台沒有專案看板 API,程式關聯不了。請開 ${host%/}/$repo/projects 手動把議題拖進看板。" >&2
|
||||
manual=1
|
||||
fi
|
||||
if [ "$manual" = 1 ]; then
|
||||
# 兩條 exit 3 的路徑都要印出看板網址:呼叫端的技能被要求把這條連結交給使用者,
|
||||
# 少印一次,使用者就只收到「關聯不上」而不知道要去哪裡手動拖。
|
||||
echo "[jsc][議題][WARN]:這個 Gitea 站台沒有專案看板 API,程式關聯不了。請開 $(board_url) 手動把議題拖進看板。" >&2
|
||||
exit 3
|
||||
fi ;;
|
||||
|
||||
title)
|
||||
idx="${1:-}"; [ -n "$idx" ] || usage
|
||||
"$GITEA" api GET "/repos/$repo/issues/$idx" | python3 -c '
|
||||
out=$(api_get "/repos/$repo/issues/$idx") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到議題 $repo#$idx。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
print(json.load(sys.stdin).get("title",""))
|
||||
' ;;
|
||||
|
||||
body)
|
||||
idx="${1:-}"; [ -n "$idx" ] || usage
|
||||
"$GITEA" api GET "/repos/$repo/issues/$idx" | python3 -c '
|
||||
out=$(api_get "/repos/$repo/issues/$idx") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到議題 $repo#$idx。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
sys.stdout.write(json.load(sys.stdin).get("body","") or "")
|
||||
' ;;
|
||||
|
||||
labels-of)
|
||||
idx="${1:-}"; [ -n "$idx" ] || usage
|
||||
"$GITEA" api GET "/repos/$repo/issues/$idx" | python3 -c '
|
||||
out=$(api_get "/repos/$repo/issues/$idx") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到議題 $repo#$idx 的標籤。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
for l in json.load(sys.stdin).get("labels") or []:
|
||||
print(l.get("name",""))
|
||||
' ;;
|
||||
|
||||
show)
|
||||
# 標題、標籤、正文都在同一份 API 回應裡。分成 title、body、labels-of 三次呼叫,
|
||||
# 打的是同一支端點三遍,還可能取到三個不同時間點的版本。
|
||||
idx="${1:-}"; [ -n "$idx" ] || usage
|
||||
out=$(api_get "/repos/$repo/issues/$idx") \
|
||||
|| { echo "[jsc][議題][ERR]:讀不到議題 $repo#$idx。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
try:
|
||||
d=json.load(sys.stdin)
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
if not isinstance(d, dict) or not d.get("title"):
|
||||
sys.exit(1)
|
||||
print("title\t%s" % d.get("title"))
|
||||
print("labels\t%s" % ",".join((l.get("name") or "") for l in (d.get("labels") or [])))
|
||||
print("body")
|
||||
sys.stdout.write(d.get("body") or "")
|
||||
' || { echo "[jsc][議題][ERR]:議題 $repo#$idx 的回應解不出標題。" >&2; exit 1; } ;;
|
||||
|
||||
create)
|
||||
title="${1:-}"; body_file="${2:-}"
|
||||
[ -n "$title" ] || usage
|
||||
@@ -133,6 +189,10 @@ for l in json.load(sys.stdin).get("labels") or []:
|
||||
*) echo "[jsc][議題][ERR]:不認得的選項「$1」。" >&2; usage ;;
|
||||
esac
|
||||
done
|
||||
confirm_target="議題「$title」"
|
||||
[ -n "$labels" ] && confirm_target="$confirm_target,標籤:$labels"
|
||||
[ -n "$milestone" ] && confirm_target="$confirm_target,里程碑:$milestone"
|
||||
sh "$script_dir/write-confirm.sh" "建立議題" "$confirm_target"
|
||||
payload=$(mktemp)
|
||||
trap 'rm -f "$payload"' EXIT
|
||||
python3 -c '
|
||||
@@ -146,7 +206,9 @@ if milestone:
|
||||
with open(out, "w", encoding="utf-8") as f:
|
||||
json.dump(d, f, ensure_ascii=False)
|
||||
' "$title" "$body_file" "$labels" "$milestone" "$payload"
|
||||
"$GITEA" api POST "/repos/$repo/issues" "$payload" | python3 -c '
|
||||
out=$("$GITEA" api POST "/repos/$repo/issues" "$payload") \
|
||||
|| { echo "[jsc][議題][ERR]:建不出議題到 $repo。" >&2; exit 1; }
|
||||
printf '%s' "$out" | python3 -c '
|
||||
import json,sys
|
||||
d=json.load(sys.stdin)
|
||||
print("index=%s" % (d.get("number") or d.get("index") or ""))
|
||||
|
||||
+8
-2
@@ -12,8 +12,14 @@
|
||||
# 照樣印出來再退出,退出碼仍是 0:留言不會因為 PR 剛好合併就消失。
|
||||
# 輸出: 全部繁中,留言行維持 gitea.sh pr-comments 的原格式
|
||||
# 「{時間}<TAB>{作者}<TAB>{類型}<TAB>{內容}」,呼叫端可直接用 cut -f 取欄位。
|
||||
# 退出碼: 0 = PR 已合併或關閉,印出最終狀態;10 = 有新留言待呼叫端跑決策樹;
|
||||
# 2 = 參數錯誤或第一輪就連不上 Gitea;3 = 查不到該 PR。
|
||||
# 結束碼: 0=PR 已合併或關閉,最終狀態印在 stdout。盯完了,不用再盯一次。
|
||||
# 2=用法或環境問題:參數個數不對、第一個參數不是 {owner}/{repo}、PR 編號不是數字、
|
||||
# JSC_PR_WATCH_INTERVAL 不是正整數秒、建不出暫存檔,或第一輪就連不上 Gitea。
|
||||
# 照 stderr 的訊息修參數或 GITEA_HOST、GITEA_TOKEN,再重新盯。
|
||||
# 3=查不到該 PR。確認存取庫與 PR 編號再重新盯,不要原樣重試——
|
||||
# 編號打錯會變成永遠輪詢一支不存在的 PR。
|
||||
# 10=有新留言,內容印在 stdout。接手跑決策樹處理完,再重新盯同一支 PR。
|
||||
# 130=收到 INT 或 TERM 訊號而中止。狀態檔留著,重新盯會從上次那則留言接下去。
|
||||
# 護欄: gitea.sh pr-status 對不存在的 PR 會印「? none none」並且 exit 0。
|
||||
# 所以 state 只認 open 與 closed、merged 只認 true 與 false,對不上就回 3。
|
||||
# 少了這道白名單,PR 編號打錯會變成永遠輪詢一支不存在的 PR。
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
# 輸出: 恰好一行,cloned、updated、dirty {分支} 或 failed {原因}。
|
||||
# 前三種 exit 0;failed exit 1。
|
||||
# dirty 會把解析好的基準分支一起帶出來,呼叫端直接拿去當 PR 的 base。
|
||||
# 結束碼: 0=同步完成,輸出是 cloned、updated 或 dirty {分支}
|
||||
# 1=失敗,輸出是 failed {原因};參數錯誤、clone-url 取不到、fetch/checkout/pull 失敗、
|
||||
# 以及找不到基準分支都走這一碼。只有 0 與 1 兩種。
|
||||
set -u
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env sh
|
||||
# write-confirm.sh — Gitea 寫入前的人工確認。
|
||||
#
|
||||
# 為什麼要有這支腳本:wiki 與議題都是對外寫入。先確認,才能避免把
|
||||
# 錯頁、錯內容、錯標籤直接送出去。
|
||||
#
|
||||
# 用法:
|
||||
# write-confirm.sh <動作> <目標>
|
||||
#
|
||||
# 規則:
|
||||
# - JSC_GITEA_CONFIRM=yes:直接放行。
|
||||
# - JSC_GITEA_CONFIRM=no:直接拒絕。
|
||||
# - 互動式執行:要求輸入「確認」。
|
||||
# - 沒有互動終端:拒絕,避免默默寫出錯資料。
|
||||
# 結束碼: 0=已確認,呼叫端接著送出這次寫入。
|
||||
# 2=不要寫入,原因印在 stderr:缺動作名稱、缺目標名稱、JSC_GITEA_CONFIRM=no、
|
||||
# 輸入的不是「確認」、讀不到輸入,以及沒有互動終端這五種都走這一碼。
|
||||
# 呼叫端一律中止這次寫入,不要重試,也不要繞過確認直接呼叫 API。
|
||||
# 只有 0 與 2 兩種。用法錯誤與人工拒絕共用 2,因為兩者的處置一樣是「不寫」;
|
||||
# 拆成兩碼只會誘使呼叫端把用法錯誤當成可重試,反而寫出沒經過確認的資料。
|
||||
set -eu
|
||||
|
||||
action="${1:-}"
|
||||
target="${2:-}"
|
||||
|
||||
[ -n "$action" ] || { echo '[jsc][Gitea][ERR]:缺少動作名稱。' >&2; exit 2; }
|
||||
[ -n "$target" ] || { echo '[jsc][Gitea][ERR]:缺少目標名稱。' >&2; exit 2; }
|
||||
|
||||
case "${JSC_GITEA_CONFIRM:-}" in
|
||||
yes|YES|1|true|TRUE)
|
||||
exit 0 ;;
|
||||
no|NO|0|false|FALSE)
|
||||
echo "[jsc][Gitea][ERR]:已取消寫入「$target」。" >&2
|
||||
exit 2 ;;
|
||||
esac
|
||||
|
||||
if [ -t 0 ]; then
|
||||
printf '[jsc][Gitea] 即將%s「%s」。輸入「確認」繼續:' "$action" "$target" >&2
|
||||
IFS= read -r answer || exit 2
|
||||
case "$answer" in
|
||||
確認)
|
||||
exit 0 ;;
|
||||
*)
|
||||
echo "[jsc][Gitea][ERR]:已取消寫入「$target」。" >&2
|
||||
exit 2 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "[jsc][Gitea][ERR]:寫入「$target」需要先確認;請改用互動式執行,或先設 JSC_GITEA_CONFIRM=yes。" >&2
|
||||
exit 2
|
||||
Reference in New Issue
Block a user